Class QueryParserUtil
- java.lang.Object
-
- org.apache.lucene.queryparser.flexible.standard.QueryParserUtil
-
public final class QueryParserUtil extends java.lang.Object
This class defines utility methods to (help) parse query strings intoQuery
objects.
-
-
Constructor Summary
Constructors Constructor Description QueryParserUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
escape(java.lang.String s)
Returns a String where those characters that TextParser expects to be escaped are escaped by a preceding\
.static Query
parse(java.lang.String[] queries, java.lang.String[] fields, Analyzer analyzer)
Parses a query which searches on the fields specified.static Query
parse(java.lang.String[] queries, java.lang.String[] fields, BooleanClause.Occur[] flags, Analyzer analyzer)
Parses a query, searching on the fields specified.static Query
parse(java.lang.String query, java.lang.String[] fields, BooleanClause.Occur[] flags, Analyzer analyzer)
Parses a query, searching on the fields specified.
-
-
-
Method Detail
-
parse
public static Query parse(java.lang.String[] queries, java.lang.String[] fields, Analyzer analyzer) throws QueryNodeException
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)
- Parameters:
queries
- Queries strings to parsefields
- Fields to search onanalyzer
- Analyzer to use- Throws:
java.lang.IllegalArgumentException
- if the length of the queries array differs from the length of the fields arrayQueryNodeException
-
parse
public static Query parse(java.lang.String query, java.lang.String[] fields, BooleanClause.Occur[] flags, Analyzer analyzer) throws QueryNodeException
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"}; BooleanClause.Occur[] flags = {BooleanClause.Occur.SHOULD, BooleanClause.Occur.MUST, BooleanClause.Occur.MUST_NOT}; MultiFieldQueryParser.parse("query", fields, flags, analyzer);
The code above would construct a query:
(filename:query) +(contents:query) -(description:query)
- Parameters:
query
- Query string to parsefields
- Fields to search onflags
- Flags describing the fieldsanalyzer
- Analyzer to use- Throws:
java.lang.IllegalArgumentException
- if the length of the fields array differs from the length of the flags arrayQueryNodeException
-
parse
public static Query parse(java.lang.String[] queries, java.lang.String[] fields, BooleanClause.Occur[] flags, Analyzer analyzer) throws QueryNodeException
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"}; BooleanClause.Occur[] flags = {BooleanClause.Occur.SHOULD, BooleanClause.Occur.MUST, BooleanClause.Occur.MUST_NOT}; MultiFieldQueryParser.parse(query, fields, flags, analyzer);
The code above would construct a query:
(filename:query1) +(contents:query2) -(description:query3)
- Parameters:
queries
- Queries string to parsefields
- Fields to search onflags
- Flags describing the fieldsanalyzer
- Analyzer to use- Throws:
java.lang.IllegalArgumentException
- if the length of the queries, fields, and flags array differQueryNodeException
-
escape
public static java.lang.String escape(java.lang.String s)
Returns a String where those characters that TextParser expects to be escaped are escaped by a preceding\
.
-
-