Class ComplexPhraseQueryParser
QueryParser which permits complex phrase query syntax eg "(john jon jonathan~) peters*".
Performs potentially multiple passes over Query text to parse any nested logic in PhraseQueries. - First pass takes any PhraseQuery content between quotes and stores for subsequent pass. All other query content is parsed as normal - Second pass parses any stored PhraseQuery content, checking all embedded clauses are referring to the same field and therefore can be rewritten as Span queries. All PhraseQuery clauses are expressed as ComplexPhraseQuery objects
This could arguably be done in one pass using a new QueryParser but here I am working within the constraints of the existing parser as a base class. This currently simply feeds all phrase content through an analyzer to select phrase terms - any "special" syntax such as * ~ * etc are not given special status
Implements
Inherited Members
Namespace: Lucene.Net.QueryParsers.ComplexPhrase
Assembly: Lucene.Net.QueryParser.dll
Syntax
public class ComplexPhraseQueryParser : QueryParser, ICommonQueryParserConfiguration
Constructors
ComplexPhraseQueryParser(LuceneVersion, string, Analyzer)
QueryParser which permits complex phrase query syntax eg "(john jon jonathan~) peters*".
Performs potentially multiple passes over Query text to parse any nested logic in PhraseQueries. - First pass takes any PhraseQuery content between quotes and stores for subsequent pass. All other query content is parsed as normal - Second pass parses any stored PhraseQuery content, checking all embedded clauses are referring to the same field and therefore can be rewritten as Span queries. All PhraseQuery clauses are expressed as ComplexPhraseQuery objects
This could arguably be done in one pass using a new QueryParser but here I am working within the constraints of the existing parser as a base class. This currently simply feeds all phrase content through an analyzer to select phrase terms - any "special" syntax such as * ~ * etc are not given special status
Declaration
public ComplexPhraseQueryParser(LuceneVersion matchVersion, string f, Analyzer a)
Parameters
Type | Name | Description |
---|---|---|
LuceneVersion | matchVersion | |
string | f | |
Analyzer | a |
Properties
InOrder
When InOrder is true, the search terms must exists in the documents as the same order as in query. Choose between ordered (true) or un-ordered (false) proximity search.
Declaration
public virtual bool InOrder { get; }
Property Value
Type | Description |
---|---|
bool |
Methods
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 override Query GetFieldQuery(string field, string queryText, int slop)
Parameters
Type | Name | Description |
---|---|---|
string | field | |
string | queryText | |
int | slop |
Returns
Type | Description |
---|---|
Query |
Overrides
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 override 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 |
Overrides
Exceptions
Type | Condition |
---|---|
ParseException | throw in overridden method to disallow |
GetRangeQuery(string, string, string, bool, bool)
QueryParser which permits complex phrase query syntax eg "(john jon jonathan~) peters*".
Performs potentially multiple passes over Query text to parse any nested logic in PhraseQueries. - First pass takes any PhraseQuery content between quotes and stores for subsequent pass. All other query content is parsed as normal - Second pass parses any stored PhraseQuery content, checking all embedded clauses are referring to the same field and therefore can be rewritten as Span queries. All PhraseQuery clauses are expressed as ComplexPhraseQuery objects
This could arguably be done in one pass using a new QueryParser but here I am working within the constraints of the existing parser as a base class. This currently simply feeds all phrase content through an analyzer to select phrase terms - any "special" syntax such as * ~ * etc are not given special status
Declaration
protected override 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 |
Overrides
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 override 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 |
Overrides
Exceptions
Type | Condition |
---|---|
ParseException | throw in overridden method to disallow |
NewRangeQuery(string, string, string, bool, bool)
Builds a new Lucene.Net.Search.TermRangeQuery instance
Declaration
protected override 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 |
Overrides
NewTermQuery(Term)
Builds a new Lucene.Net.Search.TermQuery instance.
This is intended for subclasses that wish to customize the generated queries.Declaration
protected override Query NewTermQuery(Term term)
Parameters
Type | Name | Description |
---|---|---|
Term | term | Term. |
Returns
Type | Description |
---|---|
Query | New Lucene.Net.Search.TermQuery instance. |
Overrides
Parse(string)
Parses a query string, returning a Lucene.Net.Search.Query.
Declaration
public override Query Parse(string query)
Parameters
Type | Name | Description |
---|---|---|
string | query | the query string to be parsed. |
Returns
Type | Description |
---|---|
Query |
Overrides
Exceptions
Type | Condition |
---|---|
ParseException | if the parsing fails |