Hi @Bernard Brown
The short answers is yes, it can be handled using the SDK.
This can be done by using the search.ismatch function in the Azure Search SDK and by properly formatting your query string to handle spaces, dashes, and multiple terms.
Here's how you can approach this:
- Prepare the Query String: Before passing the query string to the
search.ismatchfunction, you need to format it to handle spaces and dashes. You can replace spaces with a space character preceded by a backslash () and replace dashes with the same pattern (\ -). This ensures that the spaces and dashes are treated as part of the term rather than separators.
query_string = "Van Noy, Jackson-Davis, Jackson - Davis, Jackson Davis Johnson"
formatted_query = query_string.replace(" ", "\ ").replace("-", "\ -")
- Use search.ismatch: Use the
search.ismatchfunction and pass the formatted query string as the pattern. Thesearch.ismatchfunction performs a regular expression match on the field, allowing you to handle multiple terms in a single query.
from azure.search.documents import SearchClient
search_client = SearchClient(...)
results = search_client.search(
search_text="",
filter="search.ismatch('lastName', '{0}')".format(formatted_query)
)
With this approach, the search.ismatch function will match any document where the lastName field contains any of the terms in the formatted query string, including terms with spaces, dashes, and multiple terms.
It's important to note that the search.ismatch function uses regular expression matching, which can be less efficient than the [search.in](http://search.in/) function for large sets of terms. If you have a large number of terms to match, you might want to consider splitting the query into multiple smaller queries or using an alternative approach, such as creating a custom analyzer that can handle these types of terms.
If you have further questions, please let us know.
-Grace