| java.lang.Object org.apache.lucene.queryParser.precedence.PrecedenceQueryParser
PrecedenceQueryParser | public class PrecedenceQueryParser implements PrecedenceQueryParserConstants(Code) | | 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:
- testSimple
- testWildcard
- testPrecedence
This class is generated by JavaCC. The only method that clients should need
to call is
PrecedenceQueryParser.parse(String) .
The syntax for query strings is as follows:
A Query is a series of clauses.
A clause may be prefixed by:
- a plus (
+ ) or a minus (- ) sign, indicating
that the clause is required or prohibited respectively; or
- a term followed by a colon, indicating the field to be searched.
This enables one to construct queries which search multiple fields.
A clause may be either:
- a term, indicating all the documents that contain this term; or
- a nested query, enclosed in parentheses. Note that this may be used
with a
+ /- prefix to require any of a set of
terms.
Thus, in BNF, the query grammar is:
Query ::= ( Clause )*
Clause ::= ["+", "-"] [<TERM> ":"] ( <TERM> | "(" Query ")" )
Examples of appropriately formatted queries can be found in the query syntax
documentation.
author: Brian Goetz author: Peter Halacsy author: Tatu Saloranta |
Inner Class :final static class Operator extends Parameter | |
Inner Class :final static class JJCalls | |
Method Summary | |
final public Query | Clause(String field) | final public int | Conjunction() | final public int | Modifier() | final public Query | Query(String field) | public void | ReInit(CharStream stream) | public void | ReInit(PrecedenceQueryParserTokenManager tm) | final public Query | Term(String field) | protected void | addClause(Vector clauses, int conj, int modifier, Query q) | final public Query | andExpression(String field) | final public void | disable_tracing() | final public void | enable_tracing() | public static String | escape(String s) Returns a String where those characters that QueryParser
expects to be escaped are escaped by a preceding \ . | public ParseException | generateParseException() | public Analyzer | getAnalyzer() | protected Query | getBooleanQuery(Vector clauses) Factory method for generating query, given a set of clauses.
By default creates a boolean query composed of clauses passed in.
Can be overridden by extending classes, to modify query being
returned.
Parameters: clauses - Vector that contains BooleanClause instancesto join. | protected Query | getBooleanQuery(Vector clauses, boolean disableCoord) Factory method for generating query, given a set of clauses.
By default creates a boolean query composed of clauses passed in.
Can be overridden by extending classes, to modify query being
returned.
Parameters: clauses - Vector that contains BooleanClause instancesto join. Parameters: disableCoord - true if coord scoring should be disabled. | public Operator | getDefaultOperator() Gets implicit operator setting, which will be either AND_OPERATOR
or OR_OPERATOR. | public String | getField() | protected Query | getFieldQuery(String field, String queryText) | protected Query | getFieldQuery(String field, String queryText, int slop) Base implementation delegates to
PrecedenceQueryParser.getFieldQuery(String,String) . | public float | getFuzzyMinSim() Get the minimal similarity for fuzzy queries. | public 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
PrecedenceQueryParser.getWildcardQuery ). | public Locale | getLocale() Returns current locale, allowing access by subclasses. | public boolean | getLowercaseExpandedTerms() | final public Token | getNextToken() | public int | getPhraseSlop() Gets the default slop for phrases. | protected Query | getPrefixQuery(String field, String termStr) Factory method for generating a query (similar to
PrecedenceQueryParser.getWildcardQuery ). | protected Query | getRangeQuery(String field, String part1, String part2, boolean inclusive) | final public Token | getToken(int index) | protected Query | getWildcardQuery(String field, String termStr) Factory method for generating a query. | public static void | main(String[] args) Command line tool to test QueryParser, using
org.apache.lucene.analysis.SimpleAnalyzer . | public Query | parse(String expression) Parses a query string, returning a
org.apache.lucene.search.Query . | public void | setDefaultOperator(Operator op) Sets the boolean operator of the QueryParser. | public void | setFuzzyMinSim(float fuzzyMinSim) Set the minimum similarity for fuzzy queries. | public void | setFuzzyPrefixLength(int fuzzyPrefixLength) Set the prefix length for fuzzy queries. | public void | setLocale(Locale locale) Set locale used by date range parsing. | public void | setLowercaseExpandedTerms(boolean lowercaseExpandedTerms) Whether terms of wildcard, prefix, fuzzy and range queries are to be automatically
lower-cased or not. | public void | setPhraseSlop(int phraseSlop) Sets the default slop for phrases. |
AND_OPERATOR | final public static Operator AND_OPERATOR(Code) | | |
OR_OPERATOR | final public static Operator OR_OPERATOR(Code) | | |
fuzzyMinSim | float fuzzyMinSim(Code) | | |
fuzzyPrefixLength | int fuzzyPrefixLength(Code) | | |
lookingAhead | public boolean lookingAhead(Code) | | |
lowercaseExpandedTerms | boolean lowercaseExpandedTerms(Code) | | |
phraseSlop | int phraseSlop(Code) | | |
PrecedenceQueryParser | public PrecedenceQueryParser(String f, Analyzer a)(Code) | | Constructs a query parser.
Parameters: f - the default field for query terms. Parameters: a - used to find terms in the query text. |
addClause | protected void addClause(Vector clauses, int conj, int modifier, Query q)(Code) | | |
disable_tracing | final public void disable_tracing()(Code) | | |
enable_tracing | final public void enable_tracing()(Code) | | |
escape | public static String escape(String s)(Code) | | Returns a String where those characters that QueryParser
expects to be escaped are escaped by a preceding \ .
|
getBooleanQuery | protected Query getBooleanQuery(Vector clauses) throws ParseException(Code) | | Factory method for generating query, given a set of clauses.
By default creates a boolean query composed of clauses passed in.
Can be overridden by extending classes, to modify query being
returned.
Parameters: clauses - Vector that contains BooleanClause instancesto join. Resulting Query object. exception: ParseException - throw in overridden method to disallow |
getBooleanQuery | protected Query getBooleanQuery(Vector clauses, boolean disableCoord) throws ParseException(Code) | | Factory method for generating query, given a set of clauses.
By default creates a boolean query composed of clauses passed in.
Can be overridden by extending classes, to modify query being
returned.
Parameters: clauses - Vector that contains BooleanClause instancesto join. Parameters: disableCoord - true if coord scoring should be disabled. Resulting Query object. exception: ParseException - throw in overridden method to disallow |
getDefaultOperator | public Operator getDefaultOperator()(Code) | | Gets implicit operator setting, which will be either AND_OPERATOR
or OR_OPERATOR.
|
getFuzzyMinSim | public float getFuzzyMinSim()(Code) | | Get the minimal similarity for fuzzy queries.
|
getFuzzyPrefixLength | public int getFuzzyPrefixLength()(Code) | | Get the prefix length for fuzzy queries.
Returns the fuzzyPrefixLength. |
getFuzzyQuery | protected Query getFuzzyQuery(String field, String termStr, float minSimilarity) throws ParseException(Code) | | Factory method for generating a query (similar to
PrecedenceQueryParser.getWildcardQuery ). Called when parser parses
an input term token that has the fuzzy suffix (~) appended.
Parameters: field - Name of the field query will use. Parameters: termStr - Term token to use for building term for the query Resulting Query built for the term exception: ParseException - throw in overridden method to disallow |
getLocale | public Locale getLocale()(Code) | | Returns current locale, allowing access by subclasses.
|
getPhraseSlop | public int getPhraseSlop()(Code) | | Gets the default slop for phrases.
|
getPrefixQuery | protected Query getPrefixQuery(String field, String termStr) throws ParseException(Code) | | Factory method for generating a query (similar to
PrecedenceQueryParser.getWildcardQuery ). 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.
Parameters: field - Name of the field query will use. Parameters: termStr - Term token to use for building term for the query(without trailing '*' character!) Resulting Query built for the term exception: ParseException - throw in overridden method to disallow |
getWildcardQuery | protected Query getWildcardQuery(String field, String termStr) throws ParseException(Code) | | Factory method for generating a query. Called when parser
parses an input term token that contains one or more wildcard
characters (? and *), but is not a prefix term token (one
that has just a single * character at the end)
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.
Parameters: field - Name of the field query will use. Parameters: termStr - Term token that contains one or more wild cardcharacters (? or *), but is not simple prefix term Resulting Query built for the term exception: ParseException - throw in overridden method to disallow |
setDefaultOperator | public void setDefaultOperator(Operator op)(Code) | | Sets the boolean operator of the QueryParser.
In default mode (OR_OPERATOR ) terms without any modifiers
are considered optional: for example capital of Hungary is equal to
capital OR of OR Hungary .
In AND_OPERATOR mode terms are considered to be in conjuction: the
above mentioned query is parsed as capital AND of AND Hungary
|
setFuzzyMinSim | public void setFuzzyMinSim(float fuzzyMinSim)(Code) | | Set the minimum similarity for fuzzy queries.
Default is 0.5f.
|
setFuzzyPrefixLength | public void setFuzzyPrefixLength(int fuzzyPrefixLength)(Code) | | Set the prefix length for fuzzy queries. Default is 0.
Parameters: fuzzyPrefixLength - The fuzzyPrefixLength to set. |
setLocale | public void setLocale(Locale locale)(Code) | | Set locale used by date range parsing.
|
setLowercaseExpandedTerms | public void setLowercaseExpandedTerms(boolean lowercaseExpandedTerms)(Code) | | Whether terms of wildcard, prefix, fuzzy and range queries are to be automatically
lower-cased or not. Default is true .
|
setPhraseSlop | public void setPhraseSlop(int phraseSlop)(Code) | | Sets the default slop for phrases. If zero, then exact phrase matches
are required. Default value is zero.
|
|
|