Search code examples
azureazure-cognitive-searchazure-sdk-.net

Azure Search Client not working for dash (-)


If I try to search /.*mydata-mydepartment.*/ directly in portal.azure.com using Search Explorer I'm getting correct data , But when I tried same search text from C# .NET API it is giving no result.

Using nuget Azure Search Document 11.4.0, below method to fetch search result:

public async virtual Task<Response<SearchResults<T>>> SearchAsync<T>(
            string searchText,
            SearchOptions options = null,
            CancellationToken cancellationToken = default) =>
            await SearchInternal<T>(
                searchText,
                options,
                async: true,
                cancellationToken)
                .ConfigureAwait(false);

Why it's not working with .net code? What needs to be done?


Solution

  • The following:

    /.*mydata-mydepartment.*/
    

    Is a Regular Expression, and it's only available if you specify the search mode as all and query type to full. (Inside SearchOptions which currently you're setting as null)

    "queryType": "full",
    "search": "/.*mydata-mydepartment.*/",
    "searchMode": "all"
    

    More info:

    https://learn.microsoft.com/en-us/azure/search/query-lucene-syntax#bkmk_regex