@aspan-corporation/ac-shared 1.2.36 → 1.2.37
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/lib/utils/diary.d.ts +8 -0
- package/lib/utils/diary.js +12 -3
- package/package.json +1 -1
package/lib/utils/diary.d.ts
CHANGED
|
@@ -49,6 +49,14 @@ export declare const parseDiaryKeyDate: (key: string) => {
|
|
|
49
49
|
* words. Strips markdown syntax (code fences, image/link targets, formatting),
|
|
50
50
|
* drops stop-words and tokens shorter than 2 chars, and caps the result at
|
|
51
51
|
* `MAX_TEXT_TOKENS` to bound the meta-item size. No stemming (exact-word match).
|
|
52
|
+
*
|
|
53
|
+
* Word boundaries and lowercasing are Unicode-aware: tokens are split on any
|
|
54
|
+
* run of characters that are neither a Unicode letter (`\p{L}`) nor number
|
|
55
|
+
* (`\p{N}`), so non-Latin scripts (e.g. Cyrillic) survive as searchable words
|
|
56
|
+
* rather than being discarded. `toLowerCase()` is likewise Unicode-aware; we
|
|
57
|
+
* deliberately avoid `toLocaleLowerCase()` so tokenisation is deterministic and
|
|
58
|
+
* independent of the host locale (the indexer lambda and the browser that
|
|
59
|
+
* builds search queries must produce identical tokens).
|
|
52
60
|
*/
|
|
53
61
|
export declare const tokenizeText: (markdown: string) => string[];
|
|
54
62
|
/** Plain-text preview: strip markdown, collapse whitespace, truncate. */
|
package/lib/utils/diary.js
CHANGED
|
@@ -91,6 +91,14 @@ const STOP_WORDS = new Set([
|
|
|
91
91
|
* words. Strips markdown syntax (code fences, image/link targets, formatting),
|
|
92
92
|
* drops stop-words and tokens shorter than 2 chars, and caps the result at
|
|
93
93
|
* `MAX_TEXT_TOKENS` to bound the meta-item size. No stemming (exact-word match).
|
|
94
|
+
*
|
|
95
|
+
* Word boundaries and lowercasing are Unicode-aware: tokens are split on any
|
|
96
|
+
* run of characters that are neither a Unicode letter (`\p{L}`) nor number
|
|
97
|
+
* (`\p{N}`), so non-Latin scripts (e.g. Cyrillic) survive as searchable words
|
|
98
|
+
* rather than being discarded. `toLowerCase()` is likewise Unicode-aware; we
|
|
99
|
+
* deliberately avoid `toLocaleLowerCase()` so tokenisation is deterministic and
|
|
100
|
+
* independent of the host locale (the indexer lambda and the browser that
|
|
101
|
+
* builds search queries must produce identical tokens).
|
|
94
102
|
*/
|
|
95
103
|
export const tokenizeText = (markdown) => {
|
|
96
104
|
if (!markdown)
|
|
@@ -109,11 +117,12 @@ export const tokenizeText = (markdown) => {
|
|
|
109
117
|
// leftover markdown punctuation
|
|
110
118
|
.replace(/[#>*_~\-]+/g, " ");
|
|
111
119
|
const seen = new Set();
|
|
112
|
-
for (const raw of stripped.toLowerCase().split(/[
|
|
120
|
+
for (const raw of stripped.toLowerCase().split(/[^\p{L}\p{N}]+/u)) {
|
|
113
121
|
if (raw.length < 2)
|
|
114
122
|
continue;
|
|
115
|
-
// Drop pure
|
|
116
|
-
|
|
123
|
+
// Drop pure-number tokens (dates/counts add noise) in any script; keep
|
|
124
|
+
// alphanumerics like "v2".
|
|
125
|
+
if (/^\p{N}+$/u.test(raw))
|
|
117
126
|
continue;
|
|
118
127
|
if (STOP_WORDS.has(raw))
|
|
119
128
|
continue;
|