Try our conversational search powered by Generative AI!
AI OnAI Off
Hi,
I think you can use AND operator in filtering by calling filters multiple times.
Example:
var searchQuery = client.Search<PageData>() .Filter(x => x.City.Match("Chicago")) .Filter(x => x.EmployeeType.Match("Exempt"));
You can read more about Episerver Find filtering here:
https://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-Find/8/DotNET-Client-API/Searching/Filtering/Filtering/
I know how to do the and/or searches, but every page will have different settings. So I would really need something like this
var searchQuery = client.Search<PageData>()
.Filter(x => x.MatchType.Match("All") & x.Groups.MatchAll(listOfUserGroups))
.Filter(x => x.MatchType.Match("Any") & x.Groups.MatchAny(listOfUserGroups))
But not sure how to write those MatchAll and MatchAny functions.
I would recommend a method newmethod that returns FilterBuilder<PageData> . Then in your search call .filter(newmethod())
Here's a sample:
private FilterBuilder<PageData> BuildTagsFilter(List<string> stringsToMatch, bool AnyOpertor) { var client = Client.CreateFromConfig(); var tagFilter = client.BuildFilter<PageData>(); // if OR operator - Any tagFilter = tagFilter.And(x => x.City.Match("Chicago") | x.City.Match("New York") | x.City.Match("Los Angeles")) // if AND operator - All return tagFilter.And(x = > x.City.Match("Chicago") & x.EmployeeType.Match("Exempt") } //In your search call: searchClient.Search<PageData>.Filter(FilterBuilder(stringsToMatch, AnyOperator))
We have a page that has two properties on them
1. Groups - Multi Select List of Attributes that the user needs to see the page in a rollup
2. Match Type - Single select (All/Any) to match either all or any of the attributes from the Groups field
So take for an example a page that has the following properties set
City - Chicago
City - New York
City - Los Angeles
Match Type - Any
If I select 'Any' then I match that the users city can be any of the following 3 above.
Howerver, if I have
City - Chicago
Employee Type - Exempt
Match Type - All
then I match that the users city has to be Chicago and the Employee Type has to be Exempt.
I had this working with the GetChilldren method but now an trying to rewrite the solution using EPi Find for performance and paging, but I can't get the filter to work. Can someone please assist.
I want to write something like
searchClient.Search()
.FilterForMatchingGroups()
Thanks,
Mike