Closed Vonfry closed 7 years ago
The document reference must be a string, try this:
_d['id'] = idx.toString()
In chrome, idx is string for default.
And if I change it to string using toString
, it also has the same problem
Interesting, can you put together a simple test case that I can use to re-create the error?
This is an error log in safari
undefined is not an object (evaluating 'this.invertedIndex[h][n][t]')
To be able to help I need to be able to re-create the issue myself. Try and put together an index and document that can be run in something like jsfiddle that also has the same issues.
https://test.vonfry.name/lunrjs/
A test case.
Could you try and narrow it down to just the document that is failing, and narrow that document down to just the field that is causing issues.
I try to narrow it down.
The problem seems that it only happen when the content has some special word, but I cannot find which word is the problem...
https://test.vonfry.name/lunrjs https://test.vonfry.name/lunrjs/search.json
jsfiddle: https://jsfiddle.net/Vonfry/suu1ju5f/
Uh...
Ok, I've update the fiddle with a more minimal reproduction.
This looks like a regression from the 1.0.0 branch. It is because "constructor" is a property of all JavaScript objects, this causes issues when using objects as hashes.
I'll look at putting together a fix for this in the next few hours, thanks for reporting.
I've just pushed 2.0.1 which includes a fix for this issue, please check it out and let me know if you still have problems...
Thank you!! It can be run.
I still have an issue with add
since I've updated to 2.0.0 (and then 2.0.1).
I've simplified it and now I have only this:
var idx = lunr(function () {
this.field('name')
})
var doc = {
"name": "hello",
"id": 1
}
idx.add(doc)
And in the console:
Uncaught TypeError: idx.add is not a function
This worked perfectly fine before the update. I have this issue in Chrome and Safari (didn't try other browsers)
@MatthiasRMS this isn't at all related to the original issue, in the future please open a new issue rather than commenting on an unrelated issue.
Also, the error message is pretty clear here, add
is not a function on idx
. Since there is a major version bump you can expect some breaking changes in the API, this is probably the largest and is well documented.
add
must be called within the function passed to the lunr
function, i.e.
var idx = lunr(function () {
this.field('name')
this.add({ name: "hello", id: "1" })
})
@olivernn my bad, I didn't see it in the doc. Sorry about that !
add
seems that it is worked is different from version 2?The same code and json data can be run correctly in version
1.0.0
, but it cannot be run in version2.0.0
. And I cannot find any question in my code.expection is here:
TypeError: Cannot read property '1' of undefined
, Un...I don't know what it is.And part of my code.