lunr.js: Uncaught TypeError: Cannot read property 'tf' of undefined
Hello, I am getting this error “Uncaught TypeError: Cannot read property ‘tf’ of undefined” in 0.7.2. (I was getting it in 0.5 as well, so upgraded, still getting it.)
It does not fail for every search; just some. I can’t figure out how to debug this or identify what is different between the search terms that work and the ones that don’t.
Note: I have a web site created by an now unavailable developer. I am hacking my way through trying to fix problems like this. I know just enough JS, etc, to be dangerous, but not enough to know what I am doing.
My browser reports the error on the tf = line here:
lunr.Index.prototype.documentVector = function (documentRef) {
var documentTokens = this.documentStore.get(documentRef),
documentTokensLength = documentTokens.length,
documentVector = new lunr.Vector
for (var i = 0; i < documentTokensLength; i++) {
var token = documentTokens.elements[i],
tf = this.tokenStore.get(token)[documentRef].tf,
idf = this.idf(token)
documentVector.insert(this.corpusTokens.indexOf(token), tf * idf)
};
return documentVector
}
It seems to be a something to do with this function. When I get the error, this function bails out at the if statement.
lunr.TokenStore.prototype.getNode = function (token) {
if (!token) return {}
var node = this.root
for (var i = 0; i < token.length; i++) {
if (!node[token.charAt(i)]) return {}
node = node[token.charAt(i)]
}
return node
}
Any suggestions how I can debug this or fix it? Thank you. – Mike
About this issue
- Original URL
- State: open
- Created 8 years ago
- Comments: 23 (10 by maintainers)
Commits related to this issue
- Remove emoji from search index. See https://github.com/olivernn/lunr.js/issues/243 . — committed to ashfurrow/jekyll-lunr-js-search by ashfurrow 7 years ago
I can confirm it’s definitely related to emoji’s. I removed them from our Gitbook and search is all good again.