@acodeninja/persist 3.0.1 → 3.1.0-next.1

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.1",
3
+ "version": "3.1.0-next.1",
4
4
  "description": "A JSON based data modelling and persistence module with alternate storage mechanisms.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -25,8 +25,8 @@
25
25
  "ajv": "^8.17.1",
26
26
  "ajv-errors": "^3.0.0",
27
27
  "ajv-formats": "^3.0.1",
28
+ "fuse.js": "^7.1.0",
28
29
  "lodash": "^4.17.21",
29
- "lunr": "^2.3.9",
30
30
  "slugify": "^1.6.6",
31
31
  "ulid": "^2.3.0"
32
32
  },
@@ -1,4 +1,4 @@
1
- import lunr from 'lunr';
1
+ import Fuse from 'fuse.js';
2
2
 
3
3
  /**
4
4
  * Represents a single search result with the associated model instance and its relevance score.
@@ -47,7 +47,7 @@ export default class SearchIndex {
47
47
  search(query) {
48
48
  return this.searchIndex
49
49
  .search(query)
50
- .map(doc => new SearchResult(this.#model.fromData(this.#index[doc.ref]), doc.score));
50
+ .map(doc => new SearchResult(this.#model.fromData(this.#index[doc.item.id]), doc.score));
51
51
  }
52
52
 
53
53
  /**
@@ -66,18 +66,11 @@ export default class SearchIndex {
66
66
  * @private
67
67
  */
68
68
  #compileIndex() {
69
- const model = this.#model;
70
69
  const index = this.#index;
71
- this.#compiledIndex = lunr(function () {
72
- this.ref('id');
73
-
74
- for (const field of model.searchProperties()) {
75
- this.field(field);
76
- }
77
-
78
- Object.values(index).forEach(function (doc) {
79
- this.add(doc);
80
- }, this);
70
+ this.#compiledIndex = new Fuse(Object.values(index), {
71
+ includeScore: true,
72
+ ignoreDiacritics: true,
73
+ keys: this.#model.searchProperties().map(p => p.replace(/\[\*]\./g, '')),
81
74
  });
82
75
 
83
76
  return this.#compiledIndex;