Uncaught TypeError: Cannot read property 'tf' of undefined
See original GitHub issueHello, 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
Issue Analytics
- State:
- Created 7 years ago
- Comments:23 (10 by maintainers)
Top GitHub Comments
I can confirm it’s definitely related to emoji’s. I removed them from our Gitbook and search is all good again.
We solved this using gitbook-plugin-advanced-emoji and replacing all emojis with their text representation from the emoji cheatsheet.