|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.jackrabbit.core.query.lucene.fulltext.QueryParser
public class QueryParser
This class is generated by JavaCC. The only method that clients should need to call is parse(). 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 test cases.
Field Summary | |
---|---|
static int |
DEFAULT_OPERATOR_AND
|
static int |
DEFAULT_OPERATOR_OR
|
Token |
jj_nt
Next token. |
protected JJTQueryParserState |
jjtree
|
Token |
token
Current token. |
QueryParserTokenManager |
token_source
Generated Token Manager. |
Fields inherited from interface org.apache.jackrabbit.core.query.lucene.fulltext.QueryParserTreeConstants |
---|
JJTCLAUSE, JJTCONJUNCTION, JJTMODIFIERS, jjtNodeName, JJTQUERY, JJTTERM |
Fields inherited from interface org.apache.jackrabbit.core.query.lucene.fulltext.QueryParserConstants |
---|
_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, SYNTERM, TERM, tokenImage, WILDTERM |
Constructor Summary | |
---|---|
QueryParser(CharStream stream)
Constructor with user supplied CharStream. |
|
QueryParser(QueryParserTokenManager tm)
Constructor with generated Token Manager. |
|
QueryParser(String f,
org.apache.lucene.analysis.Analyzer a)
Constructs a query parser. |
|
QueryParser(String f,
org.apache.lucene.analysis.Analyzer a,
SynonymProvider sp)
Constructs a query parser. |
Method Summary | |
---|---|
protected void |
addClause(Vector clauses,
int conj,
int mods,
org.apache.lucene.search.Query q)
|
org.apache.lucene.search.Query |
Clause(String field)
|
int |
Conjunction()
|
void |
disable_tracing()
Disable tracing. |
void |
enable_tracing()
Enable tracing. |
static String |
escape(String s)
Returns a String where those characters that QueryParser expects to be escaped are escaped, i.e. |
ParseException |
generateParseException()
Generate ParseException. |
org.apache.lucene.analysis.Analyzer |
getAnalyzer()
|
protected org.apache.lucene.search.Query |
getBooleanQuery(Vector clauses)
Factory method for generating query, given a set of clauses. |
String |
getField()
|
protected org.apache.lucene.search.Query |
getFieldQuery(String field,
org.apache.lucene.analysis.Analyzer analyzer,
String queryText)
Note that parameter analyzer is ignored. |
protected org.apache.lucene.search.Query |
getFieldQuery(String field,
org.apache.lucene.analysis.Analyzer analyzer,
String queryText,
int slop)
Base implementation delegates to getFieldQuery(String, Analyzer, String) . |
protected org.apache.lucene.search.Query |
getFieldQuery(String field,
String queryText)
|
protected org.apache.lucene.search.Query |
getFieldQuery(String field,
String queryText,
int slop)
Base implementation delegates to getFieldQuery(String,String) . |
float |
getFuzzyMinSim()
Get the default minimal similarity for fuzzy queries. |
protected org.apache.lucene.search.Query |
getFuzzyQuery(String field,
String termStr)
Factory method for generating a query (similar to ( getWildcardQuery(java.lang.String, java.lang.String) ). |
protected org.apache.lucene.search.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 |
getLowercaseWildcardTerms()
|
Token |
getNextToken()
Get the next Token. |
int |
getOperator()
Gets implicit operator setting, which will be either DEFAULT_OPERATOR_AND or DEFAULT_OPERATOR_OR. |
int |
getPhraseSlop()
Gets the default slop for phrases. |
protected org.apache.lucene.search.Query |
getPrefixQuery(String field,
String termStr)
Factory method for generating a query (similar to ( getWildcardQuery(java.lang.String, java.lang.String) ). |
protected org.apache.lucene.search.Query |
getRangeQuery(String field,
org.apache.lucene.analysis.Analyzer analyzer,
String part1,
String part2,
boolean inclusive)
Note that parameter analyzer is ignored. |
protected org.apache.lucene.search.Query |
getRangeQuery(String field,
String part1,
String part2,
boolean inclusive)
|
protected org.apache.lucene.search.Query |
getSynonymQuery(String field,
String termStr)
Factory method for generating a synonym query. |
Token |
getToken(int index)
Get the specific Token. |
protected org.apache.lucene.search.Query |
getWildcardQuery(String field,
String termStr)
Factory method for generating a query. |
static void |
main(String[] args)
|
int |
Modifiers()
|
org.apache.lucene.search.Query |
parse(String query)
Parses a query string, returning a Query. |
static org.apache.lucene.search.Query |
parse(String query,
String field,
org.apache.lucene.analysis.Analyzer analyzer)
Parses a query string, returning a Query . |
org.apache.lucene.search.Query |
Query(String field)
|
void |
ReInit(CharStream stream)
Reinitialise. |
void |
ReInit(QueryParserTokenManager tm)
Reinitialise. |
void |
setFuzzyMinSim(float fuzzyMinSim)
Set the default minimum similarity for fuzzy queries. |
void |
setLocale(Locale locale)
Set locale used by date range parsing. |
void |
setLowercaseWildcardTerms(boolean lowercaseWildcardTerms)
|
void |
setOperator(int operator)
Sets the boolean operator of the QueryParser. |
void |
setPhraseSlop(int phraseSlop)
Sets the default slop for phrases. |
org.apache.lucene.search.Query |
Term(String field)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected JJTQueryParserState jjtree
public static final int DEFAULT_OPERATOR_OR
public static final int DEFAULT_OPERATOR_AND
public QueryParserTokenManager token_source
public Token token
public Token jj_nt
Constructor Detail |
---|
public QueryParser(String f, org.apache.lucene.analysis.Analyzer a)
f
- the default field for query terms.a
- used to find terms in the query text.public QueryParser(String f, org.apache.lucene.analysis.Analyzer a, SynonymProvider sp)
f
- the default field for query terms.a
- used to find terms in the query text.sp
- the synonym providerpublic QueryParser(CharStream stream)
public QueryParser(QueryParserTokenManager tm)
Method Detail |
---|
public static org.apache.lucene.search.Query parse(String query, String field, org.apache.lucene.analysis.Analyzer analyzer) throws ParseException
Query
.
query
- the query string to be parsed.field
- the default field for query terms.analyzer
- used to find terms in the query text.
ParseException
- if the parsing failspublic org.apache.lucene.search.Query parse(String query) throws ParseException
query
- the query string to be parsed.
ParseException
- if the parsing failspublic org.apache.lucene.analysis.Analyzer getAnalyzer()
public String getField()
public float getFuzzyMinSim()
public void setFuzzyMinSim(float fuzzyMinSim)
public void setPhraseSlop(int phraseSlop)
public int getPhraseSlop()
public void setOperator(int operator)
DEFAULT_OPERATOR_OR
) terms without any modifiers
are considered optional: for example capital of Hungary
is equal to
capital OR of OR Hungary
.DEFAULT_OPERATOR_AND
terms are considered to be in conjuction: the
above mentioned query is parsed as capital AND of AND Hungary
public int getOperator()
public void setLowercaseWildcardTerms(boolean lowercaseWildcardTerms)
public boolean getLowercaseWildcardTerms()
public void setLocale(Locale locale)
public Locale getLocale()
protected void addClause(Vector clauses, int conj, int mods, org.apache.lucene.search.Query q)
protected org.apache.lucene.search.Query getFieldQuery(String field, org.apache.lucene.analysis.Analyzer analyzer, String queryText) throws ParseException
getFieldQuery(String, String)
in future versions of Lucene.
Currently overwriting either of these methods works.
ParseException
- throw in overridden method to disallowprotected org.apache.lucene.search.Query getFieldQuery(String field, String queryText) throws ParseException
ParseException
- throw in overridden method to disallowprotected org.apache.lucene.search.Query getFieldQuery(String field, org.apache.lucene.analysis.Analyzer analyzer, String queryText, int slop) throws ParseException
getFieldQuery(String, Analyzer, String)
.
This method may be overwritten, for example, to return
a SpanNearQuery instead of a PhraseQuery.
Note that parameter analyzer is ignored. Calls inside the parser always
use class member analyser. This method will be deprecated and substituted
by getFieldQuery(String, String, int)
in future versions of Lucene.
Currently overwriting either of these methods works.
ParseException
- throw in overridden method to disallowprotected org.apache.lucene.search.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 org.apache.lucene.search.Query getRangeQuery(String field, org.apache.lucene.analysis.Analyzer analyzer, String part1, String part2, boolean inclusive) throws ParseException
getRangeQuery(String, String, String, boolean)
in future versions of Lucene.
Currently overwriting either of these methods works.
ParseException
- throw in overridden method to disallowprotected org.apache.lucene.search.Query getRangeQuery(String field, String part1, String part2, boolean inclusive) throws ParseException
ParseException
- throw in overridden method to disallowprotected org.apache.lucene.search.Query getBooleanQuery(Vector clauses) throws ParseException
clauses
- Vector that contains BooleanClause
instances
to join.
Query
object.
ParseException
- throw in overridden method to disallowprotected org.apache.lucene.search.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 org.apache.lucene.search.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 org.apache.lucene.search.Query getFuzzyQuery(String field, String termStr) 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 disallowprotected org.apache.lucene.search.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 (~floatNumber) appended.
field
- Name of the field query will use.termStr
- Term token to use for building term for the queryminSimilarity
- the minimum similarity required for a fuzzy match
Query
built for the term
ParseException
- throw in overridden method to disallowprotected org.apache.lucene.search.Query getSynonymQuery(String field, String termStr) throws ParseException
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
Exception
public final int Conjunction() throws ParseException
ParseException
public final int Modifiers() throws ParseException
ParseException
public final org.apache.lucene.search.Query Query(String field) throws ParseException
ParseException
public final org.apache.lucene.search.Query Clause(String field) throws ParseException
ParseException
public final org.apache.lucene.search.Query Term(String field) throws ParseException
ParseException
public void ReInit(CharStream stream)
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()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |