Class MultiFieldQueryParser
A QueryParser which constructs queries to search multiple fields.
Implements
Inherited Members
Namespace: Lucene.Net.QueryParsers.Classic
Assembly: Lucene.Net.QueryParser.dll
Syntax
public class MultiFieldQueryParser : QueryParser, ICommonQueryParserConfiguration
Constructors
MultiFieldQueryParser(LuceneVersion, string[], Analyzer)
Creates a MultiFieldQueryParser.
It will, when Parse(string) is called, construct a query like this (assuming the query consists of two terms and you specify the two fieldstitle
and body
):
(title:term1 body:term1) (title:term2 body:term2)
When DefaultOperator is set to AND_OPERATOR, the result will be:
+(title:term1 body:term1) +(title:term2 body:term2)
In other words, all the query's terms must appear, but it doesn't matter
in what fields they appear.
Declaration
public MultiFieldQueryParser(LuceneVersion matchVersion, string[] fields, Analyzer analyzer)
Parameters
Type | Name | Description |
---|---|---|
LuceneVersion | matchVersion | |
string[] | fields | |
Analyzer | analyzer |
MultiFieldQueryParser(LuceneVersion, string[], Analyzer, IDictionary<string, float>)
Creates a MultiFieldQueryParser. Allows passing of a map with term to Boost, and the boost to apply to each term.
It will, when Parse(string) is called, construct a query like this (assuming the query consists of two terms and you specify the two fieldstitle
and body
):
(title:term1 body:term1) (title:term2 body:term2)
When DefaultOperator is set to AND_OPERATOR, the result will be:
+(title:term1 body:term1) +(title:term2 body:term2)
When you pass a boost (title=>5 body=>10) you can get
+(title:term1^5.0 body:term1^10.0) +(title:term2^5.0 body:term2^10.0)
In other words, all the query's terms must appear, but it doesn't matter
in what fields they appear.
Declaration
public MultiFieldQueryParser(LuceneVersion matchVersion, string[] fields, Analyzer analyzer, IDictionary<string, float> boosts)
Parameters
Type | Name | Description |
---|---|---|
LuceneVersion | matchVersion | |
string[] | fields | |
Analyzer | analyzer | |
IDictionary<string, float> | boosts |
Fields
m_boosts
A QueryParser which constructs queries to search multiple fields.
Declaration
protected IDictionary<string, float> m_boosts
Field Value
Type | Description |
---|---|
IDictionary<string, float> |
m_fields
A QueryParser which constructs queries to search multiple fields.
Declaration
protected string[] m_fields
Field Value
Type | Description |
---|---|
string[] |
Methods
GetFieldQuery(string, string, bool)
A QueryParser which constructs queries to search multiple fields.
Declaration
protected override Query GetFieldQuery(string field, string queryText, bool quoted)
Parameters
Type | Name | Description |
---|---|---|
string | field | |
string | queryText | |
bool | quoted |
Returns
Type | Description |
---|---|
Query |
Overrides
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 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 |
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 override 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 |
Overrides
Exceptions
Type | Condition |
---|---|
ParseException | throw in overridden method to disallow |
GetRangeQuery(string, string, string, bool, bool)
A QueryParser which constructs queries to search multiple fields.
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
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 override 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 |
Overrides
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 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 |
Parse(LuceneVersion, string, string[], Occur[], Analyzer)
Parses a query, searching on the fields specified. Use this if you need to specify certain fields as required, and others as prohibited.
Usage:string[] fields = {"filename", "contents", "description"};
Occur[] flags = {Occur.SHOULD,
Occur.MUST,
Occur.MUST_NOT};
MultiFieldQueryParser.Parse("query", fields, flags, analyzer);
The code above would construct a query:
(filename:query) +(contents:query) -(description:query)
Declaration
public static Query Parse(LuceneVersion matchVersion, string query, string[] fields, Occur[] flags, Analyzer analyzer)
Parameters
Type | Name | Description |
---|---|---|
LuceneVersion | matchVersion | Lucene version to match; this is passed through to QueryParser. |
string | query | Query string to parse |
string[] | fields | Fields to search on |
Occur[] | flags | Flags describing the fields |
Analyzer | analyzer | Analyzer to use |
Returns
Type | Description |
---|---|
Query |
Exceptions
Type | Condition |
---|---|
ParseException | if query parsing fails |
ArgumentException | if the length of the fields array differs from the length of the flags array |
Parse(LuceneVersion, string[], string[], Analyzer)
Parses a query which searches on the fields specified.
If x fields are specified, this effectively constructs:(field1:query1) (field2:query2) (field3:query3)...(fieldx:queryx)
Declaration
public static Query Parse(LuceneVersion matchVersion, string[] queries, string[] fields, Analyzer analyzer)
Parameters
Type | Name | Description |
---|---|---|
LuceneVersion | matchVersion | Lucene version to match; this is passed through to QueryParser. |
string[] | queries | Queries strings to parse |
string[] | fields | Fields to search on |
Analyzer | analyzer | Analyzer to use |
Returns
Type | Description |
---|---|
Query |
Exceptions
Type | Condition |
---|---|
ParseException | if query parsing fails |
ArgumentException | if the length of the queries array differs from the length of the fields array |
Parse(LuceneVersion, string[], string[], Occur[], Analyzer)
Parses a query, searching on the fields specified. Use this if you need to specify certain fields as required, and others as prohibited.
Usage:string[] query = {"query1", "query2", "query3"};
string[] fields = {"filename", "contents", "description"};
Occur[] flags = {Occur.SHOULD,
Occur.MUST,
Occur.MUST_NOT};
MultiFieldQueryParser.Parse(query, fields, flags, analyzer);
The code above would construct a query:
(filename:query1) +(contents:query2) -(description:query3)
Declaration
public static Query Parse(LuceneVersion matchVersion, string[] queries, string[] fields, Occur[] flags, Analyzer analyzer)
Parameters
Type | Name | Description |
---|---|---|
LuceneVersion | matchVersion | Lucene version to match; this is passed through to QueryParser. |
string[] | queries | Queries string to parse |
string[] | fields | Fields to search on |
Occur[] | flags | Flags describing the fields |
Analyzer | analyzer | Analyzer to use |
Returns
Type | Description |
---|---|
Query |
Exceptions
Type | Condition |
---|---|
ParseException | if query parsing fails |
ArgumentException | if the length of the queries, fields, and flags array differ |