摘自lucene官网
public static Query parse(String[] queries, String[] fields, BooleanClause.Occur[] flags, Analyzer analyzer) throws ParseException
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 parse -
fields
- Fields to search on -
flags
- Flags describing the fields -
analyzer
- Analyzer to use
Throws:
-
ParseException
- if query parsing fails -
IllegalArgumentException
- if the length of the queries, fields, and flags array differ - /**
- * BooleanClause.Occur.MUST表示and
- * BooleanClause.Occur.MUST_NOT表示not
- * BooleanClause.Occur.SHOULD表示or
- */