@acodeninja/persist 3.0.0-next.11 → 3.0.0-next.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acodeninja/persist",
3
- "version": "3.0.0-next.11",
3
+ "version": "3.0.0-next.12",
4
4
  "description": "A JSON based data modelling and persistence module with alternate storage mechanisms.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -11,7 +11,18 @@ export default class SearchIndex {
11
11
  if (model.searchProperties().length === 0) {
12
12
  throw new NoIndexAvailableSearchIndexError(this.#model);
13
13
  }
14
+ }
15
+
16
+ search(query) {
17
+ return (this.#compiledIndex ?? this.#compileIndex()).search(query).map(doc => ({
18
+ score: doc.score,
19
+ model: this.#model.fromData(this.#index[doc.ref]),
20
+ }));
21
+ }
14
22
 
23
+ #compileIndex() {
24
+ const model = this.#model;
25
+ const index = this.#index;
15
26
  this.#compiledIndex = lunr(function () {
16
27
  this.ref('id');
17
28
 
@@ -23,13 +34,8 @@ export default class SearchIndex {
23
34
  this.add(doc);
24
35
  }, this);
25
36
  });
26
- }
27
37
 
28
- search(query) {
29
- return this.#compiledIndex.search(query).map(doc => ({
30
- score: doc.score,
31
- model: this.#model.fromData(this.#index[doc.ref]),
32
- }));
38
+ return this.#compiledIndex;
33
39
  }
34
40
  }
35
41