Java Doc for QueryParser.java in  » Net » lucene-connector » org » apache » lucene » queryParser » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » lucene connector » org.apache.lucene.queryParser 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.lucene.queryParser.QueryParser

All known Subclasses:   org.apache.lucene.queryParser.MultiFieldQueryParser,  org.apache.lucene.queryParser.analyzing.AnalyzingQueryParser,  net.bagaluten.jca.lucene.connector.impl.CompositeQuerySuggester,
QueryParser
public class QueryParser implements QueryParserConstants(Code)
This class is generated by JavaCC. The most important method is QueryParser.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.

In RangeQuery 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 QueryParser.setLocale(Locale) the locale . By default a date is converted into a search term using the deprecated DateField for compatibility reasons. To use the new DateTools to convert dates, a org.apache.lucene.document.DateTools.Resolution has to be set.

The date resolution that shall be used for RangeQueries can be set using QueryParser.setDateResolution(DateTools.Resolution) or QueryParser.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 use neither DateField nor DateTools in your index, you can create your own query parser that inherits QueryParser and overwrites QueryParser.getRangeQuery(String,String,String,boolean) to use a different method for date conversion.

Note that QueryParser is not thread-safe.


author:
   Brian Goetz
author:
   Peter Halacsy
author:
   Tatu Saloranta

Inner Class :final public static class Operator extends Parameter
Inner Class :final static class JJCalls

Field Summary
final public static  OperatorAND_OPERATOR
    
final public static  OperatorOR_OPERATOR
    
 booleanallowLeadingWildcard
    
 Analyzeranalyzer
    
 DateTools.ResolutiondateResolution
    
 booleanenablePositionIncrements
    
 Stringfield
    
 MapfieldToDateResolution
    
 floatfuzzyMinSim
    
 intfuzzyPrefixLength
    
 Localelocale
    
public  booleanlookingAhead
    
 booleanlowercaseExpandedTerms
    
 intphraseSlop
    
public  QueryParserTokenManagertoken_source
    
public  Tokentokenjj_nt
    
 booleanuseOldRangeQuery
    

Constructor Summary
public  QueryParser(String f, Analyzer a)
     Constructs a query parser.
public  QueryParser(CharStream stream)
    
public  QueryParser(QueryParserTokenManager tm)
    

Method Summary
final public  QueryClause(String field)
    
final public  intConjunction()
    
final public  intModifiers()
    
final public  QueryQuery(String field)
    
public  voidReInit(CharStream stream)
    
public  voidReInit(QueryParserTokenManager tm)
    
final public  QueryTerm(String field)
    
final public  QueryTopLevelQuery(String field)
    
protected  voidaddClause(Vector clauses, int conj, int mods, Query q)
    
final public  voiddisable_tracing()
    
final public  voidenable_tracing()
    
public static  Stringescape(String s)
     Returns a String where those characters that QueryParser expects to be escaped are escaped by a preceding \.
public  ParseExceptiongenerateParseException()
    
public  booleangetAllowLeadingWildcard()
    
public  AnalyzergetAnalyzer()
    
