Commit 8e55cae
committed
feat(token-search): add customizable tokenizer with unicode-aware default
Token search previously hardcoded /\b\w+\b/g, which (a) split tokens with
internal punctuation like node.js, c++, U.S.A apart, and (b) produced
empty token lists for non-Latin scripts (CJK, Devanagari, Hebrew, etc.) —
making token search effectively unavailable to East Asian users.
Two changes:
1. New `tokenize` option accepting either RegExp or (text) => string[].
The function form lets users plug in Intl.Segmenter for word-level
CJK segmentation. Function-form tokenizers are rejected by FuseWorker
(cannot cross postMessage); regex-form passes through cleanly.
2. Default tokenizer changes from /\b\w+\b/g to /[\p{L}\p{M}\p{N}_]+/gu.
The new default handles unicode letter, mark, and number runs out of
the box — so CJK is indexed (was empty before) and combining marks
on Devanagari, vowelized Hebrew/Arabic, NFD-normalized Latin stay
attached to their base letter. Latin behavior is unchanged for ASCII
alphanumerics + underscore.
This is a behavior change for corpora containing characters outside
[A-Za-z0-9_]; score distributions may differ. Targeted for 7.5.0 minor.
Closes #8211 parent ebde7cb commit 8e55cae
23 files changed
Lines changed: 618 additions & 41 deletions
File tree
- dist
- docs
- src
- core
- search/token
- workers
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
53 | 56 | | |
54 | 57 | | |
55 | 58 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
50 | 53 | | |
51 | 54 | | |
52 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
| 206 | + | |
206 | 207 | | |
207 | 208 | | |
208 | 209 | | |
| |||
1023 | 1024 | | |
1024 | 1025 | | |
1025 | 1026 | | |
1026 | | - | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
1027 | 1058 | | |
1028 | 1059 | | |
1029 | | - | |
| 1060 | + | |
| 1061 | + | |
1030 | 1062 | | |
| 1063 | + | |
1031 | 1064 | | |
1032 | 1065 | | |
1033 | 1066 | | |
| |||
1036 | 1069 | | |
1037 | 1070 | | |
1038 | 1071 | | |
1039 | | - | |
| 1072 | + | |
1040 | 1073 | | |
1041 | 1074 | | |
1042 | 1075 | | |
| |||
1211 | 1244 | | |
1212 | 1245 | | |
1213 | 1246 | | |
1214 | | - | |
| 1247 | + | |
| 1248 | + | |
1215 | 1249 | | |
1216 | 1250 | | |
1217 | 1251 | | |
| |||
1227 | 1261 | | |
1228 | 1262 | | |
1229 | 1263 | | |
1230 | | - | |
| 1264 | + | |
| 1265 | + | |
1231 | 1266 | | |
1232 | 1267 | | |
1233 | 1268 | | |
| |||
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
| 204 | + | |
204 | 205 | | |
205 | 206 | | |
206 | 207 | | |
| |||
1021 | 1022 | | |
1022 | 1023 | | |
1023 | 1024 | | |
1024 | | - | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
1025 | 1056 | | |
1026 | 1057 | | |
1027 | | - | |
| 1058 | + | |
| 1059 | + | |
1028 | 1060 | | |
| 1061 | + | |
1029 | 1062 | | |
1030 | 1063 | | |
1031 | 1064 | | |
| |||
1034 | 1067 | | |
1035 | 1068 | | |
1036 | 1069 | | |
1037 | | - | |
| 1070 | + | |
1038 | 1071 | | |
1039 | 1072 | | |
1040 | 1073 | | |
| |||
1209 | 1242 | | |
1210 | 1243 | | |
1211 | 1244 | | |
1212 | | - | |
| 1245 | + | |
| 1246 | + | |
1213 | 1247 | | |
1214 | 1248 | | |
1215 | 1249 | | |
| |||
1225 | 1259 | | |
1226 | 1260 | | |
1227 | 1261 | | |
1228 | | - | |
| 1262 | + | |
| 1263 | + | |
1229 | 1264 | | |
1230 | 1265 | | |
1231 | 1266 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
| 203 | + | |
203 | 204 | | |
204 | 205 | | |
205 | 206 | | |
| |||
1418 | 1419 | | |
1419 | 1420 | | |
1420 | 1421 | | |
1421 | | - | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
| 1441 | + | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
1422 | 1453 | | |
1423 | 1454 | | |
1424 | | - | |
| 1455 | + | |
| 1456 | + | |
1425 | 1457 | | |
| 1458 | + | |
1426 | 1459 | | |
1427 | 1460 | | |
1428 | 1461 | | |
| |||
1431 | 1464 | | |
1432 | 1465 | | |
1433 | 1466 | | |
1434 | | - | |
| 1467 | + | |
1435 | 1468 | | |
1436 | 1469 | | |
1437 | 1470 | | |
| |||
1602 | 1635 | | |
1603 | 1636 | | |
1604 | 1637 | | |
1605 | | - | |
| 1638 | + | |
| 1639 | + | |
1606 | 1640 | | |
1607 | 1641 | | |
1608 | 1642 | | |
| |||
1618 | 1652 | | |
1619 | 1653 | | |
1620 | 1654 | | |
1621 | | - | |
| 1655 | + | |
| 1656 | + | |
1622 | 1657 | | |
1623 | 1658 | | |
1624 | 1659 | | |
| |||
1990 | 2025 | | |
1991 | 2026 | | |
1992 | 2027 | | |
1993 | | - | |
| 2028 | + | |
| 2029 | + | |
1994 | 2030 | | |
1995 | 2031 | | |
1996 | 2032 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
28 | 35 | | |
29 | 36 | | |
30 | 37 | | |
| |||
142 | 149 | | |
143 | 150 | | |
144 | 151 | | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
145 | 161 | | |
146 | 162 | | |
147 | 163 | | |
| |||
289 | 305 | | |
290 | 306 | | |
291 | 307 | | |
292 | | - | |
| 308 | + | |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
0 commit comments