From 8dca24f9395baa56c4b9fe25ef3d76f30b7bb24d Mon Sep 17 00:00:00 2001 From: Adam Cabler Date: Mon, 31 Aug 2015 16:12:40 -0700 Subject: [PATCH] Skip adding null fieldTokens If a particular doc doesn't have a field, it will have null tokens, so don't add null to the set to prevent invalid ref later. --- lunr.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lunr.js b/lunr.js index 3c5fabaf..e5922897 100644 --- a/lunr.js +++ b/lunr.js @@ -934,7 +934,8 @@ lunr.Index.prototype.add = function (doc, emitEvent) { var fieldTokens = this.pipeline.run(lunr.tokenizer(doc[field.name])) docTokens[field.name] = fieldTokens - lunr.SortedSet.prototype.add.apply(allDocumentTokens, fieldTokens) + if(doc[field.name]) + lunr.SortedSet.prototype.add.apply(allDocumentTokens, fieldTokens) }, this) this.documentStore.set(docRef, allDocumentTokens)