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

wildcards search sometimes gives error "TypeError: Cannot read property '_index' of undefined" #314

Closed lz000 closed 6 years ago

lz000 commented 6 years ago

I have an array of 100000+ objects indexed

var data = [
{id: 'xxx', name: 'xxx'}
...
]

var index = lunr(function () {
                    this.field('name');
                    data.forEach(function(item){
                        this.add(item)
                    });
                });

When I do wildcards search index.search(query + '*');, some queries give error "TypeError: Cannot read property '_index' of undefined", others not.

"error": "TypeError: Cannot read property '_index' of undefined\n    at lunr.Index.query (...node_modules\\lunr\\lunr.js:1815:33)\n    at lunr.Index.search (...node_modules\\lunr\\lunr.js:1725:15)\n

But so far as I tested, the queries that failed on wildcards search work on fuzzy matches index.search(query + '~1'); The version I'm using is 2.1.4.

Any idea why this is happening?

olivernn commented 6 years ago

Could you take a look at #279 and tell me if it is similar to your issue? Also, if you could put together a reproduction somewhere like jsfiddle that would be a great help.

lz000 commented 6 years ago

Yes it is similar. I can confirm that the following code can work around the issue.

lunr(function () {
  this.pipeline.remove(lunr.trimmer)
})
olivernn commented 6 years ago

Ok, I'm going to close this as a duplicate of #279, if you have any more questions/suggestions please comment on that issue.