Lucene.Net  3.0.3
Lucene.Net is a port of the Lucene search engine library, written in C# and targeted at .NET runtime users.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Properties | List of all members
Lucene.Net.QueryParsers.QueryParser Class Reference

This class is generated by JavaCC. The most important method is Parse(String). More...

Inherits Lucene.Net.QueryParsers.QueryParserConstants.

Inherited by Lucene.Net.QueryParsers.MultiFieldQueryParser.

Classes

class  JJCalls
 

Public Types

enum  Operator { OR, AND }
 

Public Member Functions

 QueryParser (Version matchVersion, String f, Analyzer a)
 
virtual Query Parse (String query)
 Parses a query string, returning a Lucene.Net.Search.Query.
 
virtual void SetDateResolution (DateTools.Resolution dateResolution)
 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 SetDateResolution(String, DateTools.Resolution).
 
virtual void SetDateResolution (String fieldName, DateTools.Resolution dateResolution)
 Sets the date resolution used by RangeQueries for a specific field.
 
virtual DateTools.Resolution getDateResolution (String fieldName)
 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.
 
int Conjunction ()
 
int Modifiers ()
 
Query TopLevelQuery (String field)
 
Query Query (String field)
 
Query Clause (String field)
 
Query Term (String field)
 
void ReInit (ICharStream stream)
 Reinitialise.
 
void ReInit (QueryParserTokenManager tm)
 Reinitialise.
 
Token GetNextToken ()
 Get the next Token.
 
Token getToken (int index)
 Get the specific Token.
 
virtual ParseException GenerateParseException ()
 Generate ParseException.
 
void Enable_tracing ()
 Enable tracing.
 
void Disable_tracing ()
 Disable tracing.
 

Static Public Member Functions

static String Escape (String s)
 Returns a String where those characters that QueryParser expects to be escaped are escaped by a preceding </c>.
 
static void Main (String[] args)
 Command line tool to test QueryParser, using Lucene.Net.Analysis.SimpleAnalyzer. Usage:
java Lucene.Net.QueryParsers.QueryParser <input>
 

Public Attributes

QueryParserTokenManager token_source
 
Token token
 
Token jj_nt
 

Static Public Attributes

static Operator AND_OPERATOR = Operator.AND
 Alternative form of QueryParser.Operator.AND
 
static Operator OR_OPERATOR = Operator.OR
 Alternative form of QueryParser.Operator.OR
 

Protected Member Functions

 QueryParser (QueryParserTokenManager tm)
 Constructor with generated Token Manager.
 

Properties

virtual Analyzer Analyzer [get]
 Returns the analyzer.
 
virtual string Field [get]
 Returns the field.
 
virtual float FuzzyMinSim [get, set]
 Gets or sets the minimal similarity for fuzzy queries. Default is 0.5f.
 
virtual int FuzzyPrefixLength [get, set]
 Gets or sets the prefix length for fuzzy queries.
 
virtual int PhraseSlop [get, set]
 Gets or sets the default slop for phrases. If zero, then exact phrase matches are required. Default value is zero.
 
virtual bool AllowLeadingWildcard [get, set]
 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.
 
virtual bool EnablePositionIncrements [get, set]
 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.
 
virtual Operator DefaultOperator [get, set]
 Gets or 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 conjunction: the above mentioned query is parsed as capital AND of AND Hungary
 
virtual bool LowercaseExpandedTerms [get, set]
 Whether terms of wildcard, prefix, fuzzy and range queries are to be automatically lower-cased or not. Default is true.
 
virtual RewriteMethod MultiTermRewriteMethod [get, set]
 By default QueryParser uses MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT when creating a PrefixQuery, WildcardQuery or RangeQuery. This implementation is generally preferable because it a) Runs faster b) Does not have the scarcity of terms unduly influence score c) avoids any "TooManyBooleanClauses" exception. However, if your application really needs to use the old-fashioned BooleanQuery expansion rewriting and the above points are not relevant then use this to change the rewrite method.
 
virtual CultureInfo Locale [get, set]
 Gets or sets locale used by date range parsing.
 
virtual CompareInfo RangeCollator [get, set]
 Gets or sets the collator used to determine index term inclusion in ranges for RangeQuerys. WARNING: Setting the rangeCollator to a non-null collator using this method will cause every single index Term in the Field referenced by lowerTerm and/or upperTerm to be examined. Depending on the number of index Terms in this Field, the operation could be very slow.
 

Additional Inherited Members

