Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore when removing a non-existent document on the index #24

Merged
merged 2 commits into from
May 8, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,11 @@ lunr.Index.prototype.add = function (doc) {
* @memberOf Index
*/
lunr.Index.prototype.remove = function (doc) {
var docRef = doc[this._ref],
docTokens = this.documentStore.get(docRef)
var docRef = doc[this._ref]

if (!this.documentStore.has(docRef)) return

var docTokens = this.documentStore.get(docRef)

this.documentStore.remove(docRef)

Expand Down
15 changes: 15 additions & 0 deletions test/index_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ test('removing a document from the index', function () {
equal(idx.documentStore.length, 0)
})

test('removing a non-existent document from the index', function () {
var idx = new lunr.Index,
doc = {id: 1, body: 'this is a test'},
doc2 = {id: 2, body: 'i dont exist'}

idx.field('body')
equal(idx.documentStore.length, 0)

idx.add(doc)
equal(idx.documentStore.length, 1)

idx.remove(doc2)
equal(idx.documentStore.length, 1)
})

test('updating a document', function () {
var idx = new lunr.Index,
doc = {id: 1, body: 'foo'}
Expand Down