How to check if list of string contains (substring) value in EpiFind?

739 views Asked by At

I have indexed an object which has a list of strings like ["ZZA-KL-2A", "ZZA-KL-ZZB"]. I want to search and get all items which starts with a certain 3 letter code. So I want to check each item in the list and check something like 'StartsWith'.

I can see from documentation that we have something like Match, MatchContained but nothing for start with for the list of string items.

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

2

There are 2 answers

0
Jon Jones On

Just use a filter

var searchQuery = client.Search<MyContent>()
  .Filter(x => x.OrderNumber.StartsWith("Find"));

https://world.episerver.com/documentation/developer-guides/search-navigation/NET-Client-API/searching/Filtering/

0
Dariusz Woźniak On

You may use Prefix or PrefixCaseInsensitive:

Matching by beginning of a string (startsWith)

The Prefix method lets you match by the beginning of a string. The following search matches blog posts titled Find and Find rocks! but not find, Finding or Hello Find.

var searchQuery = client.Search<BlogPost>().Filter(x =>
x.Title.Prefix("Find"));

Use the PrefixCaseInsensitive method to match by the beginning of a string in a case-insensitive way. The following search matches blog posts titled Find, Find rocks! and Find but not Finding or Hello Find.

var searchQuery = client.Search<BlogPost>().Filter(x =>
x.Title.PrefixCaseInsensitive("Find"));

Source: https://docs.developers.optimizely.com/digital-experience-platform/v1.1.0-search-and-navigation/docs/strings#matching-by-beginning-of-a-string-startswith