Do we have anything like contains in Unified search?


I have this line of code

query = query.Filter(i => (!i.MatchTypeHierarchy(typeof(InfoPage)) | (((InfoPage)i).SearchSubsection().Exists() &
                        ((InfoPage)i).GetSearchSubSection().Contains(SOMETHING)))); // I want to check if it contains

I want to check if there is anything like a string contains a substring in FIND query. 

Thanks for help in advance. :)

Oct 06, 2022 8:07

Hi Mohsin,

Can you elaborate? Contains() method is the substring search. Which is already in your code example.

Oct 06, 2022 8:37

Hello Surjit,

Yes, I want the substring search, but contains doesn't work here as it is from LINQ. I am looking for an alternative of Contains() method in FIND search query. 

Oct 06, 2022 8:39

Try using Match() - there is an overload for string that should work like Contains()

Oct 06, 2022 8:58

I do not see it, can you please give an example @Quan Mai

Oct 06, 2022 9:03

Ah I see, apologies I missed that the first time.

You could try this:

  • Add a new index property to your InfoPage and set it to GetSearchSubSection split into an array string
  • Reindex
  • Filter again but do a Match against your new property. I forget if you need to do MatchContained because its a collection now or if Match will do it for now.

If you decide to give that a go and it doesn't work. let me know and I can try it myself for you.

Oct 06, 2022 9:23

Ignore my last comment, Quan's overload on Match does the same thing but better.

Oct 06, 2022 9:24

But I am not able to find that overload, do you have an example for that please?

Oct 06, 2022 9:25

It should be in EPiServer.Find namespace. You might want to use MatchCaseInsensitive which is more relaxed. 


                .And(x => x.MatchTypeHierarchy(typeof(ILocalizable)) & !x.MatchTypeHierarchy(typeof(IVersionable)))
                .And(x => x.Language.Name.MatchCaseInsensitive(language));

Oct 06, 2022 9:33

So you mean this would work

query = query.Filter(i => (!i.MatchTypeHierarchy(typeof(InfoPage)) | (((InfoPage)i).SearchSubsection().Exists() &

lets say my input is testInput = "I want to find this";


Will this match?

Edited, Oct 06, 2022 9:37

I'm not a FInd expert, but I think you can build your filter like this 

filter = client.BuildFilter<InfoPage>()
                .And(x => x.MatchTypeHierarchy(typeof(InfoPage))))
                .And(x => x.SearchSubsection().MatchCaseInsensitive(blah));

then use that filter in your query. you probably can rewrite the query to include above filter as well 

Oct 06, 2022 10:01

I do not thing this will work as you can read here MatchCaseInsensitive still does an exact match without considering casing. 

I am looking for a solution which is like contains in LINQ. To find if a string contains a substring. 

Oct 06, 2022 10:10

I see. in theory you can index your SearchSubsection as a array of string, then use MatchContained. However I'm not sure if that's a good idea or not 

Oct 06, 2022 10:40

lets say my input is testInput = "I want to find this";


For that specific example at least, wouldn't AnyWordBeginsWith work for you? (But, if you're looking for true substrings -- trying to match a search for "ban" in the content "abandon", to use the example from that doc -- then that won't do it for you.)

There are a few more options via EPiServer.Labs.Find.Toolbox, though I don't think they're exactly what you're looking for either.

Oct 11, 2022 21:30
* 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.