protected  QuerygetBooleanQuery(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  QuerygetBooleanQuery(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  DateTools.ResolutiongetDateResolution(String fieldName)
     Returns the date resolution that is used by RangeQueries for the given field.
public  OperatorgetDefaultOperator()
     Gets implicit operator setting, which will be either AND_OPERATOR or OR_OPERATOR.
public  booleangetEnablePositionIncrements()
    
public  StringgetField()
    
protected  QuerygetFieldQuery(String field, String queryText)
    
protected  QuerygetFieldQuery(String field, String queryText, int slop)
     Base implementation delegates to QueryParser.getFieldQuery(String,String) .
public  floatgetFuzzyMinSim()
     Get the minimal similarity for fuzzy queries.
public  intgetFuzzyPrefixLength()
     Get the prefix length for fuzzy queries.
protected  QuerygetFuzzyQuery(String field, String termStr, float minSimilarity)
     Factory method for generating a query (similar to QueryParser.getWildcardQuery ).
public  LocalegetLocale()
     Returns current locale, allowing access by subclasses.
public  booleangetLowercaseExpandedTerms()
    
final public  TokengetNextToken()
    
public  intgetPhraseSlop()
     Gets the default slop for phrases.
protected  QuerygetPrefixQuery(String field, String termStr)
     Factory method for generating a query (similar to QueryParser.getWildcardQuery ).
protected  QuerygetRangeQuery(String field, String part1, String part2, boolean inclusive)
    
final public  TokengetToken(int index)
    
public  booleangetUseOldRangeQuery()
    
protected  QuerygetWildcardQuery(String field, String termStr)
     Factory method for generating a query.
public static  voidmain(String[] args)
     Command line tool to test QueryParser, using org.apache.lucene.analysis.SimpleAnalyzer .
public  Queryparse(String query)
     Parses a query string, returning a org.apache.lucene.search.Query .
public  voidsetAllowLeadingWildcard(boolean allowLeadingWildcard)
     Set to true to allow leading wildcard characters.

When set, * or ? are allowed as the first character of a PrefixQuery and WildcardQuery. Note that this can produce very slow queries on big indexes.

public  voidsetDateResolution(DateTools.Resolution dateResolution)
     Sets the default date resolution used by RangeQueries for fields for which no specific date resolutions has been set.
public  voidsetDateResolution(String fieldName, DateTools.Resolution dateResolution)
     Sets the date resolution used by RangeQueries for a specific field.
public  voidsetDefaultOperator(Operator op)
     Sets the boolean operator of the QueryParser.
public  voidsetEnablePositionIncrements(boolean enable)
     Set to true to enable position increments in result query.

When set, result phrase and multi-phrase queries will be aware of position increments. Useful when e.g.

public  voidsetFuzzyMinSim(float fuzzyMinSim)
     Set the minimum similarity for fuzzy queries.
public  voidsetFuzzyPrefixLength(int fuzzyPrefixLength)
     Set the prefix length for fuzzy queries.
public  voidsetLocale(Locale locale)
     Set locale used by date range parsing.
public  voidsetLowercaseExpandedTerms(boolean lowercaseExpandedTerms)
     Whether terms of wildcard, prefix, fuzzy and range queries are to be automatically lower-cased or not.
public  voidsetPhraseSlop(int phraseSlop)
     Sets the default slop for phrases.
public  voidsetUseOldRangeQuery(boolean useOldRangeQuery)
     By default QueryParser uses new ConstantScoreRangeQuery in preference to RangeQuery for range queries.

Field Detail
AND_OPERATOR
final public static Operator AND_OPERATOR(Code)
Alternative form of QueryParser.Operator.AND



OR_OPERATOR
final public static Operator OR_OPERATOR(Code)
Alternative form of QueryParser.Operator.OR



allowLeadingWildcard
boolean allowLeadingWildcard(Code)



analyzer
Analyzer analyzer(Code)



dateResolution
DateTools.Resolution dateResolution(Code)



enablePositionIncrements
boolean enablePositionIncrements(Code)



field
String field(Code)



fieldToDateResolution
Map fieldToDateResolution(Code)



fuzzyMinSim
float fuzzyMinSim(Code)



fuzzyPrefixLength
int fuzzyPrefixLength(Code)



locale
Locale locale(Code)



lookingAhead
public boolean lookingAhead(Code)



lowercaseExpandedTerms
boolean lowercaseExpandedTerms(Code)



phraseSlop
int phraseSlop(Code)



token_source
public QueryParserTokenManager token_source(Code)



tokenjj_nt
public Token tokenjj_nt(Code)



useOldRangeQuery
boolean useOldRangeQuery(Code)




Constructor Detail
QueryParser
public QueryParser(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.



QueryParser
public QueryParser(CharStream stream)(Code)



QueryParser
public QueryParser(QueryParserTokenManager tm)(Code)




Method Detail
Clause
final public Query Clause(String field) throws ParseException(Code)



Conjunction
final public int Conjunction() throws ParseException(Code)



Modifiers
final public int Modifiers() throws ParseException(Code)



Query
final public Query Query(String field) throws ParseException(Code)



ReInit
public void ReInit(CharStream stream)(Code)



ReInit
public void ReInit(QueryParserTokenManager tm)(Code)



Term
final public Query Term(String field) throws ParseException(Code)



TopLevelQuery
final public Query TopLevelQuery(String field) throws ParseException(Code)



addClause
protected void addClause(Vector clauses, int conj, int mods, 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 \.



generateParseException
public ParseException generateParseException()(Code)



getAllowLeadingWildcard
public boolean getAllowLeadingWildcard()(Code)

See Also:   QueryParser.setAllowLeadingWildcard(boolean)



getAnalyzer
public Analyzer getAnalyzer()(Code)
Returns the analyzer.



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



getDateResolution
public DateTools.Resolution getDateResolution(String fieldName)(Code)
Returns the date resolution that is used by RangeQueries for the given field. Returns null, if no default or field specific date resolution has been set for the given field.



getDefaultOperator
public Operator getDefaultOperator()(Code)
Gets implicit operator setting, which will be either AND_OPERATOR or OR_OPERATOR.



getEnablePositionIncrements
public boolean getEnablePositionIncrements()(Code)

See Also:   QueryParser.setEnablePositionIncrements(boolean)



getField
public String getField()(Code)
Returns the field.



getFieldQuery
protected Query getFieldQuery(String field, String queryText) throws ParseException(Code)

exception:
  ParseException - throw in overridden method to disallow



getFieldQuery
protected Query getFieldQuery(String field, String queryText, int slop) throws ParseException(Code)
Base implementation delegates to QueryParser.getFieldQuery(String,String) . This method may be overridden, for example, to return a SpanNearQuery instead of a PhraseQuery.
exception:
  ParseException - throw in overridden method to disallow



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 QueryParser.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.



getLowercaseExpandedTerms
public boolean getLowercaseExpandedTerms()(Code)

See Also:   QueryParser.setLowercaseExpandedTerms(boolean)



getNextToken
final public Token getNextToken()(Code)



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 QueryParser.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




getRangeQuery
protected Query getRangeQuery(String field, String part1, String part2, boolean inclusive) throws ParseException(Code)

exception:
  ParseException - throw in overridden method to disallow



getToken
final public Token getToken(int index)(Code)



getUseOldRangeQuery
public boolean getUseOldRangeQuery()(Code)

See Also:   QueryParser.setUseOldRangeQuery(boolean)



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




main
public static void main(String[] args) throws Exception(Code)
Command line tool to test QueryParser, using org.apache.lucene.analysis.SimpleAnalyzer . Usage:
java org.apache.lucene.queryParser.QueryParser <input>



parse
public Query parse(String query) throws ParseException(Code)
Parses a query string, returning a org.apache.lucene.search.Query .
Parameters:
  query - the query string to be parsed.
throws:
  ParseException - if the parsing fails



setAllowLeadingWildcard
public void setAllowLeadingWildcard(boolean allowLeadingWildcard)(Code)
Set to true to allow leading wildcard characters.

When set, * or ? are allowed as the first character of a PrefixQuery and WildcardQuery. Note that this can produce very slow queries on big indexes.

Default: false.




setDateResolution
public void setDateResolution(DateTools.Resolution dateResolution)(Code)
Sets the default date resolution used by RangeQueries for fields for which no specific date resolutions has been set. Field specific resolutions can be set with QueryParser.setDateResolution(String,DateTools.Resolution) .
Parameters:
  dateResolution - the default date resolution to set



setDateResolution
public void setDateResolution(String fieldName, DateTools.Resolution dateResolution)(Code)
Sets the date resolution used by RangeQueries for a specific field.
Parameters:
  fieldName - field for which the date resolution is to be set
Parameters:
  dateResolution - date resolution to set



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



setEnablePositionIncrements
public void setEnablePositionIncrements(boolean enable)(Code)
Set to true to enable position increments in result query.

When set, result phrase and multi-phrase queries will be aware of position increments. Useful when e.g. a StopFilter increases the position increment of the token that follows an omitted token.

Default: false.




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.



setUseOldRangeQuery
public void setUseOldRangeQuery(boolean useOldRangeQuery)(Code)
By default QueryParser uses new ConstantScoreRangeQuery in preference to RangeQuery for range queries. This implementation is generally preferable because it a) Runs faster b) Does not have the scarcity of range terms unduly influence score c) avoids any "TooManyBooleanClauses" exception. However, if your application really needs to use the old-fashioned RangeQuery and the above points are not required then set this option to true Default is false.



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.