When should we use text search

I have a collection of following format.

{
    "hotelId": "H00000",
    "hotelName": "Hotel Spa Elia",
}

I want to build a autocomplete feature on hotelName

Is atlas text search with autocomplete is suitable for this task or this would be a over kill?

If trying to do autocomplete, Atlas Search is the way to go!

Check out this blog to see an in depth comparison: A Decisioning Framework for MongoDB $regex and $text vs Atlas Search | MongoDB

2 Likes

Thanks,

I made following two indices and respective queries

index_1:

index

{
  "mappings": {
    "dynamic": false,
    "fields": {
      "hotelName": {
        "foldDiacritics": false,
        "type": "autocomplete"
      }
    }
  }
}

query

[
        {
            "$search": {
                "index": "index_1",
                "autocomplete": {
                    "path": "hotelName",
                    "query": "rad",
                    "fuzzy": {
                        "maxEdits": 1,
                        "prefixLength": 3,
                        "maxExpansions": 10
                    }
                }
            }
        }
]

index_2:

index

{
  "mappings": {
    "dynamic": false,
    "fields": {
      "hotelName": {
        "type": "string"
      }
    }
  }
}

query

[
      {
          '$search': {
              'index': 'index_2',
              'text': {
                  "query": "rad",
                  'path': {
                      'wildcard': '*'
                  },
                  "fuzzy": {
                      "maxEdits": 1,
                      "prefixLength": 3,
                      "maxExpansions": 10
                  }
              }
          }
      }
]

I find accepted results in both case. I wonder what are the difference in using fuzzy search with autocomplete and not?

Fuzzy creates space for spelling errors or 1 letter being off from the results returned. Autocomplete just returning results as they match the fragment being typed. Combined allows for 1 letter off and fragments to return results.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.