An Azure search service with built-in artificial intelligence capabilities that enrich information to help identify and explore relevant content at scale.
Hi Shruti,
To address this, introduce a new field in the index specifically designed for exact matches. Define this field using a custom analyzer with a keyword tokenizer. That way, the entire phrase “Microsoft Inc” is treated as a single token and not split into "Microsoft" and "Inc".
"analyzers": [
{
"name": "keyword_analyzer",
"tokenizer": "keyword",
"filters": [
"lowercase"
]
}
]
And the field definition:
{
"name": "organisationName_exact",
"type": "Edm.String",
"searchable": true,
"analyzer": "keyword_analyzer",
"filterable": false,
"retrievable": true,
"sortable": false,
"facetable": false,
"key": false
}
When indexing documents, check the organisationName_exact field contains a lowercased version of the original name. For example, if the value is “Microsoft Inc”, the organisationName_exact field should store “microsoft inc”.
Now, in the search query, continue using the regular organisationName field for general term matching, but also introduce a scoring profile that gives a significant boost when the exact phrase appears in the organisationName_exact field.
{
"search": "Microsoft Inc",
"queryType": "full",
"searchMode": "all",
"searchFields": "organisationName",
"filter": "countryCode eq 'USA'",
"scoringProfile": "exactMatchBoost",
"scoringParameters": [
"searchText='Microsoft Inc'"
]
}
And the scoring profile:
"scoringProfiles": [
{
"name": "exactMatchBoost",
"functions": [
{
"type": "magnitude",
"fieldName": "organisationName_exact",
"boost": 10,
"interpolation": "constant",
"parameters": {
"values": ["Microsoft Inc"]
}
}
],
"functionAggregation": "sum"
}
]
This way, BM25 will continue to work for overall relevance, but the exact match will receive a strong score boost, helping “Microsoft Inc” appear above similar but less precise matches like “Microsoft Inc. US.”
Hope it helps!
Please do not forget to click "Accept the answer” and Yes wherever the information provided helps you, this can be beneficial to other community members.
If you have any other questions or still running into more issues, let me know in the "comments" and I would be happy to help you.