Lucene OR search using Boolean query

后端 未结 1 1347
滥情空心
滥情空心 2020-12-31 13:41

I have an index with multiple fields, one of which is a string field in which I store category names for a product... such as \"Electronics\", \"Home\", \"Garden\", etc

相关标签:
1条回答
  • 2020-12-31 14:05

    You can write like:

    BooleanQuery categoryQuery = new BooleanQuery();
    TermQuery catQuery1 = new TermQuery(new Term("category_name", "Electronics"));
    TermQuery catQuery2 = new TermQuery(new Term("category_name", "Home"));
    categoryQuery.add(new BooleanClause(catQuery1, BooleanClause.Occur.SHOULD));
    categoryQuery.add(new BooleanClause(catQuery2, BooleanClause.Occur.SHOULD));
    bq.add(new BooleanClause(categoryQuery, BooleanClause.Occur.MUST));
    
    0 讨论(0)
提交回复
热议问题