corejavascript / typeahead.js

typeahead.js is a fast and fully-featured autocomplete library
https://typeahead.js.org/
MIT License
967 stars 231 forks source link

bug in the intersect function #170

Open simonquest opened 6 years ago

simonquest commented 6 years ago

There is a small bug in the getIntersection function used for filtering results: the two input arrays don't get sorted correctly if arrays contain numeric values as javascript sort function sorts alphabetically. This will affect searches involving multiple tokens.

I suggest sorting array like this

.sort((a, b) => (a - b));

cimbul commented 6 years ago

This should be fixed by #159, if someone can merge it in.

Note to anyone else encountering this: the workaround for us was to coerce the IDs to a string. Something like this:

var engine = new Bloodhound({
  identify: function(datum) {
    return datum.id + "";
  },
});

This will make the > and < comparisons in getIntersection() consistent with the Array#sort() ordering.

ezr-ondrej commented 2 years ago

? :)