@forcecalendar/core 2.1.14 → 2.1.15
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/core/search/EventSearch.js +42 -0
- package/package.json +1 -1
|
@@ -10,9 +10,37 @@ export class EventSearch {
|
|
|
10
10
|
// Search index for performance
|
|
11
11
|
this.searchIndex = new Map();
|
|
12
12
|
this.indexFields = ['title', 'description', 'location', 'category'];
|
|
13
|
+
this._indexDirty = false;
|
|
13
14
|
|
|
14
15
|
// Build initial index
|
|
15
16
|
this.rebuildIndex();
|
|
17
|
+
|
|
18
|
+
// Subscribe to EventStore changes to keep index in sync
|
|
19
|
+
if (this.eventStore && typeof this.eventStore.subscribe === 'function') {
|
|
20
|
+
this._unsubscribe = this.eventStore.subscribe(change => {
|
|
21
|
+
if (change.type === 'batch') {
|
|
22
|
+
this._indexDirty = true;
|
|
23
|
+
} else if (
|
|
24
|
+
change.type === 'add' ||
|
|
25
|
+
change.type === 'update' ||
|
|
26
|
+
change.type === 'remove' ||
|
|
27
|
+
change.type === 'clear'
|
|
28
|
+
) {
|
|
29
|
+
this._indexDirty = true;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Destroy the search engine and unsubscribe from store changes
|
|
37
|
+
*/
|
|
38
|
+
destroy() {
|
|
39
|
+
if (this._unsubscribe) {
|
|
40
|
+
this._unsubscribe();
|
|
41
|
+
this._unsubscribe = null;
|
|
42
|
+
}
|
|
43
|
+
this.searchIndex.clear();
|
|
16
44
|
}
|
|
17
45
|
|
|
18
46
|
/**
|
|
@@ -34,6 +62,9 @@ export class EventSearch {
|
|
|
34
62
|
return [];
|
|
35
63
|
}
|
|
36
64
|
|
|
65
|
+
// Rebuild index if stale
|
|
66
|
+
this._ensureIndex();
|
|
67
|
+
|
|
37
68
|
// Normalize query
|
|
38
69
|
const normalizedQuery = caseSensitive ? query : query.toLowerCase();
|
|
39
70
|
const queryTerms = this.tokenize(normalizedQuery);
|
|
@@ -443,11 +474,22 @@ export class EventSearch {
|
|
|
443
474
|
}
|
|
444
475
|
}
|
|
445
476
|
|
|
477
|
+
/**
|
|
478
|
+
* Ensure the search index is up to date
|
|
479
|
+
* @private
|
|
480
|
+
*/
|
|
481
|
+
_ensureIndex() {
|
|
482
|
+
if (this._indexDirty) {
|
|
483
|
+
this.rebuildIndex();
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
446
487
|
/**
|
|
447
488
|
* Rebuild search index
|
|
448
489
|
*/
|
|
449
490
|
rebuildIndex() {
|
|
450
491
|
this.searchIndex.clear();
|
|
492
|
+
this._indexDirty = false;
|
|
451
493
|
const events = this.eventStore.getAllEvents();
|
|
452
494
|
|
|
453
495
|
for (const event of events) {
|