Question

How to search by multi Category IDs with OR Boolean opeeation at Lucence

We have CategoryID as field at Lucene index, when we are using single value to search in CategoryID field, it is working fine but if we are passing multi values the search doesn't return a values

Example:
Category IDs = 10, 20, 30

Search Data:
Category ID = 10

Results:
It is working fine

Search Data:
Category ID = 10, 20

Results: It is not working

// 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);
  }
}
Was it helpful?

Solution

I found the answer, it is into the following great article

http://searchhub.org/2011/12/28/why-not-and-or-and-not/

What I did to solve my problem is:

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

The formula is (A and B and C and D) and (E1 or E2 or .... En), where and = MUST and or = SHOULD

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top