olivernn / lunr.js

A bit like Solr, but much smaller and not as bright
http://lunrjs.com
MIT License
8.96k stars 548 forks source link

Error in some search queries #40

Closed tinganho closed 9 years ago

tinganho commented 11 years ago

I got this error on some certain search queries

TypeError: Cannot read property 'tf' of undefined at lunr.Index.documentVector (/usr/local/lib/node_modules/grunt-translate/node_modules/lunr/lunr.js:1104:53) at lunr.Index.search (/usr/local/lib/node_modules/grunt-translate/node_modules/lunr/lunr.js:1076:61) at Array.map (native) at lunr.SortedSet.map (/usr/local/lib/node_modules/grunt-translate/node_modules/lunr/lunr.js:574:24) at lunr.Index.search (/usr/local/lib/node_modules/grunt-translate/node_modules/lunr/lunr.js:1075:6) at Search.query (/usr/local/lib/node_modules/grunt-translate/src/modules/search.js:93:24) at module.exports (/usr/local/lib/node_modules/grunt-translate/app/modules/search/searchApi.js:9:21) at callbacks (/usr/local/lib/node_modules/grunt-translate/node_modules/express/lib/router/index.js:161:37) at param (/usr/local/lib/node_modules/grunt-translate/node_modules/express/lib/router/index.js:135:11) at pass (/usr/local/lib/node_modules/grunt-translate/node_modules/express/lib/router/index.js:142:5)

olivernn commented 11 years ago

Thanks for reporting this error, please let me know what version of lunr you are using (and what version of node). It'd be really useful if you could provide a cut down version of your index and a query that causes the error too.

severinh commented 11 years ago

lunr.js crashed on exactly the same line of code in my case because my German stop word filter did not filter the empty string. Apparently, the document store contained the empty string token, while the token store did not, leading to the error. Of course, there might be a different cause in tinganho's case.

Either way, I might try to find the source of the empty string bug and provide a fix and corresponding test case.

tinganho commented 10 years ago

@severinh and @olivernn I removed this line after this.index.pipeline.remove(lunr.stopWordFilter); creating the index caused this problem. I installed it recently with bower@0.4.3

shredding commented 10 years ago

Adding

this.pipeline.add(function (token) {
    if (token.length > 0) return token;
})

fixed it for me.

olivernn commented 9 years ago

Wow, this is an old issue! I've pushed changes now in 0.6.0 that should solve this issue, let me know if you still have issues with the latest version.