- Protected Attributes inherited from Lucene.Net.QueryParsers.QueryParserConstants
const int RangeExToken = 1
 Lexical state.
 

Detailed Description

This class is generated by JavaCC. The most important method is Parse(String).

The syntax for query strings is as follows: A Query is a series of clauses. A clause may be prefixed by:

A clause may be either:

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 TermRangeQuerys, 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. 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 Lucene.Net.Documents.DateTools.Resolution has to be set.

The date resolution that shall be used for RangeQueries can be set using SetDateResolution(DateTools.Resolution) or 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 GetRangeQuery(String, String, String, bool) 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: 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:

Definition at line 130 of file QueryParser.cs.

Member Enumeration Documentation

enum Lucene.Net.QueryParsers.QueryParser.Operator
Enumerator
OR 
AND 

Definition at line 180 of file QueryParser.cs.

Constructor & Destructor Documentation

Lucene.Net.QueryParsers.QueryParser.QueryParser ( Version  matchVersion,
String  f,
Analyzer  a 
)

Definition at line 192 of file QueryParser.cs.

Lucene.Net.QueryParsers.QueryParser.QueryParser ( QueryParserTokenManager  tm)
protected

Constructor with generated Token Manager.

Definition at line 1814 of file QueryParser.cs.

Member Function Documentation

Query Lucene.Net.QueryParsers.QueryParser.Clause ( String  field)

Definition at line 1345 of file QueryParser.cs.

int Lucene.Net.QueryParsers.QueryParser.Conjunction ( )

Definition at line 1212 of file QueryParser.cs.

void Lucene.Net.QueryParsers.QueryParser.Disable_tracing ( )

Disable tracing.

Definition at line 2027 of file QueryParser.cs.

void Lucene.Net.QueryParsers.QueryParser.Enable_tracing ( )

Enable tracing.

Definition at line 2022 of file QueryParser.cs.

static String Lucene.Net.QueryParsers.QueryParser.Escape ( String  s)
static

Returns a String where those characters that QueryParser expects to be escaped are escaped by a preceding </c>.

Definition at line 1175 of file QueryParser.cs.

virtual ParseException Lucene.Net.QueryParsers.QueryParser.GenerateParseException ( )
virtual

Generate ParseException.

Definition at line 1975 of file QueryParser.cs.

virtual DateTools.Resolution Lucene.Net.QueryParsers.QueryParser.getDateResolution ( String  fieldName)
virtual

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.

Definition at line 394 of file QueryParser.cs.

Token Lucene.Net.QueryParsers.QueryParser.GetNextToken ( )

Get the next Token.

Definition at line 1905 of file QueryParser.cs.

Token Lucene.Net.QueryParsers.QueryParser.getToken ( int  index)

Get the specific Token.

Definition at line 1915 of file QueryParser.cs.

static void Lucene.Net.QueryParsers.QueryParser.Main ( String[]  args)
static

Command line tool to test QueryParser, using Lucene.Net.Analysis.SimpleAnalyzer. Usage:
java Lucene.Net.QueryParsers.QueryParser <input>

Definition at line 1198 of file QueryParser.cs.

int Lucene.Net.QueryParsers.QueryParser.Modifiers ( )

Definition at line 1245 of file QueryParser.cs.

virtual Query Lucene.Net.QueryParsers.QueryParser.Parse ( String  query)
virtual

Parses a query string, returning a Lucene.Net.Search.Query.

Parameters
querythe query string to be parsed.

<throws> ParseException if the parsing fails </throws>

Definition at line 217 of file QueryParser.cs.

Query Lucene.Net.QueryParsers.QueryParser.Query ( String  field)

Definition at line 1295 of file QueryParser.cs.

void Lucene.Net.QueryParsers.QueryParser.ReInit ( ICharStream  stream)

Reinitialise.

Definition at line 1803 of file QueryParser.cs.

void Lucene.Net.QueryParsers.QueryParser.ReInit ( QueryParserTokenManager  tm)

Reinitialise.

Definition at line 1825 of file QueryParser.cs.

virtual void Lucene.Net.QueryParsers.QueryParser.SetDateResolution ( DateTools.Resolution  dateResolution)
virtual

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 SetDateResolution(String, DateTools.Resolution).

Parameters
dateResolutionthe default date resolution to set

Definition at line 362 of file QueryParser.cs.

virtual void Lucene.Net.QueryParsers.QueryParser.SetDateResolution ( String  fieldName,
DateTools.Resolution  dateResolution 
)
virtual

