lucene 多字段查询

方法一:

BooleanQuery booleanQuery = new BooleanQuery();

QueryParser parser = new QueryParser("title",分词器);
Query titleQuery = parser .parser("中国人民共和国");
booleanQuery.add(titleQuery,....SHOULD);

QueryParser parser = new QueryParser("content",分词器);
Query contentQuery = parser .parser("中国人民共和国");
booleanQuery.add(contentQuery ,....SHOULD);

 

 

方法二:

String[] queries = { "中文版", "8*" };
   String[] fields = { "name", "isbn" };
   BooleanClause.Occur[] clauses = { BooleanClause.Occur.SHOULD, BooleanClause.Occur.SHOULD };
        Query query = MultiFieldQueryParser.parse(queries, fields, clauses, new StandardAnalyzer());

 

 

你可能感兴趣的:(Lucene)