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

Try our conversational search powered by Generative AI!

Do we have anything like contains in Unified search?

Vote:
 

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. :)

#288729
Oct 06, 2022 8:07
Vote:
 

Hi Mohsin,

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

#288730
Oct 06, 2022 8:37
Vote:
 

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. 

#288732
Oct 06, 2022 8:39
Vote:
 

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

#288733
Oct 06, 2022 8:58
Vote:
 

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

#288734
Oct 06, 2022 9:03
Vote:
 

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.

#288737
Oct 06, 2022 9:23
Vote:
 

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

#288738
Oct 06, 2022 9:24
Vote:
 

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

#288739
Oct 06, 2022 9:25
Vote:
 

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

Example

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

#288740
Oct 06, 2022 9:33
Vote:
 

So you mean this would work

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

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

testInput.MatchCaseInsensitive("find"); 

Will this match?

#288742
Edited, Oct 06, 2022 9:37
Vote:
 

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 

#288743
Oct 06, 2022 10:01
Vote:
 

I do not thing this will work as you can read here https://docs.developers.optimizely.com/digital-experience-platform/v1.1.0-search-and-navigation/docs/strings#case-insensitive-match. 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. 

#288744
Oct 06, 2022 10:10
Vote:
 

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 

#288749
Oct 06, 2022 10:40
Vote:
 

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

testInput.MatchCaseInsensitive("find"); 

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.

#289030
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.