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)
//在不同的Field上进行不同的查找
public static Query parse(String[] queries, String[] fields, Analyzer analyzer) { }
//在不同的Field上进行同一个的查找,指定它们之间的布尔关系
public static Query parse(String query, String[] fields, BooleanClause.Occur[] flags, Analyzer analyzer) { }
//在不同的Field上进行不同的查找,指定它们之间的布尔关系
public static Query parse(String[] queries, String[] fields, BooleanClause.Occur[] flags,Analyzer analyzer) { }
/*参数说明
query: 所要查询的关键字
*field:field name
*/
//如果要在不同的Field上进行不同的查找(1和3),则queries 和 fields 两个数组的长度要相同
//比如说搜索一本Java的书,如果要在Title和Author两个field搜的话,就是
MultiFieldQueryParser.Parse("Java",new string[]{"Title","Author"},BooleanClause.Occur[],new StandardAnalyzer());