olivernn / lunr.js

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

TypeError: Cannot convert undefined or null to object #360

Closed brandon-bethke-timu closed 6 years ago

brandon-bethke-timu commented 6 years ago

The following code will throw an exception: TypeError: Cannot convert undefined or null to object

const lunr = require("lunr");
let lunarbuilder;
lunr(builder => {
    lunrbuilder = builder;
    builder.field('name');
    builder.field('description');
    builder.ref('id');
});

lunrbuilder.add({
    name: 'myname',
    description: 'mydescription',
    type: 'core:test',
    key: '1',
    id: 1,
    url: '/api/graph/core:test/1',
    createdAt: '2018-07-19T20:33:18.964Z',
    archived: false
});

lunrbuilder.add({
    name: 'myname2',
    description: 'mydescription',
    type: 'core:test',
    key: '2',
    id: 2,
    url: '/api/graph/core:test/2',
    createdAt: '2018-07-19T20:33:18.968Z',
    archived: false
});

let search = lunrbuilder.build();
search.search("+name:myname +description:value");
olivernn commented 6 years ago

Thanks for reporting, I was able to reproduce this issue. It looks like it is triggered when the search contains two required terms each scoped by a field but one that matches nothing.

I've tracked the bug down to the way that lunr.Set.complete and lunr.Set.empty are handled in lunr.Set#union and lunr.Set#intersect. I'll put together a bug fix and a new release in the next few days.

asinakdeniz commented 6 years ago

Hi, We have faced with the same problem so kindly request you to this fix this bug as soon as possible. We will be waiting a new release impatiently. Many thanks...

olivernn commented 6 years ago

I have just published 2.3.1 which contains a fix for this issue.