Class QueryParserBase
This class is overridden by QueryParser.
Implements
Inherited Members
Namespace: Lucene.Net.QueryParsers.Classic
Assembly: Lucene.Net.QueryParser.dll
Syntax
public abstract class QueryParserBase : QueryBuilder, ICommonQueryParserConfiguration
Constructors
QueryParserBase()
So the generated QueryParser(CharStream) won't error out
Declaration
protected QueryParserBase()
Fields
AND_OPERATOR
Alternative form of AND
Declaration
public const Operator AND_OPERATOR = AND
Field Value
Type | Description |
---|---|
Operator |
CONJ_AND
This class is overridden by QueryParser.
Declaration
protected const int CONJ_AND = 1
Field Value
Type | Description |
---|---|
int |
CONJ_NONE
This class is overridden by QueryParser.
Declaration
protected const int CONJ_NONE = 0
Field Value
Type | Description |
---|---|
int |
CONJ_OR
This class is overridden by QueryParser.
Declaration
protected const int CONJ_OR = 2
Field Value
Type | Description |
---|---|
int |
MOD_NONE
This class is overridden by QueryParser.
Declaration
protected const int MOD_NONE = 0
Field Value
Type | Description |
---|---|
int |
MOD_NOT
This class is overridden by QueryParser.
Declaration
protected const int MOD_NOT = 10
Field Value
Type | Description |
---|---|
int |
MOD_REQ
This class is overridden by QueryParser.
Declaration
protected const int MOD_REQ = 11
Field Value
Type | Description |
---|---|
int |
OR_OPERATOR
Alternative form of OR
Declaration
public const Operator OR_OPERATOR = OR
Field Value
Type | Description |
---|---|
Operator |
m_field
This class is overridden by QueryParser.
Declaration
protected string m_field
Field Value
Type | Description |
---|---|
string |
Properties
AllowLeadingWildcard
Set to true
to allow leading wildcard characters.
*
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.
Declaration
public virtual bool AllowLeadingWildcard { get; set; }
Property Value
Type | Description |
---|---|
bool |
AnalyzeRangeTerms
Get or Set whether or not to analyze range terms when constructing Lucene.Net.Search.TermRangeQuerys. For example, setting this to true can enable analyzing terms into collation keys for locale-sensitive Lucene.Net.Search.TermRangeQuery.
Declaration
public virtual bool AnalyzeRangeTerms { get; set; }
Property Value
Type | Description |
---|---|
bool |
AutoGeneratePhraseQueries
Set to true if phrase queries will be automatically generated when the analyzer returns more than one term from whitespace delimited text. NOTE: this behavior may not be suitable for all languages.
Set to false if phrase queries should only be generated when surrounded by double quotes.Declaration
public bool AutoGeneratePhraseQueries { get; set; }
Property Value
Type | Description |
---|---|
bool |
DefaultOperator
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
.
capital AND of AND Hungary
Declaration
public virtual Operator DefaultOperator { get; set; }
Property Value
Type | Description |
---|---|
Operator |
Field
Returns the default field.
Declaration
public virtual string Field { get; }
Property Value
Type | Description |
---|---|
string |
FuzzyMinSim
Get or Set the minimum similarity for fuzzy queries. Default is 2f.
Declaration
public virtual float FuzzyMinSim { get; set; }
Property Value
Type | Description |
---|---|
float |
FuzzyPrefixLength
Get or Set the prefix length for fuzzy queries. Default is 0.
Declaration
public virtual int FuzzyPrefixLength { get; set; }
Property Value
Type | Description |
---|---|
int |
Locale
Get or Set locale used by date range parsing, lowercasing, and other locale-sensitive operations.
By default, the culture isnull
, which indicates to read the culture on the fly
from CurrentCulture. This ensures if you change the culture on
the current thread, QueryParser will utilize it. You can also explicitly set a culture.
Setting the culture to null
will restore the default behavior if you have explicitly set a culture.
Declaration
public virtual CultureInfo Locale { get; set; }
Property Value
Type | Description |
---|---|
CultureInfo |
LowercaseExpandedTerms
Whether terms of wildcard, prefix, fuzzy and range queries are to be automatically
lower-cased or not. Default is true
.
Declaration
public virtual bool LowercaseExpandedTerms { get; set; }
Property Value
Type | Description |
---|---|
bool |
MultiTermRewriteMethod
By default QueryParser uses Lucene.Net.Search.MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT when creating a Lucene.Net.Search.PrefixQuery, Lucene.Net.Search.WildcardQuery or Lucene.Net.Search.TermRangeQuery. This implementation is generally preferable because it a) Runs faster b) Does not have the scarcity of terms unduly influence score c) avoids any Lucene.Net.Search.BooleanQuery.TooManyClausesException exception. However, if your application really needs to use the old-fashioned Lucene.Net.Search.BooleanQuery expansion rewriting and the above points are not relevant then use this to change the rewrite method.
Declaration
public virtual MultiTermQuery.RewriteMethod MultiTermRewriteMethod { get; set; }
Property Value
Type | Description |
---|---|
MultiTermQuery.RewriteMethod |
PhraseSlop
Gets or Sets the default slop for phrases. If zero, then exact phrase matches are required. Default value is zero.
Declaration
public virtual int PhraseSlop { get; set; }
Property Value
Type | Description |
---|---|
int |
TimeZone
Get or Set the current time zone for date and time parsing operations.
By default, the time zone isnull
, which indicates to read the time zone on the fly
from Local. This ensures if you change the time zone on
the current system, QueryParser will utilize it. You can also explicitly set a time zone.
Setting the time zone to null
will restore the default behavior if you have explicitly set a time zone.
Declaration
public virtual TimeZoneInfo TimeZone { get; set; }
Property Value
Type | Description |
---|---|
TimeZoneInfo |
Methods
AddClause(IList<BooleanClause>, int, int, Query)
This class is overridden by QueryParser.
Declaration
protected virtual void AddClause(IList<BooleanClause> clauses, int conj, int mods, Query q)
Parameters
Type | Name | Description |
---|---|---|
IList<BooleanClause> | clauses | |
int | conj | |
int | mods | |
Query | q |
AnalyzeMultitermTerm(string, string, Analyzer)
This class is overridden by QueryParser.
Declaration
protected virtual BytesRef AnalyzeMultitermTerm(string field, string part, Analyzer analyzerIn)
Parameters
Type | Name | Description |
---|---|---|
string | field | |
string | part | |
Analyzer | analyzerIn |
Returns
Type | Description |
---|---|
BytesRef |
Escape(string)
Returns a string where those characters that QueryParser expects to be escaped are escaped by a preceding
</code>
.
Declaration
public static string Escape(string s)
Parameters
Type | Name | Description |
---|---|---|
string | s |
Returns
Type | Description |
---|---|
string |
GetBooleanQuery(IList<BooleanClause>)
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.Declaration
protected virtual Query GetBooleanQuery(IList<BooleanClause> clauses)
Parameters
Type | Name | Description |
---|---|---|
IList<BooleanClause> | clauses | List that contains Lucene.Net.Search.BooleanClause instances to join. |
Returns
Type | Description |
---|---|
Query | Resulting Lucene.Net.Search.Query object. |
Exceptions
Type | Condition |
---|---|
ParseException | throw in overridden method to disallow |
GetBooleanQuery(IList<BooleanClause>, bool)
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.Declaration
protected virtual Query GetBooleanQuery(IList<BooleanClause> clauses, bool disableCoord)
Parameters
Type | Name | Description |
---|---|---|
IList<BooleanClause> | clauses | List that contains Lucene.Net.Search.BooleanClause instances to join. |
bool | disableCoord | true if coord scoring should be disabled. |
Returns
Type | Description |
---|---|
Query | Resulting Lucene.Net.Search.Query object. |
Exceptions
Type | Condition |
---|---|
ParseException | throw in overridden method to disallow |
GetDateResolution(string)
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.
Declaration
public virtual DateResolution GetDateResolution(string fieldName)
Parameters
Type | Name | Description |
---|---|---|
string | fieldName |
Returns
Type | Description |
---|---|
DateResolution |
GetFieldQuery(string, string, bool)
This class is overridden by QueryParser.
Declaration
protected virtual Query GetFieldQuery(string field, string queryText, bool quoted)
Parameters
Type | Name | Description |
---|---|---|
string | field | |
string | queryText | |
bool | quoted |
Returns
Type | Description |
---|---|
Query |
Exceptions
Type | Condition |
---|---|
ParseException | throw in overridden method to disallow |
GetFieldQuery(string, string, int)
Base implementation delegates to GetFieldQuery(string, string, bool). This method may be overridden, for example, to return a Lucene.Net.Search.Spans.SpanNearQuery instead of a Lucene.Net.Search.PhraseQuery.
Declaration
protected virtual Query GetFieldQuery(string field, string queryText, int slop)
Parameters
Type | Name | Description |
---|---|---|
string | field | |
string | queryText | |
int | slop |
Returns
Type | Description |
---|---|
Query |
Exceptions
Type | Condition |
---|---|
ParseException | throw in overridden method to disallow |
GetFuzzyQuery(string, string, float)
Factory method for generating a query (similar to GetWildcardQuery(string, string)). Called when parser parses an input term token that has the fuzzy suffix (~) appended.
Declaration
protected virtual Query GetFuzzyQuery(string field, string termStr, float minSimilarity)
Parameters
Type | Name | Description |
---|---|---|
string | field | Name of the field query will use. |
string | termStr | Term token to use for building term for the query |
float | minSimilarity | minimum similarity |
Returns
Type | Description |
---|---|
Query | Resulting Lucene.Net.Search.Query built for the term |
Exceptions
Type | Condition |
---|---|
ParseException | throw in overridden method to disallow |
GetPrefixQuery(string, string)
Factory method for generating a query (similar to GetWildcardQuery(string, 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.Declaration
protected virtual Query GetPrefixQuery(string field, string termStr)
Parameters
Type | Name | Description |
---|---|---|
string | field | Name of the field query will use. |
string | termStr | Term token to use for building term for the query |
Returns
Type | Description |
---|---|
Query | Resulting Lucene.Net.Search.Query built for the term |
Exceptions
Type | Condition |
---|---|
ParseException | throw in overridden method to disallow |
GetRangeQuery(string, string, string, bool, bool)
This class is overridden by QueryParser.
Declaration
protected virtual Query GetRangeQuery(string field, string part1, string part2, bool startInclusive, bool endInclusive)
Parameters
Type | Name | Description |
---|---|---|
string | field | |
string | part1 | |
string | part2 | |
bool | startInclusive | |
bool | endInclusive |
Returns
Type | Description |
---|---|
Query |
GetRegexpQuery(string, string)
Factory method for generating a query. Called when parser parses an input term token that contains a regular expression query.
Depending on settings, pattern term may be lower-cased automatically. It will not go through the default Analyzer, however, since normal Analyzers are unlikely to work properly with regular expression templates. Can be overridden by extending classes, to provide custom handling for regular expression queries, which may be necessary due to missing analyzer calls.Declaration
protected virtual Query GetRegexpQuery(string field, string termStr)
Parameters
Type | Name | Description |
---|---|---|
string | field | Name of the field query will use. |
string | termStr | Term token that contains a regular expression |
Returns
Type | Description |
---|---|
Query | Resulting Lucene.Net.Search.Query built for the term |
Exceptions
Type | Condition |
---|---|
ParseException | throw in overridden method to disallow |
GetWildcardQuery(string, string)
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.Declaration
protected virtual Query GetWildcardQuery(string field, string termStr)
Parameters
Type | Name | Description |
---|---|---|
string | field | Name of the field query will use. |
string | termStr | Term token that contains one or more wild card characters (? or *), but is not simple prefix term |
Returns
Type | Description |
---|---|
Query | Resulting Lucene.Net.Search.Query built for the term |
Exceptions
Type | Condition |
---|---|
ParseException | throw in overridden method to disallow |
Init(LuceneVersion, string, Analyzer)
Initializes a query parser. Called by the QueryParser constructor
Declaration
public virtual void Init(LuceneVersion matchVersion, string f, Analyzer a)
Parameters
Type | Name | Description |
---|---|---|
LuceneVersion | matchVersion | Lucene version to match. |
string | f | the default field for query terms. |
Analyzer | a | used to find terms in the query text. |
NewBooleanClause(Query, Occur)
Builds a new Lucene.Net.Search.BooleanClause instance
Declaration
protected virtual BooleanClause NewBooleanClause(Query q, Occur occur)
Parameters
Type | Name | Description |
---|---|---|
Query | q | sub query |
Occur | occur | how this clause should occur when matching documents |
Returns
Type | Description |
---|---|
BooleanClause | new Lucene.Net.Search.BooleanClause instance |
NewFieldQuery(Analyzer, string, string, bool)
This class is overridden by QueryParser.
Declaration
protected virtual Query NewFieldQuery(Analyzer analyzer, string field, string queryText, bool quoted)
Parameters
Type | Name | Description |
---|---|---|
Analyzer | analyzer | |
string | field | |
string | queryText | |
bool | quoted |
Returns
Type | Description |
---|---|
Query |
Exceptions
Type | Condition |
---|---|
ParseException | throw in overridden method to disallow |
NewFuzzyQuery(Term, float, int)
Builds a new Lucene.Net.Search.FuzzyQuery instance
Declaration
protected virtual Query NewFuzzyQuery(Term term, float minimumSimilarity, int prefixLength)
Parameters
Type | Name | Description |
---|---|---|
Term | term | Term |
float | minimumSimilarity | minimum similarity |
int | prefixLength | prefix length |
Returns
Type | Description |
---|---|
Query | new Lucene.Net.Search.FuzzyQuery Instance |
NewMatchAllDocsQuery()
Builds a new Lucene.Net.Search.MatchAllDocsQuery instance
Declaration
protected virtual Query NewMatchAllDocsQuery()
Returns
Type | Description |
---|---|
Query | new Lucene.Net.Search.MatchAllDocsQuery instance |
NewPrefixQuery(Term)
Builds a new Lucene.Net.Search.PrefixQuery instance
Declaration
protected virtual Query NewPrefixQuery(Term prefix)
Parameters
Type | Name | Description |
---|---|---|
Term | prefix | Prefix term |
Returns
Type | Description |
---|---|
Query | new Lucene.Net.Search.PrefixQuery instance |
NewRangeQuery(string, string, string, bool, bool)
Builds a new Lucene.Net.Search.TermRangeQuery instance
Declaration
protected virtual Query NewRangeQuery(string field, string part1, string part2, bool startInclusive, bool endInclusive)
Parameters
Type | Name | Description |
---|---|---|
string | field | Field |
string | part1 | min |
string | part2 | max |
bool | startInclusive | true if the start of the range is inclusive |
bool | endInclusive | true if the end of the range is inclusive |
Returns
Type | Description |
---|---|
Query | new Lucene.Net.Search.TermRangeQuery instance |
NewRegexpQuery(Term)
Builds a new Lucene.Net.Search.RegexpQuery instance
Declaration
protected virtual Query NewRegexpQuery(Term regexp)
Parameters
Type | Name | Description |
---|---|---|
Term | regexp | Regexp term |
Returns
Type | Description |
---|---|
Query | new Lucene.Net.Search.RegexpQuery instance |
NewWildcardQuery(Term)
Builds a new Lucene.Net.Search.WildcardQuery instance
Declaration
protected virtual Query NewWildcardQuery(Term t)
Parameters
Type | Name | Description |
---|---|---|
Term | t | wildcard term |
Returns
Type | Description |
---|---|
Query | new Lucene.Net.Search.WildcardQuery instance |
Parse(string)
Parses a query string, returning a Lucene.Net.Search.Query.
Declaration
public virtual Query Parse(string query)
Parameters
Type | Name | Description |
---|---|---|
string | query | the query string to be parsed. |
Returns
Type | Description |
---|---|
Query |
Exceptions
Type | Condition |
---|---|
ParseException | if the parsing fails |
ReInit(ICharStream)
This class is overridden by QueryParser.
Declaration
public abstract void ReInit(ICharStream stream)
Parameters
Type | Name | Description |
---|---|---|
ICharStream | stream |
SetDateResolution(DateResolution)
Gets or 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, DateResolution).
Declaration
public virtual void SetDateResolution(DateResolution dateResolution)
Parameters
Type | Name | Description |
---|---|---|
DateResolution | dateResolution |
SetDateResolution(string, DateResolution)
Sets the date resolution used by RangeQueries for a specific field.
Declaration
public virtual void SetDateResolution(string fieldName, DateResolution dateResolution)
Parameters
Type | Name | Description |
---|---|---|
string | fieldName | field for which the date resolution is to be set |
DateResolution | dateResolution | date resolution to set |
TopLevelQuery(string)
This class is overridden by QueryParser.
Declaration
public abstract Query TopLevelQuery(string field)
Parameters
Type | Name | Description |
---|---|---|
string | field |
Returns
Type | Description |
---|---|
Query |