" characters need escaping in my Lucene full query syntax that I'm using with Azure Search in ." /> " characters need escaping in my Lucene full query syntax that I'm using with Azure Search in ." /> " characters need escaping in my Lucene full query syntax that I'm using with Azure Search in ."/>

Azure Search lucene regular expression with "<" and ">" symbols not working properly without escaping

113 Views Asked by At

I'm having a hard time understanding why the "<" and ">" characters need escaping in my Lucene full query syntax that I'm using with Azure Search in .NET with the Azure SDK for .NET.

For example, this search expression: "/.<Test./"

Gives me the following error:

Error occurred when searching. Error message: Failed to parse regex expression. See https://aka.ms/azure-search-full-query-regex for supported expressions. Message: Failed to parse regex expression. See https://aka.ms/azure-search-full-query-regex for supported expressions.

If I escape the "<" character so that the search expression looks like this: "/.\<Test./" then the query runs fine.

This seems weird to me because the "<" and ">" characters are not in the reserved characters for either Azure Search or for Lucene regex.

Am I missing something here?

Code for reference:

using Azure;
using Azure.Search.Documents;
using Azure.Search.Documents.Models;

const string endpoint = "{Endpoint}";
const string indexName = "{IndexName}";
const string queryApiKey = "{QueryApiKey}";
const string searchExpression = "/.<Test./";

var searchClient = new SearchClient(new Uri(endpoint), indexName, new AzureKeyCredential(queryApiKey));

var options = new SearchOptions()
{
    QueryType = SearchQueryType.Full
};

searchClient.Search<SearchResult<SearchDocument>>(searchExpression, options);

JSON query for the Azure Search explorer:

{
  "search": "/.<Test./",
  "queryType": "full"
}
0

There are 0 best solutions below