Autocomplete search returns more precise results if a search query is wrapped in double quotes

the index definition

{
  "mappings": {
    "dynamic": false,
    "fields": {
      "fullName": [
        {
          "foldDiacritics": false,
          "maxGrams": 7,
          "minGrams": 3,
          "tokenization": "edgeGram",
          "type": "autocomplete"
        }
      ]
    }
  }
}

the search query

{
  index: 'usersAutocomplete',
  autocomplete: {
    path: 'fullName',
    query: '"bogdan"',
    fuzzy: {
      maxEdits: 2,
      prefixLength: 0,
      maxExpansions: 50
    }
  }
}

For query query: '"bogdan"' i’m getting 5 users that matches the query very well.
For query query: 'bogdan' i’m getting more than 20 users, some of then don’t match the query well.
So my question, how double quotes affects the searching behavior?

Hi @Bohdan_Zagursky, it’s a good question. It really comes down to how your data looks. You might benefit from executing the query as a compound query where the autocomplete is one should clause and there is a phrase query as a should clause as well.

compound docs

I’m also attempting to build this functionality on top of Atlas Search.

Most of my index fields are autocomplete, however, autocomplete appears to be incompatible with phrase. (See https://www.mongodb.com/community/forums/t/phrase-searches-dont-work-for-autocomplete-fields/146749) Making the field type: "string" in the index allows for exact searching but causes another issue, which is that I want my field to be both searchable as an autocomplete (fuzzy) and as an exact match (double quotes).

So as an example, let’s say the field is called tags, and I’ve got a document where tags is Horror, Film Noir, Dark. I’d like my users to be able to find this document by searching with "Film Noir" (with double quotes) but also by fuzzy-searching by something with typos, such as Fiml Nior.

But also I want them to find the document with a search like "Film Noir" Dakr (exact match + fuzzy on the same field).

So @Marcus (or anyone else), is there some way to index a field as both autocomplete and as a string? Or is there a better way to do this?

Right now it seems I have to choose one or the other for a given field, and in my case I want almost all of my collection’s fields to be searchable as exact matches AND fuzzily, depending on whether quoted phrases/words are included (like Google Search).

Thank you!

OK, my issue was that I had to find an undocumented feature of index field definitions, which is that a field can be defined as an array of types!

someField: [     /* <--- NOT DOCUMENTED on 'Define Atlas Search Indexes' page
  { type: "string" },
  { type: "autocomplete", /*...*/ },
]

I found the answer in Atlas Search from Soup to Nuts: The Restaurant Finder Demo App.