Guillaume Morin
Guillaume Morin

Reputation: 4010

Azure Search Suggester - Why return duplicate value?

As a user is typing in a filter field, I want to show an autocomplete containing suggestions.

I'm trying to use Azure Search Suggester for that, but it returns duplicate values ?

ex:

POST /indexes/assets/docs/suggest?api-version=2016-09-01 HTTP/1.1
Host: xxx.search.windows.net
api-key: xxx
Content-Type: application/json

{
    search: 'bank',
    suggesterName: 'sg',
    top:5,
    searchFields: "accountName",
    select: 'accountName'
}

What is being returned:

{
  "@odata.context": "https://xxx.search.windows.net/indexes('assets')/$metadata#docs(accountName)",
  "value": [
    {
      "@search.text": "CAIXA BANK",
      "accountName": "CAIXA BANK"
    },
    {
      "@search.text": "CAIXA BANK",
      "accountName": "CAIXA BANK"
    },
    {
      "@search.text": "BANK OF AMERICA",
      "accountName": "BANK OF AMERICA"
    },
    {
      "@search.text": "BANK OF AMERICA",
      "accountName": "BANK OF AMERICA"
    },
    {
      "@search.text": "BANK OF AMERICA",
      "accountName": "BANK OF AMERICA"
    }
  ]
}

I was expecting the result to contains 5 different accountName, not repeated values for each documents having the same accountName...

I'm a missing something here ?

EDIT

It seems to be the expected behavior, suggestion return distinct documents ... It makes no sense to me, if I would like to retrieve documents I would do a query, not a suggestion.

What is the use cases of suggestions then if we can't use them to populate autocomplete fields ?

Upvotes: 0

Views: 1404

Answers (1)

Nate Ko
Nate Ko

Reputation: 933

As the link in the comment pointed out, Suggest API in Azure Search suggests documents not query terms. Suggest API returns document IDs associated with the matched field. Common use cases would be to find newspaper articles whose titles match or products whose names match the searched terms/phrases.

Some customers are using the Suggest API for autocompleting search fields. In such cases, we suggest deduping the returned field on the client side or use a secondary index. The feature however isn't designed for that. We are in fact working on a new feature that suggests search terms from the corpus for autocompleting purposes. I will update the thread when the feature is available.

Nate

Upvotes: 3

Related Questions