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
| Improve this Doc View SourceMultiFieldQueryParser(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 fields
title
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 | |
System.String[] | fields | |
Analyzer | analyzer |
MultiFieldQueryParser(LuceneVersion, String[], Analyzer, IDictionary<String, Single>)
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 fields
title
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 | |
System.String[] | fields | |
Analyzer | analyzer | |
IDictionary<System.String, System.Single> | boosts |
Fields
| Improve this Doc View Sourcem_boosts
Declaration
protected IDictionary<string, float> m_boosts
Field Value
Type | Description |
---|---|
IDictionary<System.String, System.Single> |
m_fields
Declaration
protected string[] m_fields
Field Value
Type | Description |
---|---|
System.String[] |
Methods
| Improve this Doc View SourceGetFieldQuery(String, String, Boolean)
Declaration
protected override Query GetFieldQuery(string field, string queryText, bool quoted)
Parameters
Type | Name | Description |
---|---|---|
System.String | field | |
System.String | queryText | |
System.Boolean | quoted |
Returns
Type | Description |
---|---|
Query |
Overrides
| Improve this Doc View SourceGetFieldQuery(String, String, Int32)
Declaration
protected override Query GetFieldQuery(string field, string queryText, int slop)
Parameters
Type | Name | Description |
---|---|---|
System.String | field | |
System.String | queryText | |
System.Int32 | slop |
Returns
Type | Description |
---|---|
Query |
Overrides
| Improve this Doc View SourceGetFuzzyQuery(String, String, Single)
Declaration
protected override Query GetFuzzyQuery(string field, string termStr, float minSimilarity)
Parameters
Type | Name | Description |
---|---|---|
System.String | field | |
System.String | termStr | |
System.Single | minSimilarity |
Returns
Type | Description |
---|---|
Query |
Overrides
| Improve this Doc View SourceGetPrefixQuery(String, String)
Declaration
protected override Query GetPrefixQuery(string field, string termStr)
Parameters
Type | Name | Description |
---|---|---|
System.String | field | |
System.String | termStr |
Returns
Type | Description |
---|---|
Query |
Overrides
| Improve this Doc View SourceGetRangeQuery(String, String, String, Boolean, Boolean)
Declaration
protected override Query GetRangeQuery(string field, string part1, string part2, bool startInclusive, bool endInclusive)
Parameters
Type | Name | Description |
---|---|---|
System.String | field | |
System.String | part1 | |
System.String | part2 | |
System.Boolean | startInclusive | |
System.Boolean | endInclusive |
Returns
Type | Description |
---|---|
Query |
Overrides
| Improve this Doc View SourceGetRegexpQuery(String, String)
Declaration
protected override Query GetRegexpQuery(string field, string termStr)
Parameters
Type | Name | Description |
---|---|---|
System.String | field | |
System.String | termStr |
Returns
Type | Description |
---|---|
Query |
Overrides
| Improve this Doc View SourceGetWildcardQuery(String, String)
Declaration
protected override Query GetWildcardQuery(string field, string termStr)
Parameters
Type | Name | Description |
---|---|---|
System.String | field | |
System.String | termStr |
Returns
Type | Description |
---|---|
Query |
Overrides
| Improve this Doc View SourceParse(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. |
System.String | query | Query string to parse |
System.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 |
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. |
System.String[] | queries | Queries strings to parse |
System.String[] | fields | Fields to search on |
Analyzer | analyzer | Analyzer to use |
Returns
Type | Description |
---|---|
Query |
Exceptions
Type | Condition |
---|---|
ParseException | if query parsing fails |
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. |
System.String[] | queries | Queries string to parse |
System.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 |