I'm trying to create a lunr index and be able to add documents to it after being assigned. This is a slightly simplified version of what I'm trying to do:
var documents = [{
'id': '1',
'content': 'hello'
}, {
'id': '2',
'content': 'world'
}, {
'id': '3',
'content': '!'
}];
var idx = lunr(function() {
this.ref('id');
this.field('content');
});
for (var i = 0; i < documents.length; ++i) {
idx.add(documents[i]);
}
This is giving me the following error: TypeError: idx.add is not a function. I've seen multiple tutorials saying this is how you're supposed to be able to do it.
It only works for me though if I add the documents when assigning idx;
var documents = [{
'id': '1',
'content': 'hello'
}, {
'id': '2',
'content': 'world'
}, {
'id': '3',
'content': '!'
}];
var idx = lunr(function() {
this.ref('id');
this.field('content');
for (var i = 0; i < documents.length; ++i) {
this.add(documents[i]);
}
});
I'm still a javascript noob so this might not be related to lunr necessarily.