@atscript/db-mysql 0.1.172 → 0.1.174

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/dist/index.cjs CHANGED
@@ -634,6 +634,72 @@ function buildWhere(filter, opts) {
634
634
  return (0, _atscript_db_sql_tools.buildWhere)(mysqlDialect, filter, opts);
635
635
  }
636
636
  //#endregion
637
+ //#region src/innodb-word-chars.ts
638
+ /** A regular-expression character class of InnoDB's word characters (`u` flag). */
639
+ const INNODB_WORD_CLASS = [
640
+ "[",
641
+ "\\u0030-\\u0039\\u0041-\\u005A\\u005F\\u0061-\\u007A\\u00AA\\u00B2\\u00B3\\u00B5\\u00B9\\u00BA",
642
+ "\\u00BC-\\u00BE\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02C1\\u02C6-\\u02D1\\u02E0-\\u02E4\\u02EE",
643
+ "\\u0300-\\u036F\\u037A-\\u037D\\u0386\\u0388-\\u038A\\u038C\\u038E-\\u03A1\\u03A3-\\u03CE",
644
+ "\\u03D0-\\u03F5\\u03F7-\\u0481\\u0483-\\u0486\\u0488-\\u0513\\u0531-\\u0556\\u0559\\u0561-\\u0587",
645
+ "\\u0591-\\u05BD\\u05BF\\u05C1\\u05C2\\u05C4\\u05C5\\u05C7\\u05D0-\\u05EA\\u05F0-\\u05F2",
646
+ "\\u0610-\\u0615\\u0621-\\u063A\\u0640-\\u065E\\u0660-\\u0669\\u066E-\\u06D3\\u06D5-\\u06DC",
647
+ "\\u06DE-\\u06E8\\u06EA-\\u06FC\\u06FF\\u0710-\\u074A\\u074D-\\u076D\\u0780-\\u07B1\\u07C0-\\u07F5",
648
+ "\\u07FA\\u0901-\\u0939\\u093C-\\u094D\\u0950-\\u0954\\u0958-\\u0963\\u0966-\\u096F\\u097B-\\u097F",
649
+ "\\u0981-\\u0983\\u0985-\\u098C\\u098F\\u0990\\u0993-\\u09A8\\u09AA-\\u09B0\\u09B2\\u09B6-\\u09B9",
650
+ "\\u09BC-\\u09C4\\u09C7\\u09C8\\u09CB-\\u09CE\\u09D7\\u09DC\\u09DD\\u09DF-\\u09E3\\u09E6-\\u09F1",
651
+ "\\u09F4-\\u09F9\\u0A01-\\u0A03\\u0A05-\\u0A0A\\u0A0F\\u0A10\\u0A13-\\u0A28\\u0A2A-\\u0A30",
652
+ "\\u0A32\\u0A33\\u0A35\\u0A36\\u0A38\\u0A39\\u0A3C\\u0A3E-\\u0A42\\u0A47\\u0A48\\u0A4B-\\u0A4D",
653
+ "\\u0A59-\\u0A5C\\u0A5E\\u0A66-\\u0A74\\u0A81-\\u0A83\\u0A85-\\u0A8D\\u0A8F-\\u0A91\\u0A93-\\u0AA8",
654
+ "\\u0AAA-\\u0AB0\\u0AB2\\u0AB3\\u0AB5-\\u0AB9\\u0ABC-\\u0AC5\\u0AC7-\\u0AC9\\u0ACB-\\u0ACD\\u0AD0",
655
+ "\\u0AE0-\\u0AE3\\u0AE6-\\u0AEF\\u0B01-\\u0B03\\u0B05-\\u0B0C\\u0B0F\\u0B10\\u0B13-\\u0B28",
656
+ "\\u0B2A-\\u0B30\\u0B32\\u0B33\\u0B35-\\u0B39\\u0B3C-\\u0B43\\u0B47\\u0B48\\u0B4B-\\u0B4D",
657
+ "\\u0B56\\u0B57\\u0B5C\\u0B5D\\u0B5F-\\u0B61\\u0B66-\\u0B6F\\u0B71\\u0B82\\u0B83\\u0B85-\\u0B8A",
658
+ "\\u0B8E-\\u0B90\\u0B92-\\u0B95\\u0B99\\u0B9A\\u0B9C\\u0B9E\\u0B9F\\u0BA3\\u0BA4\\u0BA8-\\u0BAA",
659
+ "\\u0BAE-\\u0BB9\\u0BBE-\\u0BC2\\u0BC6-\\u0BC8\\u0BCA-\\u0BCD\\u0BD7\\u0BE6-\\u0BF2\\u0C01-\\u0C03",
660
+ "\\u0C05-\\u0C0C\\u0C0E-\\u0C10\\u0C12-\\u0C28\\u0C2A-\\u0C33\\u0C35-\\u0C39\\u0C3E-\\u0C44",
661
+ "\\u0C46-\\u0C48\\u0C4A-\\u0C4D\\u0C55\\u0C56\\u0C60\\u0C61\\u0C66-\\u0C6F\\u0C82\\u0C83",
662
+ "\\u0C85-\\u0C8C\\u0C8E-\\u0C90\\u0C92-\\u0CA8\\u0CAA-\\u0CB3\\u0CB5-\\u0CB9\\u0CBC-\\u0CC4",
663
+ "\\u0CC6-\\u0CC8\\u0CCA-\\u0CCD\\u0CD5\\u0CD6\\u0CDE\\u0CE0-\\u0CE3\\u0CE6-\\u0CEF\\u0D02\\u0D03",
664
+ "\\u0D05-\\u0D0C\\u0D0E-\\u0D10\\u0D12-\\u0D28\\u0D2A-\\u0D39\\u0D3E-\\u0D43\\u0D46-\\u0D48",
665
+ "\\u0D4A-\\u0D4D\\u0D57\\u0D60\\u0D61\\u0D66-\\u0D6F\\u0D82\\u0D83\\u0D85-\\u0D96\\u0D9A-\\u0DB1",
666
+ "\\u0DB3-\\u0DBB\\u0DBD\\u0DC0-\\u0DC6\\u0DCA\\u0DCF-\\u0DD4\\u0DD6\\u0DD8-\\u0DDF\\u0DF2\\u0DF3",
667
+ "\\u0E01-\\u0E3A\\u0E40-\\u0E4E\\u0E50-\\u0E59\\u0E81\\u0E82\\u0E84\\u0E87\\u0E88\\u0E8A\\u0E8D",
668
+ "\\u0E94-\\u0E97\\u0E99-\\u0E9F\\u0EA1-\\u0EA3\\u0EA5\\u0EA7\\u0EAA\\u0EAB\\u0EAD-\\u0EB9",
669
+ "\\u0EBB-\\u0EBD\\u0EC0-\\u0EC4\\u0EC6\\u0EC8-\\u0ECD\\u0ED0-\\u0ED9\\u0EDC\\u0EDD\\u0F00",
670
+ "\\u0F18\\u0F19\\u0F20-\\u0F33\\u0F35\\u0F37\\u0F39\\u0F3E-\\u0F47\\u0F49-\\u0F6A\\u0F71-\\u0F84",
671
+ "\\u0F86-\\u0F8B\\u0F90-\\u0F97\\u0F99-\\u0FBC\\u0FC6\\u1000-\\u1021\\u1023-\\u1027\\u1029\\u102A",
672
+ "\\u102C-\\u1032\\u1036-\\u1039\\u1040-\\u1049\\u1050-\\u1059\\u10A0-\\u10C5\\u10D0-\\u10FA\\u10FC",
673
+ "\\u1100-\\u1159\\u115F-\\u11A2\\u11A8-\\u11F9\\u1200-\\u1248\\u124A-\\u124D\\u1250-\\u1256\\u1258",
674
+ "\\u125A-\\u125D\\u1260-\\u1288\\u128A-\\u128D\\u1290-\\u12B0\\u12B2-\\u12B5\\u12B8-\\u12BE\\u12C0",
675
+ "\\u12C2-\\u12C5\\u12C8-\\u12D6\\u12D8-\\u1310\\u1312-\\u1315\\u1318-\\u135A\\u135F\\u1369-\\u137C",
676
+ "\\u1380-\\u138F\\u13A0-\\u13F4\\u1401-\\u166C\\u166F-\\u1676\\u1681-\\u169A\\u16A0-\\u16EA",
677
+ "\\u16EE-\\u16F0\\u1700-\\u170C\\u170E-\\u1714\\u1720-\\u1734\\u1740-\\u1753\\u1760-\\u176C",
678
+ "\\u176E-\\u1770\\u1772\\u1773\\u1780-\\u17B3\\u17B6-\\u17D3\\u17D7\\u17DC\\u17DD\\u17E0-\\u17E9",
679
+ "\\u17F0-\\u17F9\\u180B-\\u180D\\u1810-\\u1819\\u1820-\\u1877\\u1880-\\u18A9\\u1900-\\u191C",
680
+ "\\u1920-\\u192B\\u1930-\\u193B\\u1946-\\u196D\\u1970-\\u1974\\u1980-\\u19A9\\u19B0-\\u19C9",
681
+ "\\u19D0-\\u19D9\\u1A00-\\u1A1B\\u1B00-\\u1B4B\\u1B50-\\u1B59\\u1B6B-\\u1B73\\u1D00-\\u1DCA",
682
+ "\\u1DFE-\\u1E9B\\u1EA0-\\u1EF9\\u1F00-\\u1F15\\u1F18-\\u1F1D\\u1F20-\\u1F45\\u1F48-\\u1F4D",
683
+ "\\u1F50-\\u1F57\\u1F59\\u1F5B\\u1F5D\\u1F5F-\\u1F7D\\u1F80-\\u1FB4\\u1FB6-\\u1FBC\\u1FBE",
684
+ "\\u1FC2-\\u1FC4\\u1FC6-\\u1FCC\\u1FD0-\\u1FD3\\u1FD6-\\u1FDB\\u1FE0-\\u1FEC\\u1FF2-\\u1FF4",
685
+ "\\u1FF6-\\u1FFC\\u2070\\u2071\\u2074-\\u2079\\u207F-\\u2089\\u2090-\\u2094\\u20D0-\\u20EF\\u2102",
686
+ "\\u2107\\u210A-\\u2113\\u2115\\u2119-\\u211D\\u2124\\u2126\\u2128\\u212A-\\u212D\\u212F-\\u2139",
687
+ "\\u213C-\\u213F\\u2145-\\u2149\\u214E\\u2153-\\u2184\\u2460-\\u249B\\u24EA-\\u24FF\\u2776-\\u2793",
688
+ "\\u2C00-\\u2C2E\\u2C30-\\u2C5E\\u2C60-\\u2C6C\\u2C74-\\u2C77\\u2C80-\\u2CE4\\u2CFD\\u2D00-\\u2D25",
689
+ "\\u2D30-\\u2D65\\u2D6F\\u2D80-\\u2D96\\u2DA0-\\u2DA6\\u2DA8-\\u2DAE\\u2DB0-\\u2DB6\\u2DB8-\\u2DBE",
690
+ "\\u2DC0-\\u2DC6\\u2DC8-\\u2DCE\\u2DD0-\\u2DD6\\u2DD8-\\u2DDE\\u3005-\\u3007\\u3021-\\u302F",
691
+ "\\u3031-\\u3035\\u3038-\\u303C\\u3041-\\u3096\\u3099\\u309A\\u309D-\\u309F\\u30A1-\\u30FA",
692
+ "\\u30FC-\\u30FF\\u3105-\\u312C\\u3131-\\u318E\\u3192-\\u3195\\u31A0-\\u31B7\\u31F0-\\u31FF",
693
+ "\\u3220-\\u3229\\u3251-\\u325F\\u3280-\\u3289\\u32B1-\\u32BF\\u3400-\\u4DB5\\u4E00-\\u9FA5\\u9FBB",
694
+ "\\uA000-\\uA48C\\uA717-\\uA71A\\uA800-\\uA827\\uA840-\\uA873\\uAC00-\\uD7A3\\uF900-\\uFA2D",
695
+ "\\uFA30-\\uFA6A\\uFA70-\\uFAD9\\uFB00-\\uFB06\\uFB13-\\uFB17\\uFB1D-\\uFB28\\uFB2A-\\uFB36",
696
+ "\\uFB38-\\uFB3C\\uFB3E\\uFB40\\uFB41\\uFB43\\uFB44\\uFB46-\\uFBB1\\uFBD3-\\uFD3D\\uFD50-\\uFD8F",
697
+ "\\uFD92-\\uFDC7\\uFDF0-\\uFDFB\\uFE00-\\uFE0F\\uFE20-\\uFE23\\uFE70-\\uFE74\\uFE76-\\uFEFC",
698
+ "\\uFF10-\\uFF19\\uFF21-\\uFF3A\\uFF41-\\uFF5A\\uFF66-\\uFFBE\\uFFC2-\\uFFC7\\uFFCA-\\uFFCF",
699
+ "\\uFFD2-\\uFFD7\\uFFDA-\\uFFDC",
700
+ "]"
701
+ ].join("");
702
+ //#endregion
637
703
  //#region src/mysql-adapter.ts
