|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.lucene.queryParser.precedence.PrecedenceQueryParser
public class PrecedenceQueryParser
Experimental query parser variant designed to handle operator precedence in a more sensible fashion than QueryParser. There are still some open issues with this parser. The following tests are currently failing in TestPrecedenceQueryParser and are disabled to make this test pass:
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.
Field Summary | |
---|---|
static org.apache.lucene.queryParser.precedence.PrecedenceQueryParser.Operator |
AND_OPERATOR
|
Token |
jj_nt
|
boolean |
lookingAhead
|
static org.apache.lucene.queryParser.precedence.PrecedenceQueryParser.Operator |
OR_OPERATOR
|
Token |
token
|
PrecedenceQueryParserTokenManager |
token_source
|
Fields inherited from interface org.apache.lucene.queryParser.precedence.PrecedenceQueryParserConstants |
---|
_ESCAPED_CHAR, _NUM_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, TERM, tokenImage, WILDTERM |
Constructor Summary | |
---|---|
PrecedenceQueryParser(CharStream stream)
|
|
PrecedenceQueryParser(PrecedenceQueryParserTokenManager tm)
|
|
PrecedenceQueryParser(String f,
Analyzer a)
Constructs a query parser. |
Method Summary | |
---|---|
protected void |
addClause(Vector clauses,
int conj,
int modifier,
Query q)
|
Query |
andExpression(String field)
|
Query |
Clause(String field)
|
int |
Conjunction()
|
void |
disable_tracing()
|
void |
enable_tracing()
|
static String |
escape(String s)
Returns a String where those characters that QueryParser expects to be escaped are escaped by a preceding \ . |
ParseException |
generateParseException()
|
Analyzer |
getAnalyzer()
|
protected Query |
getBooleanQuery(Vector clauses)
Factory method for generating query, given a set of clauses. |
protected Query |
getBooleanQuery(Vector clauses,
boolean disableCoord)
Factory method for generating query, given a set of clauses. |
org.apache.lucene.queryParser.precedence.PrecedenceQueryParser.Operator |
getDefaultOperator()
Gets implicit operator setting, which will be either AND_OPERATOR or OR_OPERATOR. |
String |
getField()
|
protected Query |
getFieldQuery(String field,
String queryText)
|
protected Query |
getFieldQuery(String field,
String queryText,
int slop)
Base implementation delegates to getFieldQuery(String,String) . |
float |
getFuzzyMinSim()
Get the minimal similarity for fuzzy queries. |
int |
getFuzzyPrefixLength()
Get the prefix length for fuzzy queries. |
protected Query |
getFuzzyQuery(String field,
String termStr,
float minSimilarity)
Factory method for generating a query (similar to getWildcardQuery(java.lang.String, java.lang.String) ). |
Locale |
getLocale()
Returns current locale, allowing access by subclasses. |
boolean |
getLowercaseExpandedTerms()
|
Token |
getNextToken()
|
int |
getPhraseSlop()
Gets the default slop for phrases. |
protected Query |
getPrefixQuery(String field,
String termStr)
Factory method for generating a query (similar to getWildcardQuery(java.lang.String, java.lang.String) ). |
protected Query |
getRangeQuery(String field,
String part1,
String part2,
boolean inclusive)
|
Token |
getToken(int index)
|
protected Query |
getWildcardQuery(String field,
String termStr)
Factory method for generating a query. |
static void |
main(String[] args)
Command line tool to test QueryParser, using SimpleAnalyzer . |
int |
Modifier()
|
Query |
parse(String expression)
Parses a query string, returning a Query . |
Query |
Query(String field)
|
void |
ReInit(CharStream stream)
|
void |
ReInit(PrecedenceQueryParserTokenManager tm)
|
void |
setDefaultOperator(org.apache.lucene.queryParser.precedence.PrecedenceQueryParser.Operator op)
Sets the boolean operator of the QueryParser. |
void |
setFuzzyMinSim(float fuzzyMinSim)
Set the minimum similarity for fuzzy queries. |
void |
setFuzzyPrefixLength(int fuzzyPrefixLength)
Set the prefix length for fuzzy queries. |
void |
setLocale(Locale locale)
Set locale used by date range parsing. |
void |
setLowercaseExpandedTerms(boolean lowercaseExpandedTerms)
Whether terms of wildcard, prefix, fuzzy and range queries are to be automatically lower-cased or not. |
void |
setPhraseSlop(int phraseSlop)
Sets the default slop for phrases. |
Query |
Term(String field)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final org.apache.lucene.queryParser.precedence.PrecedenceQueryParser.Operator AND_OPERATOR
public static final org.apache.lucene.queryParser.precedence.PrecedenceQueryParser.Operator OR_OPERATOR
public PrecedenceQueryParserTokenManager token_source
public Token token
public Token jj_nt
public boolean lookingAhead
Constructor Detail |
---|
public PrecedenceQueryParser(String f, Analyzer a)
f
- the default field for query terms.a
- used to find terms in the query text.public PrecedenceQueryParser(CharStream stream)
public PrecedenceQueryParser(PrecedenceQueryParserTokenManager tm)
Method Detail |
---|
public Query parse(String expression) throws ParseException
Query
.
expression
- the query string to be parsed.
ParseException
- if the parsing failspublic Analyzer getAnalyzer()
public String getField()
public float getFuzzyMinSim()
public void setFuzzyMinSim(float fuzzyMinSim)
public int getFuzzyPrefixLength()
public void setFuzzyPrefixLength(int fuzzyPrefixLength)
fuzzyPrefixLength
- The fuzzyPrefixLength to set.public void setPhraseSlop(int phraseSlop)
public int getPhraseSlop()
public void setDefaultOperator(org.apache.lucene.queryParser.precedence.PrecedenceQueryParser.Operator op)
OR_OPERATOR
) terms without any modifiers
are considered optional: for example capital of Hungary
is equal to
capital OR of OR Hungary
.AND_OPERATOR
mode terms are considered to be in conjuction: the
above mentioned query is parsed as capital AND of AND Hungary
public org.apache.lucene.queryParser.precedence.PrecedenceQueryParser.Operator getDefaultOperator()
public void setLowercaseExpandedTerms(boolean lowercaseExpandedTerms)
true
.
public boolean getLowercaseExpandedTerms()
setLowercaseExpandedTerms(boolean)
public void setLocale(Locale locale)
public Locale getLocale()
protected void addClause(Vector clauses, int conj, int modifier, Query q)
protected Query getFieldQuery(String field, String queryText) throws ParseException
ParseException
- throw in overridden method to disallowprotected Query getFieldQuery(String field, String queryText, int slop) throws ParseException
getFieldQuery(String,String)
.
This method may be overridden, for example, to return
a SpanNearQuery instead of a PhraseQuery.
ParseException
- throw in overridden method to disallowprotected Query getRangeQuery(String field, String part1, String part2, boolean inclusive) throws ParseException
ParseException
- throw in overridden method to disallowprotected Query getBooleanQuery(Vector clauses) throws ParseException
clauses
- Vector that contains BooleanClause
instances
to join.
Query
object.
ParseException
- throw in overridden method to disallowprotected Query getBooleanQuery(Vector clauses, boolean disableCoord) throws ParseException
clauses
- Vector that contains BooleanClause
instances
to join.disableCoord
- true if coord scoring should be disabled.
Query
object.
ParseException
- throw in overridden method to disallowprotected Query getWildcardQuery(String field, String termStr) throws ParseException
Depending on settings, prefix term may be lower-cased automatically. It will not go through the default Analyzer, however, since normal Analyzers are unlikely to work properly with wildcard templates.
Can be overridden by extending classes, to provide custom handling for wildcard queries, which may be necessary due to missing analyzer calls.
field
- Name of the field query will use.termStr
- Term token that contains one or more wild card
characters (? or *), but is not simple prefix term
Query
built for the term
ParseException
- throw in overridden method to disallowprotected Query getPrefixQuery(String field, String termStr) throws ParseException
getWildcardQuery(java.lang.String, java.lang.String)
). Called when parser parses an input term
token that uses prefix notation; that is, contains a single '*' wildcard
character as its last character. Since this is a special case
of generic wildcard term, and such a query can be optimized easily,
this usually results in a different query object.
Depending on settings, a prefix term may be lower-cased automatically. It will not go through the default Analyzer, however, since normal Analyzers are unlikely to work properly with wildcard templates.
Can be overridden by extending classes, to provide custom handling for wild card queries, which may be necessary due to missing analyzer calls.
field
- Name of the field query will use.termStr
- Term token to use for building term for the query
(without trailing '*' character!)
Query
built for the term
ParseException
- throw in overridden method to disallowprotected Query getFuzzyQuery(String field, String termStr, float minSimilarity) throws ParseException
getWildcardQuery(java.lang.String, java.lang.String)
). Called when parser parses
an input term token that has the fuzzy suffix (~) appended.
field
- Name of the field query will use.termStr
- Term token to use for building term for the query
Query
built for the term
ParseException
- throw in overridden method to disallowpublic static String escape(String s)
\
.
public static void main(String[] args) throws Exception
SimpleAnalyzer
.
Usage:java org.apache.lucene.queryParser.QueryParser <input>
Exception
public final int Conjunction() throws ParseException
ParseException
public final int Modifier() throws ParseException
ParseException
public final Query Query(String field) throws ParseException
ParseException
public final Query andExpression(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)
public void ReInit(PrecedenceQueryParserTokenManager tm)
public final Token getNextToken()
public final Token getToken(int index)
public ParseException generateParseException()
public final void enable_tracing()
public final void disable_tracing()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |