moroshko / autosuggest-trie

Minimalistic trie implementation for autosuggest and autocomplete components
MIT License
25 stars 4 forks source link

Weird issue with splitting with custom regex #6

Closed yunyu closed 7 years ago

yunyu commented 7 years ago

I get an error with the following code:

var createTrie = require('autosuggest-trie');

var splitByHyphen = /\s+|-/;
var universities = [{ name: 'University of Tennessee-Knoxville' }];
const trie = createTrie(universities, 'name', { splitRegex: splitByHyphen });
console.log(trie.getMatches('tennessee-', { limit: 15, splitRegex: splitByHyphen }));

The error is:

C:\Users\Yunyu\Documents\VHF2017-landingpage\node_modules\autosuggest-trie\dist\create-trie\create-trie.js:79
    var length = ids.length;
                    ^

TypeError: Cannot read property 'length' of undefined
    at getWordIndices (C:\Users\Yunyu\Documents\VHF2017-landingpage\node_modules\autosuggest-trie\dist\create-trie\create-trie.js:79:21)
    at getPhraseIndices (C:\Users\Yunyu\Documents\VHF2017-landingpage\node_modules\autosuggest-trie\dist\create-trie\create-trie.js:107:43)
    at Object.getMatches (C:\Users\Yunyu\Documents\VHF2017-landingpage\node_modules\autosuggest-trie\dist\create-trie\create-trie.js:116:19)
trie\dist\create-trie\create-trie.js:116:19)

It doesn't occur when searching for a string like "of " or "tennessee-k", which is strange.

moroshko commented 7 years ago

Looks like a bug, I'll have a look.

moroshko commented 7 years ago

Should be fixed in v2.1.1.

yunyu commented 7 years ago

Thanks a lot!