`

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());

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics