Class QueryParserUtil
This class defines utility methods to (help) parse query strings into Lucene.Net.Search.Query objects.
Inheritance
Inherited Members
Namespace: Lucene.Net.QueryParsers.Flexible.Standard
Assembly: Lucene.Net.QueryParser.dll
Syntax
public sealed class QueryParserUtil
Methods
| Improve this Doc View SourceEscape(String)
Returns a string where those characters that TextParser expects to be
escaped are escaped by a preceding
</code>.
Declaration
public static string Escape(string s)
Parameters
Type | Name | Description |
---|---|---|
System.String | s |
Returns
Type | Description |
---|---|
System.String |
Parse(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(string query, string[] fields, Occur[] flags, Analyzer analyzer)
Parameters
Type | Name | Description |
---|---|---|
System.String | query | Query string to parse |
System.String[] | fields | Fields to search on |
Lucene.Net.Search.Occur[] | flags | Flags describing the fields |
Lucene.Net.Analysis.Analyzer | analyzer | Analyzer to use |
Returns
Type | Description |
---|---|
Lucene.Net.Search.Query |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | if the length of the fields array differs from the length of the flags array |
Parse(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(string[] queries, string[] fields, Analyzer analyzer)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | queries | Queries strings to parse |
System.String[] | fields | Fields to search on |
Lucene.Net.Analysis.Analyzer | analyzer | Analyzer to use |
Returns
Type | Description |
---|---|
Lucene.Net.Search.Query |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | if the length of the queries array differs from the length of the fields array |
Parse(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(string[] queries, string[] fields, Occur[] flags, Analyzer analyzer)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | queries | Queries string to parse |
System.String[] | fields | Fields to search on |
Lucene.Net.Search.Occur[] | flags | Flags describing the fields |
Lucene.Net.Analysis.Analyzer | analyzer | Analyzer to use |
Returns
Type | Description |
---|---|
Lucene.Net.Search.Query |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | if the length of the queries, fields, and flags array differ |