azure-cognitive-searchshingles

Azure Search Index: Tokenize words in reverse order


I have a collection field composed of "lastname, firstname" which is correctly generating two tokens, but I'd like to generate a third one (a shingle) but in the format "firstname lastname".

Example: Data on the index is "Bond, James"

A search for James Bond will bring results with both "James" or "Bond" which is what I want, but there are results with the name "James Bond" that I'd like to be on top. (As an example, one result that has the word "Bond" in several places but no James will rank higher). Comparatively, if the user searches for Bond James the results match exactly what I want, but most users will not type the last name first.

Is there a way to generate this additional token, or to at least boost the answer when both tokens are found?

I tried creating a ShingleFilter to generate the name combinations, but couldn't "inverse" the order of words. I think this might be possible using RegEx patterns but wasn't able to make it work.

The search is also used for other fields that work as expected so I can't invert the search terms. I'd like to avoid inverting the field on the Azure SQL database if possible.


Solution

  • Currently, there is no direct support for "inverting" the order of words, but there is a boosting strategy to prioritize results where both "James" and "Bond" tokens are present using Scoring profile.

    enter image description here

    To create a scoring profile to boost documents where both tokens are found in the desired order, follow these steps:

    1. Go to the index and select the scoring profile to add a scoring profile. enter image description here

    2. Select Function Aggregation in Functions.

    3. Add a scoring Function. Use functions when simple relative weights are insufficient or don't apply, as is the case of distance and freshness, which are calculations over numeric data. You can specify multiple functions per scoring profile. For more information about the EDM data types used in Azure AI Search, see Supported data types.

    enter image description here

    1. Save the function and index. To see the changes, restart and run the Indexers. enter image description here

    enter image description here

    1. Follow this link for the REST API for Azure AI Search.