TarekRaafat / autoComplete.js

Simple autocomplete pure vanilla Javascript library.
https://tarekraafat.github.io/autoComplete.js
Apache License 2.0
3.93k stars 236 forks source link

Items aren't matched for every search string #348

Open tannerli opened 2 years ago

tannerli commented 2 years ago

System information

Describe the bug Certain items seem are not matched for every search-string. I initialized an autocomplete with a list with ~150 entries, among others:

  {
    "id": 86,
    "name": "231031 - molcare - molcare, shampoo für normales bis trockenes haar, 5 l (5 Liter)"
  },
 /* ... more items ... */
  {
    "id": 136,
    "name": "None - molcare, Shampoo für normales bis trockenes Haar, 10 Liter (10 Liter)"
  },

the autocomplete config is as follows:

const AUTOCOMPLETE_CONFIG = {
  data: {
    keys: ['name'],
    cache: false
  },
  resultsList: {
      element: (list, data) => {
          if (!data.results.length) {
              const message = document.createElement("div");
              message.setAttribute("class", "no_result");
              message.innerHTML = `<span>Kein Treffer für "${data.query}"</span>`;
              list.prepend(message);
          }
      },
      maxResults: -1,
      noResults: true,
  },
  resultItem: {
      highlight: true
  },
  searchEngine: 'loose'
}

Now, the first of these items is matched for any substring of it's name, like trock, shampoo, haar: Selection_857 Selection_856

However, the second Item is never matched, despite having the same substrings in it's name. I only could get it to mtch using the None at the start, but no other search string worked, in either strict or loose engine setting nor when playing around: Selection_855 with capitalization

Expected behavior Since the second element can be matched, I assume it to be loaded correctly in the autocomplete. Therefore I would expect it to be matched for any Substring in it's name, like Shampoo, normal or Haar

IvAndrew commented 1 year ago

maxResults: -1, This line cause your error. If you want remove limitation of list length than set maxResults to undefined. See #378

tannerli commented 1 year ago

@IvAndrew Thanks for your input. Tbh, it was a pressing issue for me/us, so we migrated away from this lib in favour of https://github.com/twitter/typeahead.js/

So I sadly cannot test your proposed fix anymore.