I am searching for a document by its "name" field. For example, I have two documents within my CosmosDB resource.
{
"name": "Carrot Cake",
....
}
and
{
"name": "Carrot something Cake",
....
}
Both name fields are searchable Edm.String types. I am using the default BM25Similarity and no scoring profiles are added within my index. For the name field, I am using the default standard.lucene analyzer.
When searching for the term "Carrot Cake"
(within the search explorer in the index on Azure) both of these results will show the same @search.score of 4.3356133
I want to be able to have the score for "Carrot Cake" be more than "Carrot something Cake" because the search term is found exactly, without the word "something" in the middle. Is this possible by adding a scoring profile or using a different similarity ranking?
To achieve your desired scoring behavior, where exact matches receive a higher score, you can create a custom scoring profile in your Azure Cognitive Search index.
You need to define a scoring profile named "sampath" in your index configuration. This scoring profile should give a higher boost to exact matches. Here's an example of how you can define this scoring profile:
"scoringProfiles": [
{
"name": "sampath",
"functionAggregation": "firstMatching",
"text": {
"weights": {
"name": 2
}
},
"functions": []
}
]
{
"@odata.context": "https://AISearchServiceName.search.windows.net/indexes('indexName')/$metadata#docs(*)",
"value": [
{
"@search.score": 1,
"id": "2",
"name": "JaneSmith"
},
{
"@search.score": 1,
"id": "4",
"name": "Carrot Cake"
},
{
"@search.score": 1,
"id": "5",
"name": "JaneSmith"
},
{
"@search.score": 1,
"id": "6",
"name": "BondJames"
},
{
"@search.score": 1,
"id": "1",
"name": "Carrot something Cake"
}
]
}
By applying this scoring profile, documents with an exact match in the "name" field will receive a higher score compared to partial matches. Adjust the boost value according to your specific requirements and test to ensure the desired scoring behavior.
In this scoring profile, we define a function also. Refer to link for how to add scoring profiles.
Output: