@digigov/text-search 1.1.3-rc.16 → 1.2.0-85c27c19
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/cjs/hook/index.js +46 -46
- package/cjs/hook.js.map +7 -0
- package/cjs/index.js +39 -19
- package/cjs/index.js.map +7 -0
- package/cjs/search/index.js +24 -6
- package/cjs/search/index.js.map +7 -0
- package/cjs/search/lang/gr/encoder/index.js +35 -23
- package/cjs/search/lang/gr/encoder.js.map +7 -0
- package/cjs/search/lang/gr/normalization-map/index.js +126 -104
- package/cjs/search/lang/gr/normalization-map.js.map +7 -0
- package/cjs/search/search-index/index.js +86 -119
- package/cjs/search/search-index.js.map +7 -0
- package/cjs/search/utils/index.js +47 -63
- package/cjs/search/utils.js.map +7 -0
- package/cjs/types/index.js +16 -4
- package/cjs/types.js.map +7 -0
- package/hook/index.js +18 -41
- package/hook.js.map +7 -0
- package/index.js +7 -3
- package/index.js.map +7 -0
- package/package.json +3 -3
- package/search/index.js +5 -1
- package/search/index.js.map +7 -0
- package/search/lang/gr/encoder/index.js +13 -19
- package/search/lang/gr/encoder.js.map +7 -0
- package/search/lang/gr/normalization-map/index.js +104 -100
- package/search/lang/gr/normalization-map.js.map +7 -0
- package/search/search-index/index.js +59 -110
- package/search/search-index.js.map +7 -0
- package/search/utils/index.js +25 -58
- package/search/utils.js.map +7 -0
- package/types/index.js +1 -1
- package/types.js.map +7 -0
- package/cjs/hook.spec/index.js +0 -481
- package/cjs/search/__tests__/utils.spec/index.js +0 -83
- package/cjs/test-utils/data.json +0 -552
- package/hook.spec/index.js +0 -478
- package/hook.spec/package.json +0 -6
- package/search/__tests__/utils.spec/index.js +0 -81
- package/search/__tests__/utils.spec/package.json +0 -6
- package/test-utils/data.json +0 -552
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
import { greekToGreeklishMap } from "./normalization-map";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*/
|
|
16
|
-
export function encodeGreek(str) {
|
|
17
|
-
return ('' + str).toLowerCase().normalize('NFD').replace(diacriticsRegex, '').replace(greekCharsRegex, function (match) {
|
|
18
|
-
return greekToGreeklishMap[match];
|
|
19
|
-
}).split(whitespaceRegex);
|
|
20
|
-
}
|
|
2
|
+
const whitespaceRegex = /[\p{Z}\p{S}\p{P}\p{C}]+/u;
|
|
3
|
+
const diacriticsRegex = /[\u0300-\u036f]/g;
|
|
4
|
+
const greekCharsRegex = new RegExp(
|
|
5
|
+
Object.keys(greekToGreeklishMap).join("|"),
|
|
6
|
+
"igu"
|
|
7
|
+
);
|
|
8
|
+
function encodeGreek(str) {
|
|
9
|
+
return ("" + str).toLowerCase().normalize("NFD").replace(diacriticsRegex, "").replace(greekCharsRegex, (match) => greekToGreeklishMap[match]).split(whitespaceRegex);
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
encodeGreek
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=encoder.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/search/lang/gr/encoder.ts"],
|
|
4
|
+
"sourcesContent": ["import { greekToGreeklishMap } from './normalization-map';\n\nconst whitespaceRegex = /[\\p{Z}\\p{S}\\p{P}\\p{C}]+/u;\nconst diacriticsRegex = /[\\u0300-\\u036f]/g;\nconst greekCharsRegex = new RegExp(\n Object.keys(greekToGreeklishMap).join('|'),\n 'igu'\n);\n\n/**\n * Encode a string containing greek characters to greeklish\n *\n * This function is used to encode and tokenize a string containing greek characters.\n * It replaces greek characters with their latin counterparts, while also removing\n * any diacritics.\n *\n * @param str - The string to encode\n * @returns An array of encoded words\n */\nexport function encodeGreek(str: string) {\n return ('' + str)\n .toLowerCase()\n .normalize('NFD')\n .replace(diacriticsRegex, '')\n .replace(greekCharsRegex, (match) => (greekToGreeklishMap as any)[match])\n .split(whitespaceRegex);\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,2BAA2B;AAEpC,MAAM,kBAAkB;AACxB,MAAM,kBAAkB;AACxB,MAAM,kBAAkB,IAAI;AAAA,EAC1B,OAAO,KAAK,mBAAmB,EAAE,KAAK,GAAG;AAAA,EACzC;AACF;AAYO,SAAS,YAAY,KAAa;AACvC,UAAQ,KAAK,KACV,YAAY,EACZ,UAAU,KAAK,EACf,QAAQ,iBAAiB,EAAE,EAC3B,QAAQ,iBAAiB,CAAC,UAAW,oBAA4B,KAAK,CAAC,EACvE,MAAM,eAAe;AAC1B;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,100 +1,104 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
};
|
|
1
|
+
const greekToGreeklishMap = {
|
|
2
|
+
\u0393\u03A7: "GX",
|
|
3
|
+
\u03B3\u03C7: "gx",
|
|
4
|
+
\u03A4\u0398: "T8",
|
|
5
|
+
\u03C4\u03B8: "t8",
|
|
6
|
+
\u03B8\u03B7: "8h",
|
|
7
|
+
\u0398\u03B7: "8h",
|
|
8
|
+
\u0398\u0397: "8H",
|
|
9
|
+
\u03B1\u03C5: "au",
|
|
10
|
+
\u0391\u03C5: "Au",
|
|
11
|
+
\u0391\u03A5: "AY",
|
|
12
|
+
\u03B5\u03C5: "eu",
|
|
13
|
+
\u03B5\u03CD: "eu",
|
|
14
|
+
\u03B5\u03CB: "ey",
|
|
15
|
+
\u03B5\u03B0: "ey",
|
|
16
|
+
\u0395\u03C5: "Eu",
|
|
17
|
+
\u0395\u03CD: "Eu",
|
|
18
|
+
\u0395\u03CB: "Ey",
|
|
19
|
+
\u0395\u03B0: "Ey",
|
|
20
|
+
\u0395\u03A5: "EY",
|
|
21
|
+
\u03BF\u03C5: "ou",
|
|
22
|
+
\u03BF\u03CD: "ou",
|
|
23
|
+
\u03BF\u03CB: "oy",
|
|
24
|
+
\u03BF\u03B0: "oy",
|
|
25
|
+
\u039F\u03C5: "Ou",
|
|
26
|
+
\u039F\u03CD: "Ou",
|
|
27
|
+
\u039F\u03CB: "Oy",
|
|
28
|
+
\u039F\u03B0: "Oy",
|
|
29
|
+
\u039F\u03A5: "OY",
|
|
30
|
+
\u0391: "A",
|
|
31
|
+
\u03B1: "a",
|
|
32
|
+
\u03AC: "a",
|
|
33
|
+
\u0386: "A",
|
|
34
|
+
\u0392: "B",
|
|
35
|
+
\u03B2: "b",
|
|
36
|
+
\u0393: "G",
|
|
37
|
+
\u03B3: "g",
|
|
38
|
+
\u0394: "D",
|
|
39
|
+
\u03B4: "d",
|
|
40
|
+
\u0395: "E",
|
|
41
|
+
\u03B5: "e",
|
|
42
|
+
\u03AD: "e",
|
|
43
|
+
\u0388: "E",
|
|
44
|
+
\u0396: "Z",
|
|
45
|
+
\u03B6: "z",
|
|
46
|
+
\u0397: "H",
|
|
47
|
+
\u03B7: "h",
|
|
48
|
+
\u03AE: "h",
|
|
49
|
+
\u0389: "H",
|
|
50
|
+
\u0398: "TH",
|
|
51
|
+
\u03B8: "th",
|
|
52
|
+
\u0399: "I",
|
|
53
|
+
\u03AA: "I",
|
|
54
|
+
\u03B9: "i",
|
|
55
|
+
\u03AF: "i",
|
|
56
|
+
\u0390: "i",
|
|
57
|
+
\u03CA: "i",
|
|
58
|
+
\u038A: "I",
|
|
59
|
+
\u039A: "K",
|
|
60
|
+
\u03BA: "k",
|
|
61
|
+
\u039B: "L",
|
|
62
|
+
\u03BB: "l",
|
|
63
|
+
\u039C: "M",
|
|
64
|
+
\u03BC: "m",
|
|
65
|
+
\u039D: "N",
|
|
66
|
+
\u03BD: "n",
|
|
67
|
+
\u039E: "KS",
|
|
68
|
+
\u03BE: "ks",
|
|
69
|
+
\u039F: "O",
|
|
70
|
+
\u03BF: "o",
|
|
71
|
+
\u038C: "O",
|
|
72
|
+
\u03CC: "o",
|
|
73
|
+
\u03A0: "P",
|
|
74
|
+
\u03C0: "p",
|
|
75
|
+
\u03A1: "R",
|
|
76
|
+
\u03C1: "r",
|
|
77
|
+
\u03A3: "S",
|
|
78
|
+
\u03C3: "s",
|
|
79
|
+
\u03A4: "T",
|
|
80
|
+
\u03C4: "t",
|
|
81
|
+
\u03A5: "Y",
|
|
82
|
+
\u038E: "Y",
|
|
83
|
+
\u03AB: "Y",
|
|
84
|
+
\u03B0: "y",
|
|
85
|
+
\u03CD: "y",
|
|
86
|
+
\u03CB: "y",
|
|
87
|
+
\u03C5: "y",
|
|
88
|
+
\u03A6: "F",
|
|
89
|
+
\u03C6: "f",
|
|
90
|
+
\u03A7: "X",
|
|
91
|
+
\u03C7: "x",
|
|
92
|
+
\u03A8: "Ps",
|
|
93
|
+
\u03C8: "ps",
|
|
94
|
+
\u03A9: "w",
|
|
95
|
+
\u03C9: "w",
|
|
96
|
+
\u038F: "w",
|
|
97
|
+
\u03CE: "w",
|
|
98
|
+
\u03C2: "s",
|
|
99
|
+
";": "?"
|
|
100
|
+
};
|
|
101
|
+
export {
|
|
102
|
+
greekToGreeklishMap
|
|
103
|
+
};
|
|
104
|
+
//# sourceMappingURL=normalization-map.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/search/lang/gr/normalization-map.ts"],
|
|
4
|
+
"sourcesContent": ["export const greekToGreeklishMap = {\n \u0393\u03A7: 'GX',\n \u03B3\u03C7: 'gx',\n \u03A4\u0398: 'T8',\n \u03C4\u03B8: 't8',\n \u03B8\u03B7: '8h',\n \u0398\u03B7: '8h',\n \u0398\u0397: '8H',\n \u03B1\u03C5: 'au',\n \u0391\u03C5: 'Au',\n \u0391\u03A5: 'AY',\n \u03B5\u03C5: 'eu',\n \u03B5\u03CD: 'eu',\n \u03B5\u03CB: 'ey',\n \u03B5\u03B0: 'ey',\n \u0395\u03C5: 'Eu',\n \u0395\u03CD: 'Eu',\n \u0395\u03CB: 'Ey',\n \u0395\u03B0: 'Ey',\n \u0395\u03A5: 'EY',\n \u03BF\u03C5: 'ou',\n \u03BF\u03CD: 'ou',\n \u03BF\u03CB: 'oy',\n \u03BF\u03B0: 'oy',\n \u039F\u03C5: 'Ou',\n \u039F\u03CD: 'Ou',\n \u039F\u03CB: 'Oy',\n \u039F\u03B0: 'Oy',\n \u039F\u03A5: 'OY',\n \u0391: 'A',\n \u03B1: 'a',\n \u03AC: 'a',\n \u0386: 'A',\n \u0392: 'B',\n \u03B2: 'b',\n \u0393: 'G',\n \u03B3: 'g',\n \u0394: 'D',\n \u03B4: 'd',\n \u0395: 'E',\n \u03B5: 'e',\n \u03AD: 'e',\n \u0388: 'E',\n \u0396: 'Z',\n \u03B6: 'z',\n \u0397: 'H',\n \u03B7: 'h',\n \u03AE: 'h',\n \u0389: 'H',\n \u0398: 'TH',\n \u03B8: 'th',\n \u0399: 'I',\n \u03AA: 'I',\n \u03B9: 'i',\n \u03AF: 'i',\n \u0390: 'i',\n \u03CA: 'i',\n \u038A: 'I',\n \u039A: 'K',\n \u03BA: 'k',\n \u039B: 'L',\n \u03BB: 'l',\n \u039C: 'M',\n \u03BC: 'm',\n \u039D: 'N',\n \u03BD: 'n',\n \u039E: 'KS',\n \u03BE: 'ks',\n \u039F: 'O',\n \u03BF: 'o',\n \u038C: 'O',\n \u03CC: 'o',\n \u03A0: 'P',\n \u03C0: 'p',\n \u03A1: 'R',\n \u03C1: 'r',\n \u03A3: 'S',\n \u03C3: 's',\n \u03A4: 'T',\n \u03C4: 't',\n \u03A5: 'Y',\n \u038E: 'Y',\n \u03AB: 'Y',\n \u03B0: 'y',\n \u03CD: 'y',\n \u03CB: 'y',\n \u03C5: 'y',\n \u03A6: 'F',\n \u03C6: 'f',\n \u03A7: 'X',\n \u03C7: 'x',\n \u03A8: 'Ps',\n \u03C8: 'ps',\n \u03A9: 'w',\n \u03C9: 'w',\n \u038F: 'w',\n \u03CE: 'w',\n \u03C2: 's',\n ';': '?',\n};\n"],
|
|
5
|
+
"mappings": "AAAO,MAAM,sBAAsB;AAAA,EACjC,cAAI;AAAA,EACJ,cAAI;AAAA,EACJ,cAAI;AAAA,EACJ,cAAI;AAAA,EACJ,cAAI;AAAA,EACJ,cAAI;AAAA,EACJ,cAAI;AAAA,EACJ,cAAI;AAAA,EACJ,cAAI;AAAA,EACJ,cAAI;AAAA,EACJ,cAAI;AAAA,EACJ,cAAI;AAAA,EACJ,cAAI;AAAA,EACJ,cAAI;AAAA,EACJ,cAAI;AAAA,EACJ,cAAI;AAAA,EACJ,cAAI;AAAA,EACJ,cAAI;AAAA,EACJ,cAAI;AAAA,EACJ,cAAI;AAAA,EACJ,cAAI;AAAA,EACJ,cAAI;AAAA,EACJ,cAAI;AAAA,EACJ,cAAI;AAAA,EACJ,cAAI;AAAA,EACJ,cAAI;AAAA,EACJ,cAAI;AAAA,EACJ,cAAI;AAAA,EACJ,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,QAAG;AAAA,EACH,KAAK;AACP;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,133 +1,82 @@
|
|
|
1
|
-
import
|
|
2
|
-
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
4
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
5
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
6
|
-
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
7
|
-
import { Document } from 'flexsearch';
|
|
1
|
+
import { Document } from "flexsearch";
|
|
8
2
|
import { encodeGreek } from "./lang/gr/encoder";
|
|
9
3
|
import { findItemsByIds, getAllItemKeys, getResultIds } from "./utils";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*
|
|
14
|
-
* @typeParam T - The type of the data that will be indexed
|
|
15
|
-
*/
|
|
16
|
-
export var SearchIndex = /*#__PURE__*/function () {
|
|
17
|
-
function SearchIndex(items, options) {
|
|
18
|
-
var _this = this;
|
|
19
|
-
_classCallCheck(this, SearchIndex);
|
|
20
|
-
/**
|
|
21
|
-
* Instance of the third party library's index
|
|
22
|
-
*/
|
|
23
|
-
this.index = void 0;
|
|
24
|
-
this.idKey = void 0;
|
|
25
|
-
this.idKey = 'id';
|
|
4
|
+
class SearchIndex {
|
|
5
|
+
constructor(items, options) {
|
|
6
|
+
this.idKey = "id";
|
|
26
7
|
if (options && options.idKey) {
|
|
27
|
-
this.idKey = options.idKey.replace(
|
|
28
|
-
} else if (!(items[0] &&
|
|
29
|
-
items = items.map(
|
|
30
|
-
return _extends({}, item, {
|
|
31
|
-
id: index
|
|
32
|
-
});
|
|
33
|
-
});
|
|
8
|
+
this.idKey = options.idKey.replace(".", ":");
|
|
9
|
+
} else if (!(items[0] && "id" in items[0])) {
|
|
10
|
+
items = items.map((item, index) => ({ ...item, id: index }));
|
|
34
11
|
}
|
|
35
|
-
|
|
12
|
+
let fields = [];
|
|
36
13
|
if (options && options.fields) {
|
|
37
14
|
fields = options.fields;
|
|
38
15
|
} else if (items[0]) {
|
|
39
16
|
fields = getAllItemKeys(items[0]);
|
|
40
17
|
}
|
|
41
|
-
fields = fields.filter(
|
|
42
|
-
return field !== _this.idKey;
|
|
43
|
-
}).map(function (field) {
|
|
44
|
-
return field.replace('.', ':');
|
|
45
|
-
});
|
|
18
|
+
fields = fields.filter((field) => field !== this.idKey).map((field) => field.replace(".", ":"));
|
|
46
19
|
this.index = new Document({
|
|
47
20
|
document: {
|
|
48
21
|
id: this.idKey,
|
|
49
22
|
index: fields
|
|
50
23
|
},
|
|
51
|
-
tokenize:
|
|
52
|
-
worker: options
|
|
24
|
+
tokenize: "forward",
|
|
25
|
+
worker: options?.enableWorker,
|
|
53
26
|
encode: encodeGreek
|
|
54
27
|
});
|
|
55
28
|
this.addAll(items);
|
|
56
29
|
}
|
|
57
|
-
|
|
58
30
|
/**
|
|
59
31
|
* Add an item to the index
|
|
60
32
|
*
|
|
61
33
|
* @param item - The item to add to the index
|
|
62
34
|
*/
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
var _this3 = this;
|
|
112
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
113
|
-
while (1) switch (_context.prev = _context.next) {
|
|
114
|
-
case 0:
|
|
115
|
-
return _context.abrupt("return", this.index.searchAsync(searchTerm).then(function (res) {
|
|
116
|
-
return getResultIds(res);
|
|
117
|
-
}).then(function (res) {
|
|
118
|
-
return findItemsByIds(documents, res, _this3.idKey);
|
|
119
|
-
}));
|
|
120
|
-
case 1:
|
|
121
|
-
case "end":
|
|
122
|
-
return _context.stop();
|
|
123
|
-
}
|
|
124
|
-
}, _callee, this);
|
|
125
|
-
}));
|
|
126
|
-
function searchAsync(_x, _x2) {
|
|
127
|
-
return _searchAsync.apply(this, arguments);
|
|
128
|
-
}
|
|
129
|
-
return searchAsync;
|
|
130
|
-
}())
|
|
131
|
-
}]);
|
|
132
|
-
return SearchIndex;
|
|
133
|
-
}();
|
|
35
|
+
add(item) {
|
|
36
|
+
this.index.add(item);
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Add multiple items to the index
|
|
41
|
+
*
|
|
42
|
+
* @param items - The list of items to add to the index
|
|
43
|
+
*/
|
|
44
|
+
addAll(items) {
|
|
45
|
+
items.forEach((item) => this.index.add(item));
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Search the index for the given term
|
|
50
|
+
*
|
|
51
|
+
* @param documents - The list of documents to search
|
|
52
|
+
* @param searchTerm - The term to search for
|
|
53
|
+
* @returns The list of items that match the search term
|
|
54
|
+
*/
|
|
55
|
+
search(documents, searchTerm) {
|
|
56
|
+
const res = this.index.search(searchTerm);
|
|
57
|
+
const ids = getResultIds(res);
|
|
58
|
+
return findItemsByIds(
|
|
59
|
+
documents,
|
|
60
|
+
ids,
|
|
61
|
+
this.idKey
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Asynchronously search the index for the given term
|
|
66
|
+
*
|
|
67
|
+
* @param documents - The list of documents to search
|
|
68
|
+
* @param searchTerm - The term to search for
|
|
69
|
+
* @returns The list of items that match the search term
|
|
70
|
+
*/
|
|
71
|
+
async searchAsync(documents, searchTerm) {
|
|
72
|
+
return this.index.searchAsync(searchTerm).then((res) => {
|
|
73
|
+
return getResultIds(res);
|
|
74
|
+
}).then(
|
|
75
|
+
(res) => findItemsByIds(documents, res, this.idKey)
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export {
|
|
80
|
+
SearchIndex
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=search-index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/search/search-index.ts"],
|
|
4
|
+
"sourcesContent": ["import { Document } from 'flexsearch';\nimport type { SearchIndexOptions } from '../types';\nimport { encodeGreek } from './lang/gr/encoder';\nimport { findItemsByIds, getAllItemKeys, getResultIds } from './utils';\n\n/**\n * Wrapper class around third party index and search library\n *\n * @typeParam T - The type of the data that will be indexed\n */\nexport class SearchIndex<T extends Record<string, any>> {\n /**\n * Instance of the third party library's index\n */\n private index: Document<T>;\n private idKey: string;\n\n constructor(items: T[], options?: SearchIndexOptions<T>) {\n this.idKey = 'id';\n if (options && options.idKey) {\n this.idKey = options.idKey.replace('.', ':');\n } else if (!(items[0] && 'id' in items[0])) {\n items = items.map((item, index) => ({ ...item, id: index }));\n }\n\n let fields: string[] = [];\n if (options && options.fields) {\n fields = options.fields;\n } else if (items[0]) {\n fields = getAllItemKeys(items[0]);\n }\n fields = fields\n .filter((field) => field !== this.idKey)\n .map((field) => field.replace('.', ':'));\n\n this.index = new Document<T>({\n document: {\n id: this.idKey,\n index: fields,\n },\n tokenize: 'forward',\n worker: options?.enableWorker,\n encode: encodeGreek,\n });\n\n this.addAll(items);\n }\n\n /**\n * Add an item to the index\n *\n * @param item - The item to add to the index\n */\n public add(item: T) {\n this.index.add(item);\n return this;\n }\n\n /**\n * Add multiple items to the index\n *\n * @param items - The list of items to add to the index\n */\n public addAll(items: T[]) {\n items.forEach((item) => this.index.add(item));\n return this;\n }\n\n /**\n * Search the index for the given term\n *\n * @param documents - The list of documents to search\n * @param searchTerm - The term to search for\n * @returns The list of items that match the search term\n */\n public search(documents: T[], searchTerm: string) {\n const res = this.index.search(searchTerm);\n const ids = getResultIds(res);\n return findItemsByIds(\n documents,\n ids,\n this.idKey as Extract<keyof T, string>\n );\n }\n\n /**\n * Asynchronously search the index for the given term\n *\n * @param documents - The list of documents to search\n * @param searchTerm - The term to search for\n * @returns The list of items that match the search term\n */\n public async searchAsync(documents: T[], searchTerm: string) {\n return this.index\n .searchAsync(searchTerm)\n .then((res) => {\n return getResultIds(res);\n })\n .then((res) =>\n findItemsByIds(documents, res, this.idKey as Extract<keyof T, string>)\n );\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,gBAAgB;AAEzB,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB,gBAAgB,oBAAoB;AAOtD,MAAM,YAA2C;AAAA,EAOtD,YAAY,OAAY,SAAiC;AACvD,SAAK,QAAQ;AACb,QAAI,WAAW,QAAQ,OAAO;AAC5B,WAAK,QAAQ,QAAQ,MAAM,QAAQ,KAAK,GAAG;AAAA,IAC7C,WAAW,EAAE,MAAM,CAAC,KAAK,QAAQ,MAAM,CAAC,IAAI;AAC1C,cAAQ,MAAM,IAAI,CAAC,MAAM,WAAW,EAAE,GAAG,MAAM,IAAI,MAAM,EAAE;AAAA,IAC7D;AAEA,QAAI,SAAmB,CAAC;AACxB,QAAI,WAAW,QAAQ,QAAQ;AAC7B,eAAS,QAAQ;AAAA,IACnB,WAAW,MAAM,CAAC,GAAG;AACnB,eAAS,eAAe,MAAM,CAAC,CAAC;AAAA,IAClC;AACA,aAAS,OACN,OAAO,CAAC,UAAU,UAAU,KAAK,KAAK,EACtC,IAAI,CAAC,UAAU,MAAM,QAAQ,KAAK,GAAG,CAAC;AAEzC,SAAK,QAAQ,IAAI,SAAY;AAAA,MAC3B,UAAU;AAAA,QACR,IAAI,KAAK;AAAA,QACT,OAAO;AAAA,MACT;AAAA,MACA,UAAU;AAAA,MACV,QAAQ,SAAS;AAAA,MACjB,QAAQ;AAAA,IACV,CAAC;AAED,SAAK,OAAO,KAAK;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,IAAI,MAAS;AAClB,SAAK,MAAM,IAAI,IAAI;AACnB,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,OAAO,OAAY;AACxB,UAAM,QAAQ,CAAC,SAAS,KAAK,MAAM,IAAI,IAAI,CAAC;AAC5C,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,OAAO,WAAgB,YAAoB;AAChD,UAAM,MAAM,KAAK,MAAM,OAAO,UAAU;AACxC,UAAM,MAAM,aAAa,GAAG;AAC5B,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA,KAAK;AAAA,IACP;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAa,YAAY,WAAgB,YAAoB;AAC3D,WAAO,KAAK,MACT,YAAY,UAAU,EACtB,KAAK,CAAC,QAAQ;AACb,aAAO,aAAa,GAAG;AAAA,IACzB,CAAC,EACA;AAAA,MAAK,CAAC,QACL,eAAe,WAAW,KAAK,KAAK,KAAiC;AAAA,IACvE;AAAA,EACJ;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/search/utils/index.js
CHANGED
|
@@ -1,70 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Extracts the unique item IDs from the result set
|
|
7
|
-
*
|
|
8
|
-
* @param result - The result set to extract the IDs from
|
|
9
|
-
*/
|
|
10
|
-
export function getResultIds(result) {
|
|
11
|
-
var set = new Set();
|
|
12
|
-
result.forEach(function (item) {
|
|
13
|
-
item.result.forEach(function (id) {
|
|
14
|
-
return set.add(id);
|
|
15
|
-
});
|
|
1
|
+
function getResultIds(result) {
|
|
2
|
+
const set = /* @__PURE__ */ new Set();
|
|
3
|
+
result.forEach((item) => {
|
|
4
|
+
item.result.forEach((id) => set.add(id));
|
|
16
5
|
});
|
|
17
6
|
return Array.from(set);
|
|
18
7
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
* @param items - The list of items to search through
|
|
24
|
-
* @param ids - The list of IDs to search for
|
|
25
|
-
* @param idKey - The key to use to find the IDs in the items
|
|
26
|
-
*/
|
|
27
|
-
export function findItemsByIds(items, ids, idKey) {
|
|
28
|
-
return items.filter(function (item) {
|
|
29
|
-
return item && ids.includes(getValueFromNestedKey(item, idKey));
|
|
30
|
-
});
|
|
8
|
+
function findItemsByIds(items, ids, idKey) {
|
|
9
|
+
return items.filter(
|
|
10
|
+
(item) => item && ids.includes(getValueFromNestedKey(item, idKey))
|
|
11
|
+
);
|
|
31
12
|
}
|
|
32
13
|
function getValueFromNestedKey(object, nestedKey) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
39
|
-
var keySegment = _step.value;
|
|
40
|
-
if (result.hasOwnProperty(keySegment)) {
|
|
41
|
-
result = result[keySegment];
|
|
42
|
-
}
|
|
14
|
+
const keys = nestedKey.split(":");
|
|
15
|
+
let result = object;
|
|
16
|
+
for (const keySegment of keys) {
|
|
17
|
+
if (result.hasOwnProperty(keySegment)) {
|
|
18
|
+
result = result[keySegment];
|
|
43
19
|
}
|
|
44
|
-
} catch (err) {
|
|
45
|
-
_iterator.e(err);
|
|
46
|
-
} finally {
|
|
47
|
-
_iterator.f();
|
|
48
20
|
}
|
|
49
21
|
return result;
|
|
50
22
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
*
|
|
55
|
-
* The keys are returned in the format `parentKey.childKey` for nested objects
|
|
56
|
-
* and `key` for top level objects (objects that are not nested inside another object).
|
|
57
|
-
*
|
|
58
|
-
* @param object - The item to get the keys from
|
|
59
|
-
* @param parentKey - The parent key to which the current key should be appended
|
|
60
|
-
*/
|
|
61
|
-
export function getAllItemKeys(object) {
|
|
62
|
-
var parentKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
63
|
-
var keys = [];
|
|
64
|
-
for (var key in object) {
|
|
23
|
+
function getAllItemKeys(object, parentKey = "") {
|
|
24
|
+
let keys = [];
|
|
25
|
+
for (const key in object) {
|
|
65
26
|
if (object.hasOwnProperty(key)) {
|
|
66
|
-
|
|
67
|
-
if (
|
|
27
|
+
const currentKey = parentKey ? `${parentKey}.${key}` : key;
|
|
28
|
+
if (typeof object[key] === "object" && object[key] !== null) {
|
|
68
29
|
keys = keys.concat(getAllItemKeys(object[key], currentKey));
|
|
69
30
|
} else {
|
|
70
31
|
keys.push(currentKey);
|
|
@@ -72,4 +33,10 @@ export function getAllItemKeys(object) {
|
|
|
72
33
|
}
|
|
73
34
|
}
|
|
74
35
|
return keys;
|
|
75
|
-
}
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
findItemsByIds,
|
|
39
|
+
getAllItemKeys,
|
|
40
|
+
getResultIds
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/search/utils.ts"],
|
|
4
|
+
"sourcesContent": ["import { SimpleDocumentSearchResultSetUnit } from 'flexsearch';\n\n/**\n * Extracts the unique item IDs from the result set\n *\n * @param result - The result set to extract the IDs from\n */\nexport function getResultIds(result: SimpleDocumentSearchResultSetUnit[]) {\n const set = new Set<number | string>();\n result.forEach((item) => {\n item.result.forEach((id) => set.add(id));\n });\n return Array.from(set);\n}\n\n/**\n * Get the items from the list that match the given IDs\n *\n * @param items - The list of items to search through\n * @param ids - The list of IDs to search for\n * @param idKey - The key to use to find the IDs in the items\n */\nexport function findItemsByIds<T extends Record<string, any>>(\n items: T[],\n ids: (string | number)[],\n idKey: Extract<keyof T, string>\n) {\n return items.filter(\n (item) => item && ids.includes(getValueFromNestedKey(item, idKey))\n );\n}\n\nfunction getValueFromNestedKey(object: Record<string, any>, nestedKey: string) {\n const keys = nestedKey.split(':');\n\n let result = object;\n for (const keySegment of keys) {\n if (result.hasOwnProperty(keySegment)) {\n result = result[keySegment];\n }\n }\n return (result as unknown) as string;\n}\n\n/**\n * Recursively get all the keys from an object\n *\n * The keys are returned in the format `parentKey.childKey` for nested objects\n * and `key` for top level objects (objects that are not nested inside another object).\n *\n * @param object - The item to get the keys from\n * @param parentKey - The parent key to which the current key should be appended\n */\nexport function getAllItemKeys(\n object: Record<string, any>,\n parentKey: string = ''\n): string[] {\n let keys: string[] = [];\n for (const key in object) {\n if (object.hasOwnProperty(key)) {\n const currentKey = parentKey ? `${parentKey}.${key}` : key;\n\n if (typeof object[key] === 'object' && object[key] !== null) {\n keys = keys.concat(getAllItemKeys(object[key], currentKey));\n } else {\n keys.push(currentKey);\n }\n }\n }\n\n return keys;\n}\n"],
|
|
5
|
+
"mappings": "AAOO,SAAS,aAAa,QAA6C;AACxE,QAAM,MAAM,oBAAI,IAAqB;AACrC,SAAO,QAAQ,CAAC,SAAS;AACvB,SAAK,OAAO,QAAQ,CAAC,OAAO,IAAI,IAAI,EAAE,CAAC;AAAA,EACzC,CAAC;AACD,SAAO,MAAM,KAAK,GAAG;AACvB;AASO,SAAS,eACd,OACA,KACA,OACA;AACA,SAAO,MAAM;AAAA,IACX,CAAC,SAAS,QAAQ,IAAI,SAAS,sBAAsB,MAAM,KAAK,CAAC;AAAA,EACnE;AACF;AAEA,SAAS,sBAAsB,QAA6B,WAAmB;AAC7E,QAAM,OAAO,UAAU,MAAM,GAAG;AAEhC,MAAI,SAAS;AACb,aAAW,cAAc,MAAM;AAC7B,QAAI,OAAO,eAAe,UAAU,GAAG;AACrC,eAAS,OAAO,UAAU;AAAA,IAC5B;AAAA,EACF;AACA,SAAQ;AACV;AAWO,SAAS,eACd,QACA,YAAoB,IACV;AACV,MAAI,OAAiB,CAAC;AACtB,aAAW,OAAO,QAAQ;AACxB,QAAI,OAAO,eAAe,GAAG,GAAG;AAC9B,YAAM,aAAa,YAAY,GAAG,SAAS,IAAI,GAAG,KAAK;AAEvD,UAAI,OAAO,OAAO,GAAG,MAAM,YAAY,OAAO,GAAG,MAAM,MAAM;AAC3D,eAAO,KAAK,OAAO,eAAe,OAAO,GAAG,GAAG,UAAU,CAAC;AAAA,MAC5D,OAAO;AACL,aAAK,KAAK,UAAU;AAAA,MACtB;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|