Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

Do we have anything like contains in Unified search?

Vote:
0

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:
0

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:
0

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:
0

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

#288733
Oct 06, 2022 8:58
Vote:
0

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

#288734
Oct 06, 2022 9:03
Vote:
0

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:
0

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

#288738
Oct 06, 2022 9:24
Vote:
0

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

#288739
Oct 06, 2022 9:25
Vote:
0

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:
0

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:
0

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:
0

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:
0

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:
0

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.