1

I want to check if indexed string (my case string is "1,2,3") contains some value (like an actual string.Contains method), but it seems like EpiFind doesn't supply method for that.

I applied value.AnyWordBeginsWith(match) and it seems to work in my case but it's a hacky solution and might fail

searchQuery.Filter(x => x.StringToCheck.AnyWordBeginsWith("2"));

Is there a proper way to check if string contains my value?

Like this:

searchQuery.Filter(x => x.StringToCheck.Contains("2"));

Please note that this question is not related to ordinary string comparison in C# or LINQ before flagging the question.

Ted Nyberg
  • 7,001
  • 7
  • 41
  • 72
Ivan Maslov
  • 168
  • 2
  • 13
  • 1
    Hi @Ivan , I think this [link](https://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-Find/11/DotNET-Client-API/Searching/Filtering/Strings/) and [this one](https://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-Find/8/DotNET-Client-API/Searching/Searching/) will solve your problem, if you need help please contact me – João Paulo Amorim Feb 13 '19 at 16:15
  • Do you use the unified search or the typed search? – Eric Herlitz Feb 13 '19 at 22:26
  • @EricHerlitz I use ITypeSearch – Ivan Maslov Feb 14 '19 at 07:00

1 Answers1

3

You should probably opt to index that value as a string array instead. It will simplify searching/filtering.

To do that, simply add a helper property like...

// Helper property used for indexing
public string[] ArrayOfStringToCheck => return StringToCheck?.Split(',');

...and then reindex your content. After that you can filter like:

searchQuery.Filter(x => x.ArrayOfStringToCheck.Match("stringToFind"));

Ted Nyberg
  • 7,001
  • 7
  • 41
  • 72
  • That hack will probably work but not better than AnyWordBeginsWith and still will hit something like 12 when searching for 2 – Ivan Maslov Feb 14 '19 at 08:16
  • AnyWordBeginsWith sounds risky as it could match values _beginning_ with "2", not equal to "2"? – Ted Nyberg Feb 14 '19 at 08:28
  • Yes, that's why I'm not going to use it – Ivan Maslov Feb 14 '19 at 08:30
  • Right, my point was just that the hack is better since it doesn't risk such incorrect matches. :) – Ted Nyberg Feb 14 '19 at 08:32
  • I'm trying to do `searchQuery.Filter(x => "2".In(x.SplittedString))` but debugger throws InvalidOperationException saying that x is out of scope (here - `x.SplittedString`). What could it be? – Ivan Maslov Feb 14 '19 at 08:33
  • Ah, x should be on the left side of DelegateFilterBuilder expression – Ivan Maslov Feb 14 '19 at 08:38
  • So it goes like this: you add new prop to your content: `IEnumerable SplittedString => StringToCheck.Split(',');`. Reindex it. Then filter will be `searchQuery.Filter(x => x.SplittedString.Match(valueToFind));`. It searches in array instead of string. If you add this to your answer I will mark it as accepted. Thanks – Ivan Maslov Feb 14 '19 at 08:44
  • @IvanMaslov Done. Thanks! – Ted Nyberg Feb 14 '19 at 14:50
  • Wait, why `.In(...`? It's for when you have string on the left and array on the right. If it's opposite, then you use `.Match(...` At least it works for me like this in Epifind 13.0.1 – Ivan Maslov Feb 15 '19 at 07:01
  • @IvanMaslov Doh, you're right, some copy-and-paste error there I think. :) Changed it to `Match`. – Ted Nyberg Feb 15 '19 at 12:46