C# Class Lucene.Net.QueryParsers.Flexible.Spans.TestSpanQueryParser

This test case demonstrates how the new query parser can be used. It tests queries likes "term", "field:term" "term1 term2" "term1 OR term2", which are all already supported by the current syntax parser ( StandardSyntaxParser). The goals is to create a new query parser that supports only the pair "field:term" or a list of pairs separated or not by an OR operator, and from this query generate SpanQuery objects instead of the regular Search.Query objects. Basically, every pair will be converted to a SpanTermQuery object and if there are more than one pair they will be grouped by an OrQueryNode. Another functionality that will be added is the ability to convert every field defined in the query to an unique specific field. The query generation is divided in three different steps: parsing (syntax), processing (semantic) and building. The parsing phase, as already mentioned will be performed by the current query parser: StandardSyntaxParser. The processing phase will be performed by a processor pipeline which is compound by 2 processors: SpansValidatorQueryNodeProcessor and UniqueFieldQueryNodeProcessor. SpansValidatorQueryNodeProcessor: as it's going to use the current query parser to parse the syntax, it will support more features than we want, this processor basically validates the query node tree generated by the parser and just let got through the elements we want, all the other elements as wildcards, range queries, etc...if found, an exception is thrown. UniqueFieldQueryNodeProcessor: this processor will take care of reading what is the "unique field" from the configuration and convert every field defined in every pair to this "unique field". For that, a SpansQueryConfigHandler is used, which has the IUniqueFieldAttribute defined in it. The building phase is performed by the SpansQueryTreeBuilder, which basically contains a map that defines which builder will be used to generate SpanQuery objects from IQueryNode objects.
Show file Open project: apache/lucenenet

Public Methods

Method Description
GetSpanQuery ( String uniqueField, string query ) : Lucene.Net.Search.Spans.SpanQuery
GetSpanQuery ( string query ) : Lucene.Net.Search.Spans.SpanQuery
SetUp ( ) : void
TestSpanQueryParser ( ) : Lucene.Net.QueryParsers.Flexible.Core

Private Methods

Method Description
TestOrSpans ( ) : void
TestQueryValidator ( ) : void
TestTermSpans ( ) : void
TestUniqueField ( ) : void

Method Details

GetSpanQuery() public method

public GetSpanQuery ( String uniqueField, string query ) : Lucene.Net.Search.Spans.SpanQuery
uniqueField String
query string
return Lucene.Net.Search.Spans.SpanQuery

GetSpanQuery() public method

public GetSpanQuery ( string query ) : Lucene.Net.Search.Spans.SpanQuery
query string
return Lucene.Net.Search.Spans.SpanQuery

SetUp() public method

public SetUp ( ) : void
return void

TestSpanQueryParser() public method

public TestSpanQueryParser ( ) : Lucene.Net.QueryParsers.Flexible.Core
return Lucene.Net.QueryParsers.Flexible.Core