DLESE Tools
v1.6.0

org.dlese.dpc.index.queryParser
Class FieldExpansionQueryParser

java.lang.Object
  extended by org.apache.lucene.queryParser.QueryParser
      extended by org.dlese.dpc.index.queryParser.FieldExpansionQueryParser
All Implemented Interfaces:
org.apache.lucene.queryParser.QueryParserConstants

public class FieldExpansionQueryParser
extends org.apache.lucene.queryParser.QueryParser

A QueryParser that modifies a user's query by expanding the fields that are searched, applying boosting, and applying Query mappings for the given virtual field/terms. The static parse method must be used - see it's definition for details.

Author:
John Weatherley
See Also:
VirtualSearchFieldMapper

Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.lucene.queryParser.QueryParser
org.apache.lucene.queryParser.QueryParser.Operator
 
Field Summary
 
Fields inherited from class org.apache.lucene.queryParser.QueryParser
AND_OPERATOR, jj_nt, OR_OPERATOR, token, token_source
 
Fields inherited from interface org.apache.lucene.queryParser.QueryParserConstants
_ESCAPED_CHAR, _NUM_CHAR, _QUOTED_CHAR, _TERM_CHAR, _TERM_START_CHAR, _WHITESPACE, AND, Boost, CARAT, COLON, DEFAULT, EOF, FUZZY_SLOP, LPAREN, MINUS, NOT, NUMBER, OR, PLUS, PREFIXTERM, QUOTED, RangeEx, RANGEEX_END, RANGEEX_GOOP, RANGEEX_QUOTED, RANGEEX_START, RANGEEX_TO, RangeIn, RANGEIN_END, RANGEIN_GOOP, RANGEIN_QUOTED, RANGEIN_START, RANGEIN_TO, RPAREN, STAR, TERM, tokenImage, WILDTERM
 
Method Summary
protected  org.apache.lucene.search.Query getFieldQuery(String field, String queryText)
          Gets the fieldQuery attribute of the FieldExpansionQueryParser object
 org.apache.lucene.search.Query parse(String query)
          Parses a query which searches on the fields specified.
static org.apache.lucene.search.Query parse(String query, org.apache.lucene.analysis.Analyzer analyzer, String[] expansionFields, String[] boostingFields, Map boostValues, VirtualSearchFieldMapper mappedFields, org.apache.lucene.queryParser.QueryParser.Operator defaultOperator)
          Parses the query text to create an expanded Lucene Query.
 org.apache.lucene.search.Query parse(String query, String field)
          Parses a query string, returning a Query.
static void setDebug(boolean db)
          Sets the debug attribute of the FieldQueryParser object
 
Methods inherited from class org.apache.lucene.queryParser.QueryParser
addClause, Clause, Conjunction, disable_tracing, enable_tracing, escape, generateParseException, getAllowLeadingWildcard, getAnalyzer, getBooleanQuery, getBooleanQuery, getDateResolution, getDefaultOperator, getEnablePositionIncrements, getField, getFieldQuery, getFuzzyMinSim, getFuzzyPrefixLength, getFuzzyQuery, getLocale, getLowercaseExpandedTerms, getMultiTermRewriteMethod, getNextToken, getPhraseSlop, getPrefixQuery, getRangeCollator, getRangeQuery, getToken, getWildcardQuery, main, Modifiers, newBooleanClause, newBooleanQuery, newFuzzyQuery, newMatchAllDocsQuery, newMultiPhraseQuery, newPhraseQuery, newPrefixQuery, newRangeQuery, newTermQuery, newWildcardQuery, Query, ReInit, ReInit, setAllowLeadingWildcard, setDateResolution, setDateResolution, setDefaultOperator, setEnablePositionIncrements, setFuzzyMinSim, setFuzzyPrefixLength, setLocale, setLowercaseExpandedTerms, setMultiTermRewriteMethod, setPhraseSlop, setRangeCollator, Term, TopLevelQuery
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

parse

public static org.apache.lucene.search.Query parse(String query,
                                                   org.apache.lucene.analysis.Analyzer analyzer,
                                                   String[] expansionFields,
                                                   String[] boostingFields,
                                                   Map boostValues,
                                                   VirtualSearchFieldMapper mappedFields,
                                                   org.apache.lucene.queryParser.QueryParser.Operator defaultOperator)
                                            throws org.apache.lucene.queryParser.ParseException
Parses the query text to create an expanded Lucene Query. Default text is searched in the given expansion fields with boosting applied for the given boosting fields. At least one field must be supplied in the expansion fields in order to form a valid query.

If n fields are specified, this effectively constructs:

 
 (field1:query) (field2:query) (field3:query)...(fieldn:query)  

Parameters:
query - The query text
analyzer - The Analyzer to user
expansionFields - Fields to search in for default text, which must contain at least one field
boostingFields - Fields to boost terms found in the default text, or null
boostValues - A Map of boosting values corresponding the the boostingFields - Map of String/Float pairs, or null
mappedFields - Field/term mappings to apply, or null
defaultOperator - Default AND or OR operator
Returns:
A Query
Throws:
org.apache.lucene.queryParser.ParseException - If unable to parse the query

parse

public org.apache.lucene.search.Query parse(String query)
                                     throws org.apache.lucene.queryParser.ParseException
Parses a query which searches on the fields specified. This expands the query so that multiple fields are searched for the default text, and boosting is applied for the given boosting fields.

If n fields are specified, this effectively constructs:

 
 (field1:query) (field2:query) (field3:query)...(fieldn:query)  

Overrides:
parse in class org.apache.lucene.queryParser.QueryParser
Parameters:
query - Query string to parse
Returns:
A Query or null if none
Throws:
org.apache.lucene.queryParser.ParseException - if query parsing fails
org.apache.lucene.queryParser.TokenMgrError - if query parsing fails

parse

public org.apache.lucene.search.Query parse(String query,
                                            String field)
                                     throws org.apache.lucene.queryParser.ParseException
Parses a query string, returning a Query. Same as the QueryParser parse method but adds the ability to specify the default field rather than using the one initialized in the constructor.

Parameters:
query - the query string to be parsed.
field - the default field for this query.
Returns:
A Query Object.
Throws:
org.apache.lucene.queryParser.ParseException - if the parsing fails

getFieldQuery

protected org.apache.lucene.search.Query getFieldQuery(String field,
                                                       String queryText)
                                                throws org.apache.lucene.queryParser.ParseException
Gets the fieldQuery attribute of the FieldExpansionQueryParser object

Overrides:
getFieldQuery in class org.apache.lucene.queryParser.QueryParser
Parameters:
field - The field being processed
queryText - The text in the field
Returns:
The fieldQuery value
Throws:
org.apache.lucene.queryParser.ParseException - If error

setDebug

public static void setDebug(boolean db)
Sets the debug attribute of the FieldQueryParser object

Parameters:
db - The new debug value

DLESE Tools
v1.6.0