0
votes

I cant seem to get the filter clause to retrieve documents from my index using a regex clause. The schema for my index is straight forward, I only have a single field which is both searchable and filterable and is of type Edm.String, called someId (which normally contains a hash value of something) and has sample values like:

someId

k6l7k2oj

k6l55iq8

k6l61ff8 ...

I need to be able to extract all values from this field that start with K6 and end with 8. So based on the documentation I am using this in my POST request body

{ "filter": "search.ismatch('/^k6[?]*d$/','someId','simple','all')",

"select":"someId",

"count":"true"

} and it comes up with nothing. On the other hand if I simplify and say I only need data where someId starts with K6, I seem to get some success if i just use a wild card. like this:

{ "filter": "search.ismatch('k6l*','someId','simple','all')",

"select":"someId",

"count":"true"

} I do get what I am looking for. Question is why does the regex not work with search.isMatch(), what am i missing?

...

3

3 Answers

1
votes

Regex is part of the full Lucene syntax; It is not available in the simple syntax. Try changing the third parameter of search.ismatch to 'full'.

Also, did you mean to use search.ismatch or search.ismatchscoring? The latter is functionally equivalent to using the top-level search, searchFields, queryType, and searchMode parameters. The former does not count matches towards relevance scoring.

1
votes

Your regex does not do what you intend either it seems. I tested your regex with your sample data and it does not match. Try this regex instead:

^k6.{5}8$

It matches a lowercase k6 from the start of the string, followed by 5 characters of anything and finally an 8.

Complete example

{ "filter": "search.ismatch('^k6.{5}8$','someId','full','all')", "select":"someId", "count":"true" }

Example from Regex Hero

0
votes

Thanks to Dan and Bruce. This exact expression worked for me

{ "filter": "search.ismatch('/k6.{5}8/','someId','full','all')", "select":"someId", "count":"true"

}