Sets the date resolution used by RangeQueries for a specific field.

Parameters
fieldNamefield for which the date resolution is to be set
dateResolutiondate resolution to set

Definition at line 374 of file QueryParser.cs.

Query Lucene.Net.QueryParsers.QueryParser.Term ( String  field)

Definition at line 1422 of file QueryParser.cs.

Query Lucene.Net.QueryParsers.QueryParser.TopLevelQuery ( String  field)

Definition at line 1284 of file QueryParser.cs.

Member Data Documentation

Operator Lucene.Net.QueryParsers.QueryParser.AND_OPERATOR = Operator.AND
static

Alternative form of QueryParser.Operator.AND

Definition at line 144 of file QueryParser.cs.

Token Lucene.Net.QueryParsers.QueryParser.jj_nt

Definition at line 1759 of file QueryParser.cs.

Operator Lucene.Net.QueryParsers.QueryParser.OR_OPERATOR = Operator.OR
static

Alternative form of QueryParser.Operator.OR

Definition at line 147 of file QueryParser.cs.

Token Lucene.Net.QueryParsers.QueryParser.token

Definition at line 1757 of file QueryParser.cs.

QueryParserTokenManager Lucene.Net.QueryParsers.QueryParser.token_source

Definition at line 1755 of file QueryParser.cs.

Property Documentation

virtual bool Lucene.Net.QueryParsers.QueryParser.AllowLeadingWildcard
getset

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.

Definition at line 290 of file QueryParser.cs.

virtual Analyzer Lucene.Net.QueryParsers.QueryParser.Analyzer
get

Returns the analyzer.

Definition at line 243 of file QueryParser.cs.

virtual Operator Lucene.Net.QueryParsers.QueryParser.DefaultOperator
getset

Gets or 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 conjunction: the above mentioned query is parsed as capital AND of AND Hungary

Definition at line 318 of file QueryParser.cs.

virtual bool Lucene.Net.QueryParsers.QueryParser.EnablePositionIncrements
getset

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.

Definition at line 305 of file QueryParser.cs.

virtual string Lucene.Net.QueryParsers.QueryParser.Field
get

Returns the field.

Definition at line 249 of file QueryParser.cs.

virtual float Lucene.Net.QueryParsers.QueryParser.FuzzyMinSim
getset

Gets or sets the minimal similarity for fuzzy queries. Default is 0.5f.

Definition at line 258 of file QueryParser.cs.

virtual int Lucene.Net.QueryParsers.QueryParser.FuzzyPrefixLength
getset

Gets or sets the prefix length for fuzzy queries.

Returns the fuzzyPrefixLength.

Definition at line 266 of file QueryParser.cs.

virtual CultureInfo Lucene.Net.QueryParsers.QueryParser.Locale
getset

Gets or sets locale used by date range parsing.

Definition at line 350 of file QueryParser.cs.

virtual bool Lucene.Net.QueryParsers.QueryParser.LowercaseExpandedTerms
getset

Whether terms of wildcard, prefix, fuzzy and range queries are to be automatically lower-cased or not. Default is true.

Definition at line 327 of file QueryParser.cs.

virtual RewriteMethod Lucene.Net.QueryParsers.QueryParser.MultiTermRewriteMethod
getset

By default QueryParser uses MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT when creating a PrefixQuery, WildcardQuery or RangeQuery. This implementation is generally preferable because it a) Runs faster b) Does not have the scarcity of terms unduly influence score c) avoids any "TooManyBooleanClauses" exception. However, if your application really needs to use the old-fashioned BooleanQuery expansion rewriting and the above points are not relevant then use this to change the rewrite method.

Definition at line 343 of file QueryParser.cs.

virtual int Lucene.Net.QueryParsers.QueryParser.PhraseSlop
getset

Gets or sets the default slop for phrases. If zero, then exact phrase matches are required. Default value is zero.

Definition at line 275 of file QueryParser.cs.

virtual CompareInfo Lucene.Net.QueryParsers.QueryParser.RangeCollator
getset

Gets or sets the collator used to determine index term inclusion in ranges for RangeQuerys. WARNING: Setting the rangeCollator to a non-null collator using this method will cause every single index Term in the Field referenced by lowerTerm and/or upperTerm to be examined. Depending on the number of index Terms in this Field, the operation could be very slow.

the collator to use when constructing RangeQuerys

Definition at line 429 of file QueryParser.cs.


The documentation for this class was generated from the following file: