lucene多条件查询

来源:转载


1.使用 MultiFieldQueryParser:
BooleanClause.Occur[] clauses = {
                    BooleanClause.Occur.SHOULD,
                    BooleanClause.Occur.SHOULD
                };
        Query query = MultiFieldQueryParser.parse(Version.LUCENE_30, queries, fields, clauses, new StandardAnalyzer(Version.LUCENE_30));

2.使用 BooleanQuery 动态 add query 对象:
BooleanQuery booleanQuery = new BooleanQuery();
   
        QueryParser parser1 = new QueryParser(Version.LUCENE_30, "chapter_name", new StandardAnalyzer(Version.LUCENE_30));
        Query titleQuery = parser1.parse("家");
        booleanQuery.add(titleQuery, BooleanClause.Occur.SHOULD);
   
        QueryParser parser2 = new QueryParser(Version.LUCENE_30, "content", new StandardAnalyzer(Version.LUCENE_30));
        Query contentQuery = parser2.parse("家");
        booleanQuery.add(contentQuery, BooleanClause.Occur.SHOULD);



分享给朋友:
您可能感兴趣的文章:
随机阅读: