org.apache.lucene.queryparser.classic
public class QueryParser extends QueryParserBase implements QueryParserConstants
QueryParserBase.parse(String)
.
The syntax for query strings is as follows:
A Query is a series of clauses.
A clause may be prefixed by:
+
) or a minus (-
) sign, indicating
that the clause is required or prohibited respectively; or
+
/-
prefix to require any of a set of
terms.
Query ::= ( Clause )* Clause ::= ["+", "-"] [<TERM> ":"] ( <TERM> | "(" Query ")" )
Examples of appropriately formatted queries can be found in the query syntax documentation.
In TermRangeQuery
s, QueryParser tries to detect date values, e.g.
date:[6/1/2005 TO 6/4/2005] produces a range query that searches
for "date" fields between 2005-06-01 and 2005-06-04. Note that the format
of the accepted input depends on the locale
.
A DateTools.Resolution
has to be set,
if you want to use DateTools
for date conversion.
The date resolution that shall be used for RangeQueries can be set
using QueryParserBase.setDateResolution(DateTools.Resolution)
or QueryParserBase.setDateResolution(String, DateTools.Resolution)
. The former
sets the default date resolution for all fields, whereas the latter can
be used to set field specific date resolutions. Field specific date
resolutions take, if set, precedence over the default date resolution.
If you don't use DateTools
in your index, you can create your own
query parser that inherits QueryParser and overwrites
QueryParserBase.getRangeQuery(String, String, String, boolean, boolean)
to
use a different method for date conversion.
Note that QueryParser is not thread-safe.
NOTE: there is a new QueryParser in contrib, which matches the same syntax as this class, but is more modular, enabling substantial customization to how a query is created.
NOTE: You must specify the required Version
compatibility when creating QueryParser:
QueryParserBase.setAutoGeneratePhraseQueries(boolean)
is false by
default.
Modifier and Type | Class and Description |
---|---|
static class |
QueryParser.Operator
The default operator for parsing queries.
|
QueryParserBase.MethodRemovedUseAnother
Modifier and Type | Field and Description |
---|---|
Token |
jj_nt
Next token.
|
Token |
token
Current token.
|
QueryParserTokenManager |
token_source
Generated Token Manager.
|
AND_OPERATOR, OR_OPERATOR
_ESCAPED_CHAR, _NUM_CHAR, _QUOTED_CHAR, _TERM_CHAR, _TERM_START_CHAR, _WHITESPACE, AND, BAREOPER, Boost, CARAT, COLON, DEFAULT, EOF, FUZZY_SLOP, LPAREN, MINUS, NOT, NUMBER, OR, PLUS, PREFIXTERM, QUOTED, Range, RANGE_GOOP, RANGE_QUOTED, RANGE_TO, RANGEEX_END, RANGEEX_START, RANGEIN_END, RANGEIN_START, REGEXPTERM, RPAREN, STAR, TERM, tokenImage, WILDTERM
Modifier | Constructor and Description |
---|---|
protected |
QueryParser(CharStream stream)
Constructor with user supplied CharStream.
|
protected |
QueryParser(QueryParserTokenManager tm)
Constructor with generated Token Manager.
|
|
QueryParser(Version matchVersion,
String f,
Analyzer a)
Create a query parser.
|
Modifier and Type | Method and Description |
---|---|
Query |
Clause(String field) |
int |
Conjunction() |
void |
disable_tracing()
Disable tracing.
|
void |
enable_tracing()
Enable tracing.
|
ParseException |
generateParseException()
Generate ParseException.
|
Token |
getNextToken()
Get the next Token.
|
Token |
getToken(int index)
Get the specific Token.
|
int |
Modifiers() |
Query |
Query(String field) |
void |
ReInit(CharStream stream)
Reinitialise.
|
void |
ReInit(QueryParserTokenManager tm)
Reinitialise.
|
Query |
Term(String field) |
Query |
TopLevelQuery(String field) |
addClause, analyzeMultitermTerm, escape, getAllowLeadingWildcard, getAnalyzeRangeTerms, getAutoGeneratePhraseQueries, getBooleanQuery, getBooleanQuery, getDateResolution, getDefaultOperator, getField, getFieldQuery, getFieldQuery, getFuzzyMinSim, getFuzzyPrefixLength, getFuzzyQuery, getLocale, getLowercaseExpandedTerms, getMultiTermRewriteMethod, getPhraseSlop, getPrefixQuery, getRangeQuery, getRegexpQuery, getTimeZone, getWildcardQuery, init, newBooleanClause, newFieldQuery, newFuzzyQuery, newMatchAllDocsQuery, newPrefixQuery, newRangeQuery, newRegexpQuery, newWildcardQuery, parse, setAllowLeadingWildcard, setAnalyzeRangeTerms, setAutoGeneratePhraseQueries, setDateResolution, setDateResolution, setDefaultOperator, setFuzzyMinSim, setFuzzyPrefixLength, setLocale, setLowercaseExpandedTerms, setMultiTermRewriteMethod, setPhraseSlop, setTimeZone
createBooleanQuery, createBooleanQuery, createFieldQuery, createMinShouldMatchQuery, createPhraseQuery, createPhraseQuery, getAnalyzer, getEnablePositionIncrements, newBooleanQuery, newMultiPhraseQuery, newPhraseQuery, newTermQuery, setAnalyzer, setEnablePositionIncrements
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getAnalyzer, getEnablePositionIncrements, setEnablePositionIncrements
public QueryParserTokenManager token_source
public Token token
public Token jj_nt
public QueryParser(Version matchVersion, String f, Analyzer a)
matchVersion
- Lucene version to match. See above.f
- the default field for query terms.a
- used to find terms in the query text.protected QueryParser(CharStream stream)
protected QueryParser(QueryParserTokenManager tm)
public final int Conjunction() throws ParseException
ParseException
public final int Modifiers() throws ParseException
ParseException
public final Query TopLevelQuery(String field) throws ParseException
TopLevelQuery
in class QueryParserBase
ParseException
public final Query Query(String field) throws ParseException
ParseException
public final Query Clause(String field) throws ParseException
ParseException
public final Query Term(String field) throws ParseException
ParseException
public void ReInit(CharStream stream)
ReInit
in class QueryParserBase
public void ReInit(QueryParserTokenManager tm)
public final Token getNextToken()
public final Token getToken(int index)
public ParseException generateParseException()
public final void enable_tracing()
public final void disable_tracing()
Copyright © 2000-2014 Apache Software Foundation. All Rights Reserved.