getWords does not fully traverse tree
atlithorn opened this issue · 3 comments
atlithorn commented
Had two words in the trie:
week
weekend
trie.getWords('wee') only returns 'week'
I hacked getWords, removed the else in the for loop and it works fine for me
for (; i < l; ++i) {
if (c[i].wordCount)
words.push(s + c[i].stem);
else
words = words.concat(c[i].getWords(s + c[i].stem));
}
changed to:
for (; i < l; ++i) {
if (c[i].wordCount)
words.push(s + c[i].stem);
words = words.concat(c[i].getWords(s + c[i].stem));
}
mikedeboer commented
I reviewed your fix and I don't see a drawback for it :) have you - by any chance - written a test for this?
atlithorn commented
No but here's one:
var t = new Trie();
t.add('week');
t.add('weekend');
assert(t.getWords(t.find('wee')).length==2);
mikedeboer commented
thanks! fixed and pushed to master.