Try our conversational search powered by Generative AI!

filters within the same category to be combined with OR logic, while filters across different categories should be AND logic

Vote:
 

i have 3 list of categories to filter ->

string[] category1

[ "value1",

"value2",

............]

,string[] category2

[ "value1",

"value2",

............]

,string[] category3

[ "value1",

"value2",

............]

Eg:

var query = this._searchService.Search<x>();

FilterBuilder<x> filter = this._searchService.BuildFilter<x>();

foreach (var item in category1)
{         
            filter = filter.And(x => x.modelValues.category1.Match(item));       
}

foreach (var item in category2)
{         
            filter = filter.And(x => x.modelValues.category2.Match(item));       
}

foreach (var item in category3)
{         
            filter = filter.And(x => x.modelValues.category3.Match(item));       
}

search = query.Filter(filter);

I want the filters within the same category to be combined with OR logic, allowing any match within a category, while filters across different categories should be combined with AND logic, requiring matches across all specified categories. The existing code should already handle the AND logic for  different categories and also for within the category.

#315507
Edited, Jan 12, 2024 4:02
Vote:
 

Got solution

//Created object for all category filtering

var category1Filter = this._searchService.BuildFilter<x>();

var category2Filter = this._searchService.BuildFilter<x>();

var category3Filter = this._searchService.BuildFilter<x>();

//Replace AND with OR logic for all categories

foreach (var item in category1)
{         
            category1Filter = category1Filter.Or(x => x.modelValues.category1.Match(item));       
}

foreach (var item in category2)
{         
            category2Filter = category2Filter.Or(x => x.modelValues.category2.Match(item));       
}

foreach (var item in category3)
{         
            category3Filter = category3Filter.Or(x => x.modelValues.category3.Match(item));       
}

search = query.Filter(category1Filter)

.Filter(category2Filter)

.Filter(category3Filter);

#315515
Jan 12, 2024 11:05
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.