638
704
  /** A column's own `@db.mysql.charset`, `@db.mysql.collate` and `@db.column.collate` (lowercased, `""` when absent). */
639
705
  function declaredCharsetCollation(field) {
@@ -2956,31 +3022,48 @@ function vectorToString(vector) {
2956
3022
  }
2957
3023
  /** InnoDB's default full-text stop words (`INFORMATION_SCHEMA.INNODB_FT_DEFAULT_STOPWORD`). */
2958
3024
  const INNODB_DEFAULT_STOPWORDS = new Set("a about an are as at be by com de en for from how i in is it la of on or that the this to was what when where who will with und www".split(" "));
3025
+ /** A word as InnoDB's full-text parser reads it: a run of {@link INNODB_WORD_CLASS}. */
3026
+ const INNODB_WORD = new RegExp(`${INNODB_WORD_CLASS}+`, "gu");
3027
+ /** A word character right before a run of `*` at the end of a chunk: a prefix. */
3028
+ const INNODB_PREFIX = new RegExp(`${INNODB_WORD_CLASS}\\*+$`, "u");
3029
+ /** `innodb_ft_min_token_size` default: shorter words are not indexed. */
3030
+ const INNODB_MIN_TOKEN_SIZE = 3;
3031
+ /**
3032
+ * Whether InnoDB indexes `word` (an {@link INNODB_WORD} match) by default —
3033
+ * required, it can match a row. Word characters are all in the BMP: `length`
3034
+ * counts characters.
3035
+ */
3036
+ function innodbIndexes(word) {
3037
+ return word.length >= INNODB_MIN_TOKEN_SIZE && !INNODB_DEFAULT_STOPWORDS.has(word.toLowerCase());
3038
+ }
2959
3039
  /**
2960
3040
  * A search text as a boolean-mode `AGAINST` term with every word required
2961
- * (`@db.index.fulltext.match "all"`, since 0.1.168): `+word` per word, a
2962
- * `"quoted phrase"` stays one required phrase, a trailing `*` keeps its prefix
2963
- * meaning. The user's own boolean operators (`+ - < > ( ) ~ * " @`) are text,
2964
- * not syntax. A word InnoDB does not index by default — shorter than 3
2965
- * characters (`innodb_ft_min_token_size`) or on its default stop-word list —
2966
- * stays optional: requiring it would match no row.
3041
+ * (`@db.index.fulltext.match "all"`, since 0.1.168). The text is split into
3042
+ * words the way InnoDB splits it ({@link INNODB_WORD}), so the user's own
3043
+ * boolean operators (`+ - < > ( ) ~ * " @`) and punctuation are text, never
3044
+ * syntax: `the, quick` is the words `the` and `quick`. Each word becomes `+word`; a
3045
+ * `"quoted phrase"` stays one required phrase; a `*` right after a word keeps
3046
+ * its prefix meaning (`+dog*`). A word InnoDB does not index by default —
3047
+ * shorter than 3 characters (`innodb_ft_min_token_size`) or on its default
3048
+ * stop-word list — stays optional (requiring it would match no row), as does
3049
+ * a phrase made only of such words. A prefix is required whatever its length:
3050
+ * it matches the indexed words that start with it.
2967
3051
  */
2968
3052
  function mysqlRequireEveryTerm(text) {
2969
3053
  const parts = [];
2970
3054
  for (const match of text.matchAll(/"([^"]*)"|(\S+)/g)) {
2971
3055
  const phrase = match[1];
2972
3056
  if (phrase !== void 0) {
2973
- const clean = phrase.trim();
2974
- if (clean) parts.push(`+"${clean}"`);
3057
+ const words = phrase.match(INNODB_WORD);
3058
+ if (words) parts.push(`${words.some(innodbIndexes) ? "+" : ""}"${words.join(" ")}"`);
2975
3059
  continue;
2976
3060
  }
2977
- const word = match[2];
2978
- const core = word.replace(/\*+$/, "");
2979
- const pieces = core.split(/[+\-<>()~*"@]+/).filter(Boolean);
2980
- pieces.forEach((piece, i) => {
2981
- const star = i === pieces.length - 1 && core.length < word.length ? "*" : "";
2982
- const required = [...piece].length >= 3 && !INNODB_DEFAULT_STOPWORDS.has(piece.toLowerCase());
2983
- parts.push(`${required ? "+" : ""}${piece}${star}`);
3061
+ const chunk = match[2];
3062
+ const words = chunk.match(INNODB_WORD) ?? [];
3063
+ const prefix = chunk.endsWith("*") && INNODB_PREFIX.test(chunk);
3064
+ words.forEach((word, i) => {
3065
+ if (prefix && i === words.length - 1) parts.push(`+${word}*`);
3066
+ else parts.push(`${innodbIndexes(word) ? "+" : ""}${word}`);
2984
3067
  });
2985
3068
  }
2986
3069
  return parts.join(" ");
package/dist/index.mjs CHANGED
@@ -633,6 +633,72 @@ function buildWhere(filter, opts) {
633
633
  return buildWhere$1(mysqlDialect, filter, opts);
634
634
  }
635
635
  //#endregion
636
+ //#region src/innodb-word-chars.ts
637
+ /** A regular-expression character class of InnoDB's word characters (`u` flag). */
638
+ const INNODB_WORD_CLASS = [
639
+ "[",
640
+ "\\u0030-\\u0039\\u0041-\\u005A\\u005F\\u0061-\\u007A\\u00AA\\u00B2\\u00B3\\u00B5\\u00B9\\u00BA",
641
+ "\\u00BC-\\u00BE\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02C1\\u02C6-\\u02D1\\u02E0-\\u02E4\\u02EE",
642
+ "\\u0300-\\u036F\\u037A-\\u037D\\u0386\\u0388-\\u038A\\u038C\\u038E-\\u03A1\\u03A3-\\u03CE",
643
+ "\\u03D0-\\u03F5\\u03F7-\\u0481\\u0483-\\u0486\\u0488-\\u0513\\u0531-\\u0556\\u0559\\u0561-\\u0587",
644
+ "\\u0591-\\u05BD\\u05BF\\u05C1\\u05C2\\u05C4\\u05C5\\u05C7\\u05D0-\\u05EA\\u05F0-\\u05F2",
645
+ "\\u0610-\\u0615\\u0621-\\u063A\\u0640-\\u065E\\u0660-\\u0669\\u066E-\\u06D3\\u06D5-\\u06DC",
646
+ "\\u06DE-\\u06E8\\u06EA-\\u06FC\\u06FF\\u0710-\\u074A\\u074D-\\u076D\\u0780-\\u07B1\\u07C0-\\u07F5",
647
+ "\\u07FA\\u0901-\\u0939\\u093C-\\u094D\\u0950-\\u0954\\u0958-\\u0963\\u0966-\\u096F\\u097B-\\u097F",
648
+ "\\u0981-\\u0983\\u0985-\\u098C\\u098F\\u0990\\u0993-\\u09A8\\u09AA-\\u09B0\\u09B2\\u09B6-\\u09B9",
649
+ "\\u09BC-\\u09C4\\u09C7\\u09C8\\u09CB-\\u09CE\\u09D7\\u09DC\\u09DD\\u09DF-\\u09E3\\u09E6-\\u09F1",
650
+ "\\u09F4-\\u09F9\\u0A01-\\u0A03\\u0A05-\\u0A0A\\u0A0F\\u0A10\\u0A13-\\u0A28\\u0A2A-\\u0A30",
651
+ "\\u0A32\\u0A33\\u0A35\\u0A36\\u0A38\\u0A39\\u0A3C\\u0A3E-\\u0A42\\u0A47\\u0A48\\u0A4B-\\u0A4D",
652
+ "\\u0A59-\\u0A5C\\u0A5E\\u0A66-\\u0A74\\u0A81-\\u0A83\\u0A85-\\u0A8D\\u0A8F-\\u0A91\\u0A93-\\u0AA8",
653
+ "\\u0AAA-\\u0AB0\\u0AB2\\u0AB3\\u0AB5-\\u0AB9\\u0ABC-\\u0AC5\\u0AC7-\\u0AC9\\u0ACB-\\u0ACD\\u0AD0",
654
+ "\\u0AE0-\\u0AE3\\u0AE6-\\u0AEF\\u0B01-\\u0B03\\u0B05-\\u0B0C\\u0B0F\\u0B10\\u0B13-\\u0B28",
655
+ "\\u0B2A-\\u0B30\\u0B32\\u0B33\\u0B35-\\u0B39\\u0B3C-\\u0B43\\u0B47\\u0B48\\u0B4B-\\u0B4D",
656
+ "\\u0B56\\u0B57\\u0B5C\\u0B5D\\u0B5F-\\u0B61\\u0B66-\\u0B6F\\u0B71\\u0B82\\u0B83\\u0B85-\\u0B8A",
657
+ "\\u0B8E-\\u0B90\\u0B92-\\u0B95\\u0B99\\u0B9A\\u0B9C\\u0B9E\\u0B9F\\u0BA3\\u0BA4\\u0BA8-\\u0BAA",
658
+ "\\u0BAE-\\u0BB9\\u0BBE-\\u0BC2\\u0BC6-\\u0BC8\\u0BCA-\\u0BCD\\u0BD7\\u0BE6-\\u0BF2\\u0C01-\\u0C03",
659
+ "\\u0C05-\\u0C0C\\u0C0E-\\u0C10\\u0C12-\\u0C28\\u0C2A-\\u0C33\\u0C35-\\u0C39\\u0C3E-\\u0C44",
660
+ "\\u0C46-\\u0C48\\u0C4A-\\u0C4D\\u0C55\\u0C56\\u0C60\\u0C61\\u0C66-\\u0C6F\\u0C82\\u0C83",
661
+ "\\u0C85-\\u0C8C\\u0C8E-\\u0C90\\u0C92-\\u0CA8\\u0CAA-\\u0CB3\\u0CB5-\\u0CB9\\u0CBC-\\u0CC4",
662
+ "\\u0CC6-\\u0CC8\\u0CCA-\\u0CCD\\u0CD5\\u0CD6\\u0CDE\\u0CE0-\\u0CE3\\u0CE6-\\u0CEF\\u0D02\\u0D03",
663
+ "\\u0D05-\\u0D0C\\u0D0E-\\u0D10\\u0D12-\\u0D28\\u0D2A-\\u0D39\\u0D3E-\\u0D43\\u0D46-\\u0D48",
664
+ "\\u0D4A-\\u0D4D\\u0D57\\u0D60\\u0D61\\u0D66-\\u0D6F\\u0D82\\u0D83\\u0D85-\\u0D96\\u0D9A-\\u0DB1",
665
+ "\\u0DB3-\\u0DBB\\u0DBD\\u0DC0-\\u0DC6\\u0DCA\\u0DCF-\\u0DD4\\u0DD6\\u0DD8-\\u0DDF\\u0DF2\\u0DF3",
666
+ "\\u0E01-\\u0E3A\\u0E40-\\u0E4E\\u0E50-\\u0E59\\u0E81\\u0E82\\u0E84\\u0E87\\u0E88\\u0E8A\\u0E8D",
667
+ "\\u0E94-\\u0E97\\u0E99-\\u0E9F\\u0EA1-\\u0EA3\\u0EA5\\u0EA7\\u0EAA\\u0EAB\\u0EAD-\\u0EB9",
668
+ "\\u0EBB-\\u0EBD\\u0EC0-\\u0EC4\\u0EC6\\u0EC8-\\u0ECD\\u0ED0-\\u0ED9\\u0EDC\\u0EDD\\u0F00",
669
+ "\\u0F18\\u0F19\\u0F20-\\u0F33\\u0F35\\u0F37\\u0F39\\u0F3E-\\u0F47\\u0F49-\\u0F6A\\u0F71-\\u0F84",
670
+ "\\u0F86-\\u0F8B\\u0F90-\\u0F97\\u0F99-\\u0FBC\\u0FC6\\u1000-\\u1021\\u1023-\\u1027\\u1029\\u102A",
671
+ "\\u102C-\\u1032\\u1036-\\u1039\\u1040-\\u1049\\u1050-\\u1059\\u10A0-\\u10C5\\u10D0-\\u10FA\\u10FC",
672
+ "\\u1100-\\u1159\\u115F-\\u11A2\\u11A8-\\u11F9\\u1200-\\u1248\\u124A-\\u124D\\u1250-\\u1256\\u1258",
673
+ "\\u125A-\\u125D\\u1260-\\u1288\\u128A-\\u128D\\u1290-\\u12B0\\u12B2-\\u12B5\\u12B8-\\u12BE\\u12C0",
674
+ "\\u12C2-\\u12C5\\u12C8-\\u12D6\\u12D8-\\u1310\\u1312-\\u1315\\u1318-\\u135A\\u135F\\u1369-\\u137C",
675
+ "\\u1380-\\u138F\\u13A0-\\u13F4\\u1401-\\u166C\\u166F-\\u1676\\u1681-\\u169A\\u16A0-\\u16EA",
676
+ "\\u16EE-\\u16F0\\u1700-\\u170C\\u170E-\\u1714\\u1720-\\u1734\\u1740-\\u1753\\u1760-\\u176C",
677
+ "\\u176E-\\u1770\\u1772\\u1773\\u1780-\\u17B3\\u17B6-\\u17D3\\u17D7\\u17DC\\u17DD\\u17E0-\\u17E9",
678
+ "\\u17F0-\\u17F9\\u180B-\\u180D\\u1810-\\u1819\\u1820-\\u1877\\u1880-\\u18A9\\u1900-\\u191C",
679
+ "\\u1920-\\u192B\\u1930-\\u193B\\u1946-\\u196D\\u1970-\\u1974\\u1980-\\u19A9\\u19B0-\\u19C9",
680
+ "\\u19D0-\\u19D9\\u1A00-\\u1A1B\\u1B00-\\u1B4B\\u1B50-\\u1B59\\u1B6B-\\u1B73\\u1D00-\\u1DCA",
681
+ "\\u1DFE-\\u1E9B\\u1EA0-\\u1EF9\\u1F00-\\u1F15\\u1F18-\\u1F1D\\u1F20-\\u1F45\\u1F48-\\u1F4D",
682
+ "\\u1F50-\\u1F57\\u1F59\\u1F5B\\u1F5D\\u1F5F-\\u1F7D\\u1F80-\\u1FB4\\u1FB6-\\u1FBC\\u1FBE",
683
+ "\\u1FC2-\\u1FC4\\u1FC6-\\u1FCC\\u1FD0-\\u1FD3\\u1FD6-\\u1FDB\\u1FE0-\\u1FEC\\u1FF2-\\u1FF4",
684
+ "\\u1FF6-\\u1FFC\\u2070\\u2071\\u2074-\\u2079\\u207F-\\u2089\\u2090-\\u2094\\u20D0-\\u20EF\\u2102",
685
+ "\\u2107\\u210A-\\u2113\\u2115\\u2119-\\u211D\\u2124\\u2126\\u2128\\u212A-\\u212D\\u212F-\\u2139",
686
+ "\\u213C-\\u213F\\u2145-\\u2149\\u214E\\u2153-\\u2184\\u2460-\\u249B\\u24EA-\\u24FF\\u2776-\\u2793",
687
+ "\\u2C00-\\u2C2E\\u2C30-\\u2C5E\\u2C60-\\u2C6C\\u2C74-\\u2C77\\u2C80-\\u2CE4\\u2CFD\\u2D00-\\u2D25",
688
+ "\\u2D30-\\u2D65\\u2D6F\\u2D80-\\u2D96\\u2DA0-\\u2DA6\\u2DA8-\\u2DAE\\u2DB0-\\u2DB6\\u2DB8-\\u2DBE",
689
+ "\\u2DC0-\\u2DC6\\u2DC8-\\u2DCE\\u2DD0-\\u2DD6\\u2DD8-\\u2DDE\\u3005-\\u3007\\u3021-\\u302F",
690
+ "\\u3031-\\u3035\\u3038-\\u303C\\u3041-\\u3096\\u3099\\u309A\\u309D-\\u309F\\u30A1-\\u30FA",
691
+ "\\u30FC-\\u30FF\\u3105-\\u312C\\u3131-\\u318E\\u3192-\\u3195\\u31A0-\\u31B7\\u31F0-\\u31FF",
692
+ "\\u3220-\\u3229\\u3251-\\u325F\\u3280-\\u3289\\u32B1-\\u32BF\\u3400-\\u4DB5\\u4E00-\\u9FA5\\u9FBB",
693
+ "\\uA000-\\uA48C\\uA717-\\uA71A\\uA800-\\uA827\\uA840-\\uA873\\uAC00-\\uD7A3\\uF900-\\uFA2D",
694
+ "\\uFA30-\\uFA6A\\uFA70-\\uFAD9\\uFB00-\\uFB06\\uFB13-\\uFB17\\uFB1D-\\uFB28\\uFB2A-\\uFB36",
695
+ "\\uFB38-\\uFB3C\\uFB3E\\uFB40\\uFB41\\uFB43\\uFB44\\uFB46-\\uFBB1\\uFBD3-\\uFD3D\\uFD50-\\uFD8F",
696
+ "\\uFD92-\\uFDC7\\uFDF0-\\uFDFB\\uFE00-\\uFE0F\\uFE20-\\uFE23\\uFE70-\\uFE74\\uFE76-\\uFEFC",
697
+ "\\uFF10-\\uFF19\\uFF21-\\uFF3A\\uFF41-\\uFF5A\\uFF66-\\uFFBE\\uFFC2-\\uFFC7\\uFFCA-\\uFFCF",
698
+ "\\uFFD2-\\uFFD7\\uFFDA-\\uFFDC",
699
+ "]"
700
+ ].join("");
701
+ //#endregion
636
702
  //#region src/mysql-adapter.ts
637
703
  /** A column's own `@db.mysql.charset`, `@db.mysql.collate` and `@db.column.collate` (lowercased, `""` when absent). */
638
704
  function declaredCharsetCollation(field) {
@@ -2955,31 +3021,48 @@ function vectorToString(vector) {
2955
3021
  }
2956
3022
  /** InnoDB's default full-text stop words (`INFORMATION_SCHEMA.INNODB_FT_DEFAULT_STOPWORD`). */
2957
3023
  const INNODB_DEFAULT_STOPWORDS = new Set("a about an are as at be by com de en for from how i in is it la of on or that the this to was what when where who will with und www".split(" "));
3024
+ /** A word as InnoDB's full-text parser reads it: a run of {@link INNODB_WORD_CLASS}. */
3025
+ const INNODB_WORD = new RegExp(`${INNODB_WORD_CLASS}+`, "gu");
3026
+ /** A word character right before a run of `*` at the end of a chunk: a prefix. */
3027
+ const INNODB_PREFIX = new RegExp(`${INNODB_WORD_CLASS}\\*+$`, "u");
3028
+ /** `innodb_ft_min_token_size` default: shorter words are not indexed. */
3029
+ const INNODB_MIN_TOKEN_SIZE = 3;
3030
+ /**
3031
+ * Whether InnoDB indexes `word` (an {@link INNODB_WORD} match) by default —
3032
+ * required, it can match a row. Word characters are all in the BMP: `length`
3033
+ * counts characters.
3034
+ */
3035
+ function innodbIndexes(word) {
3036
+ return word.length >= INNODB_MIN_TOKEN_SIZE && !INNODB_DEFAULT_STOPWORDS.has(word.toLowerCase());
3037
+ }
2958
3038
  /**
2959
3039
  * A search text as a boolean-mode `AGAINST` term with every word required
2960
- * (`@db.index.fulltext.match "all"`, since 0.1.168): `+word` per word, a
2961
- * `"quoted phrase"` stays one required phrase, a trailing `*` keeps its prefix
2962
- * meaning. The user's own boolean operators (`+ - < > ( ) ~ * " @`) are text,
2963
- * not syntax. A word InnoDB does not index by default — shorter than 3
2964
- * characters (`innodb_ft_min_token_size`) or on its default stop-word list —
2965
- * stays optional: requiring it would match no row.
3040
+ * (`@db.index.fulltext.match "all"`, since 0.1.168). The text is split into
3041
+ * words the way InnoDB splits it ({@link INNODB_WORD}), so the user's own
3042
+ * boolean operators (`+ - < > ( ) ~ * " @`) and punctuation are text, never
3043
+ * syntax: `the, quick` is the words `the` and `quick`. Each word becomes `+word`; a
3044
+ * `"quoted phrase"` stays one required phrase; a `*` right after a word keeps
3045
+ * its prefix meaning (`+dog*`). A word InnoDB does not index by default —
3046
+ * shorter than 3 characters (`innodb_ft_min_token_size`) or on its default
3047
+ * stop-word list — stays optional (requiring it would match no row), as does
3048
+ * a phrase made only of such words. A prefix is required whatever its length:
3049
+ * it matches the indexed words that start with it.
2966
3050
  */
2967
3051
  function mysqlRequireEveryTerm(text) {
2968
3052
  const parts = [];
2969
3053
  for (const match of text.matchAll(/"([^"]*)"|(\S+)/g)) {
2970
3054
  const phrase = match[1];
2971
3055
  if (phrase !== void 0) {
2972
- const clean = phrase.trim();
2973
- if (clean) parts.push(`+"${clean}"`);
3056
+ const words = phrase.match(INNODB_WORD);
3057
+ if (words) parts.push(`${words.some(innodbIndexes) ? "+" : ""}"${words.join(" ")}"`);
2974
3058
  continue;
2975
3059
  }
2976
- const word = match[2];
2977
- const core = word.replace(/\*+$/, "");
2978
- const pieces = core.split(/[+\-<>()~*"@]+/).filter(Boolean);
2979
- pieces.forEach((piece, i) => {
2980
- const star = i === pieces.length - 1 && core.length < word.length ? "*" : "";
2981
- const required = [...piece].length >= 3 && !INNODB_DEFAULT_STOPWORDS.has(piece.toLowerCase());
2982
- parts.push(`${required ? "+" : ""}${piece}${star}`);
3060
+ const chunk = match[2];
3061
+ const words = chunk.match(INNODB_WORD) ?? [];
3062
+ const prefix = chunk.endsWith("*") && INNODB_PREFIX.test(chunk);
3063
+ words.forEach((word, i) => {
3064
+ if (prefix && i === words.length - 1) parts.push(`+${word}*`);
3065
+ else parts.push(`${innodbIndexes(word) ? "+" : ""}${word}`);
2983
3066
  });
2984
3067
  }
2985
3068
  return parts.join(" ");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/db-mysql",
3
- "version": "0.1.172",
3
+ "version": "0.1.174",
4
4
  "description": "MySQL adapter for @atscript/db with mysql2 driver support.",
5
5
  "keywords": [
6
6
  "atscript",
@@ -41,21 +41,21 @@
41
41
  "access": "public"
42
42
  },
43
43
  "dependencies": {
44
- "@atscript/db-sql-tools": "^0.1.172"
44
+ "@atscript/db-sql-tools": "^0.1.174"
45
45
  },
46
46
  "devDependencies": {
47
- "@atscript/core": "^0.2.8",
48
- "@atscript/typescript": "^0.2.8",
47
+ "@atscript/core": "^0.2.9",
48
+ "@atscript/typescript": "^0.2.9",
49
49
  "@uniqu/core": "^0.2.1",
50
50
  "mysql2": "^3.11.0",
51
- "unplugin-atscript": "^0.2.8"
51
+ "unplugin-atscript": "^0.2.9"
52
52
  },
53
53
  "peerDependencies": {
54
- "@atscript/core": "^0.2.8",
55
- "@atscript/typescript": "^0.2.8",
54
+ "@atscript/core": "^0.2.9",
55
+ "@atscript/typescript": "^0.2.9",
56
56
  "@uniqu/core": "^0.2.1",
57
57
  "mysql2": ">=3.0.0",
58
- "@atscript/db": "^0.1.172"
58
+ "@atscript/db": "^0.1.174"
59
59
  },
60
60
  "peerDependenciesMeta": {
61
61
  "mysql2": {