elasticlunr.DocumentStore is a simple key-value document store used for storing sets of tokens for
documents stored in index.
elasticlunr.DocumentStore = function () {
this.docs = {};
this.length = 0;
};
Option name | Type | Description |
---|---|---|
serialisedData | Object | The serialised document store to load. |
return | elasticlunr.Store |
Loads a previously serialised document store
elasticlunr.DocumentStore.load = function (serialisedData) {
var store = new this;
store.length = serialisedData.length;
store.docs = serialisedData.docs;
return store;
};
Option name | Type | Description |
---|---|---|
docRef | Object | The key used to store the JSON format doc. |
doc | Object | The JSON format doc. |
Stores the given doc in the document store against the given id.
If docRef already exist, then update doc.
elasticlunr.DocumentStore.prototype.addDoc = function (docRef, doc) {
if (!this.hasDoc(docRef)) this.length++;
this.docs[docRef] = doc;
};
Option name | Type | Description |
---|---|---|
docRef, | Object | The key to lookup and retrieve from the document store. |
return | Object |
Retrieves the JSON doc from the document store for a given key.
elasticlunr.DocumentStore.prototype.getDoc = function (docRef) {
return this.docs[docRef];
};
Option name | Type | Description |
---|---|---|
docRef | Object | The id to look up in the document store. |
return | Boolean |
Checks whether the document store contains a key (docRef).
elasticlunr.DocumentStore.prototype.hasDoc = function (docRef) {
return docRef in this.docs;
};
Option name | Type | Description |
---|---|---|
docRef | Object | The id to remove from the document store. |
Removes the value for a key in the document store.
elasticlunr.DocumentStore.prototype.removeDoc = function (docRef) {
if (!this.hasDoc(docRef)) return;
delete this.docs[docRef];
this.length--;
};
Returns a representation of the document store ready for serialisation.
elasticlunr.DocumentStore.prototype.toJSON = function () {
return {
docs: this.docs,
length: this.length
};
};