EPi Find Custom Filter

Vote:
 

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

#196156
Aug 20, 2018 18:31
Vote:
 
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/
#196161
Edited, Aug 21, 2018 6:18
Vote:
 

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.

#196189
Aug 21, 2018 16:23
Vote:
 

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))
#196191
Aug 21, 2018 16:31
* 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.