Skip to content

Conversation

DannyNemer
Copy link

See issue #18

As demonstrated below, when loading a serialized index, lunr.js incorrectly loads the serialized index's documentStore.

First, create an index, add a document to the index, and log the index.documentStore.store to show its correct form:

var index = lunr(function () { //create index
    this.field('title')
    this.ref('id')
})
index.add({id: 100, title: 'apple' }) //add document to index
console.log(index.documentStore.store) //log documentStore.store before serializing index

The following is the log of the index.documentStore.store in its correct form:

{ '100': { length: 1, elements: [ 'appl' ] } }

Then, serialize the index and store it to the database:

user.index = index.toJSON() //serialize index and store it in the database
user.save() //save changes to database

Load the serialized index and log the index.documentStore.store to show it in its incorrect form:

index = lunr.Index.load(user.index) //load previously serialized index from database
console.log(index.documentStore.store) //log incorrect documentStore after loading serialized index

The following is the log of the index.documentStore.store in its incorrect form:

{ '100': { length: 1, elements: { length: 1, elements: [Object] } } }

Bug: The bug occurs on line 962 of lunr.js in the lunr.Store.load() function, which is called in lunr.Index.load(). Simply, this is fixed by changing

memo[key] = lunr.SortedSet.load(serialisedData.store[key])

to

memo[key] = lunr.SortedSet.load(serialisedData.store[key].elements)

Fixes a bug where when loading a serialized index, the elements of the index.documentStore.store would be incorrectly loaded. See issue #18
@DannyNemer DannyNemer closed this Apr 18, 2013
@DannyNemer DannyNemer deleted the patch-1 branch April 18, 2013 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant