如何在Lucence
上使用OR布尔操作搜索多个类别ID我们在Lucene索引中将CategoryID作为字段,当我们使用单个值在CategoryID字段中搜索时,它工作正常但如果我们传递多个值,则搜索不会返回值
Example:
Category IDs = 10, 20, 30
Search Data:
Category ID = 10
Results:
It is working fine
Search Data:
Category ID = 10, 20
结果: 它无法正常工作
// search in categories
if (checkedCategories != null && checkedCategories.Count > 0)
{
foreach (int categoryID in checkedCategories)
{
Query queryEntity = new TermQuery(new Term("CategoryID", categoryID.ToString()));
booleanQuery.Add(queryEntity, Occur.MUST);
}
}
答案 0 :(得分:0)
我找到了答案,这是以下很棒的文章
http://searchhub.org/2011/12/28/why-not-and-or-and-not/
我为解决问题所做的是:
Search by Lucene_KsuDmsDesc = A
Search by Lucene_EmployeeNO = B
Search by Lucene_CreatedBy = C
Search by Lucene_CreatedDateTime = D
Search by Lucene_CategoryID = E
公式为(A和B和C和D)和(E1或E2或...... En),其中和=必须和或者应该