Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Can I filter by "EndsWith" on PageName?

Vote:
 

I'm using:

SearchClient.Instance.UnifiedSearch().For(searchQ)

as the basis for my search, afterwhich I've a bunch of filters I've already implented, but now I need to filter pages OUT that have a PageName that ends with "_Compare"...

I tried using "MatchContainedCaseInsensitive" like soo...

.Filter(x => !((PageData) x).PageName.MatchContainedCaseInsensitive(c => c.ToString(),"_Compare"));

but "c.ToString()" is wrong I think and I dont know what is the correct thing to put in there as "fieldSelector" as I've already selected "pagename".

Any help would be great please.

#207481
Sep 20, 2019 19:10
mekala v - Sep 25, 2019 11:26
Hi Noel Sefton,

Try this after getting the result.

var result = SearchClient.Instance.UnifiedSearch().For(searchq).GetResult();

var endsWithResult = result .Where(x => !x.NameSearchable.EndsWith("_Compare"));
Noel Sefton - Sep 25, 2019 12:36
that would filter on our webserver instead of find's webserver, which isn't playing to find's strengths.

What I ended up doing was adding a property on the model that does the computation, then "includefield" adds that property to the index, which I can then compare directly...

.Filter(x => !((myCustomContentPage)x).ExcludeFromSearch.Match(true)); // where "ExcludeFromSearch" is my custom property that returns a bool.
* 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.