How does search.ismatchscoring handle special characters?

Csaba Hári 20 Reputation points
2024-11-25T09:03:44.0266667+00:00

We have set an Azure Search Index. One of our use cases is to search by the "Title" property of these documents in a way where the results have to start with the search string but it does not have to be a full match. For this we have set up the following filter. In the example below we search for the text "SEC (10-Q) : Acutus Medical, Inc.":

"(Product eq 'CapitalStructure') and (search.ismatchscoring('\"SEC (10-Q) : Acutus Medical, Inc.*', 'Title', 'simple', 'all'))"

We have noticed two inconsistencies that we can't find an answer for:

  1. As in the example above, if the text ends with a dot, we receive no results. Removing the dot from the end does give results where to dot actually exists in though.
  2. For the search string "SEC (10-Q) : Local Bounti Corporation/DE" in the same filter we also have no results. Removing the "/DE" gives results where this specific original title exists as well.

Escaping the . and /DE with an escape character does not work. Adding a space between the search text and the * also results in the expected results. Why do we get no results for "SEC (10-Q) : Acutus Medical, Inc." and "SEC (10-Q) : Local Bounti Corporation/DE" if these specific titles do have existing documents?

Azure AI Search
Azure AI Search
An Azure search service with built-in artificial intelligence capabilities that enrich information to help identify and explore relevant content at scale.
1,100 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sina Salam 13,371 Reputation points
    2024-11-25T16:26:49.42+00:00

    Hello Csaba Hári,

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    I understand that you would like how to handle search.ismatchscoring special characters.

    When using search.ismatchscoring in Azure Search, handling special characters like dots (.) and slashes (/) can sometimes cause unexpected behavior. Below are practical strategies and examples to resolve such issues effectively.

    1. The full Lucene query syntax allows you to control how special characters are processed. You can enable it by setting the queryType parameter to 'full'. This is an example:
    (Product eq 'CapitalStructure') and (search.ismatchscoring('"SEC (10-Q) : Acutus Medical, Inc.*"', 'Title', 'full', 'all'))
    

    This approach ensures that special characters like colons (:) and parentheses (( and )) are treated as part of the search term.

    1. Custom analyzers allow you to define specific rules for tokenizing and indexing text. By configuring an analyzer to handle special characters, you can ensure consistent search behavior. For instance:
    • Use a custom tokenizer to split tokens only at desired characters.
    • Apply filters to preserve or remove specific symbols.

    Use this link in Azure Search analyzer documentation. - https://learn.microsoft.com/en-us/azure/search/search-analyzers) for detailed guidance on creating custom analyzers

    1. In Lucene syntax, special characters (e.g., +, -, &&, ||, !, (, ), {, }, [, ], ^, ", ~, *, ?, :) can be escaped using a backslash (\). For example:
    search.ismatchscoring('"SEC \(10\-Q\) : Acutus Medical, Inc."', 'Title', 'full', 'all')
    

    This ensures that the query treats special characters as literal parts of the search term.

    1. If the query allows, remove unnecessary special characters to simplify your input. For instance:
    • Original: "SEC (10-Q) : Acutus Medical, Inc."
    • Simplified: "SEC 10-Q Acutus Medical Inc"

    This approach minimizes the risk of misinterpretation by the search engine.

    1. If you're searching for text that begins with a specific pattern, use a prefix query:
    (Product eq 'CapitalStructure') and (search.ismatchscoring('"SEC (10-Q) : Acutus Medical, Inc*"', 'Title', 'full', 'all'))
    

    The asterisk (*) acts as a wildcard to match any characters following the prefix.

    For additional examples and reading use this link: https://learn.microsoft.com/en-us/azure/search/search-query-odata-full-text-search-functions

    I hope this is helpful! Do not hesitate to let me know if you have any other questions.


    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.