Hi Mohsin,
Can you elaborate? Contains() method is the substring search. Which is already in your code example.
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.
Try using Match() - there is an overload for string that should work like Contains()
Ah I see, apologies I missed that the first time.
You could try this:
If you decide to give that a go and it doesn't work. let me know and I can try it myself for you.
Ignore my last comment, Quan's overload on Match does the same thing but better.
But I am not able to find that overload, do you have an example for that please?
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));
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?
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
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.
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
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.
I have this line of code
I want to check if there is anything like a string contains a substring in FIND query.
Thanks for help in advance. :)