@stoker-platform/web-app 0.5.12 → 0.5.13
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/CHANGELOG.md +6 -0
- package/package.json +1 -1
- package/src/utils/localFullTextSearch.ts +8 -4
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { CollectionSchema, StokerRecord } from "@stoker-platform/types"
|
|
2
|
-
import MiniSearch, { SearchResult } from "minisearch"
|
|
2
|
+
import MiniSearch, { Options, SearchResult } from "minisearch"
|
|
3
3
|
|
|
4
4
|
export const localFullTextSearch = (
|
|
5
5
|
collection: CollectionSchema,
|
|
6
6
|
query: string,
|
|
7
7
|
list: StokerRecord[],
|
|
8
8
|
filter?: (result: SearchResult) => boolean,
|
|
9
|
+
tokenize?: boolean,
|
|
9
10
|
) => {
|
|
10
11
|
const { recordTitleField, fullTextSearch } = collection
|
|
11
|
-
const
|
|
12
|
+
const miniSearchConfig: Options = {
|
|
12
13
|
fields: fullTextSearch || [recordTitleField],
|
|
13
14
|
storeFields: fullTextSearch || [recordTitleField],
|
|
14
|
-
tokenize: (string) => [string],
|
|
15
15
|
searchOptions: {
|
|
16
16
|
...(collection.searchOptions || {
|
|
17
17
|
fuzzy: 0.2,
|
|
@@ -19,7 +19,11 @@ export const localFullTextSearch = (
|
|
|
19
19
|
}),
|
|
20
20
|
filter,
|
|
21
21
|
},
|
|
22
|
-
}
|
|
22
|
+
}
|
|
23
|
+
if (tokenize) {
|
|
24
|
+
miniSearchConfig.tokenize = (string) => [string]
|
|
25
|
+
}
|
|
26
|
+
const miniSearch = new MiniSearch(miniSearchConfig)
|
|
23
27
|
// eslint-disable-next-line security/detect-object-injection
|
|
24
28
|
miniSearch.addAll(list)
|
|
25
29
|
const results = miniSearch.search(query)
|