feat(fts): add MeCab tokenizer for Japanese + tokenizer registry refactor - #57
Open
chiangchenghsin-hash wants to merge 112 commits into
Open
feat(fts): add MeCab tokenizer for Japanese + tokenizer registry refactor#57chiangchenghsin-hash wants to merge 112 commits into
chiangchenghsin-hash wants to merge 112 commits into
Conversation
…d_subdirectory for CI
…d_subdirectory for CI
Contributor
Preference is to add third_party as a submodule if necessary instead of vendoring. We're already doing it for datasets submodule in various language bindings (e.g. ladybug-python). Also why does this PR have 112 commits? Given that FTS is a widely used module and the impact of such a large diff on the text size, it's probably best maintained as an out of tree extension. Adding third_party/opengql was a mistake. It should be added to main repo's third_party and then added as a submodule. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a MeCab tokenizer for Japanese to the FTS extension, together with a small tokenizer registry refactor that makes adding new tokenizers a one-line registration, and a fix for a silent correctness bug in incremental index updates.
While working on this, I noticed the FTS tokenizer code referenced
third_party/cppjiebabut the directory was never vendored in this repo, so the Jieba (Chinese) tokenizer could not be built from source. This PR includes the vendoredcppjiebatree (from the upstream cppjieba project, MIT license) so the extension builds self-contained.Changes
New tokenizer architecture (
fts/src/utils/tokenizer.{h,cpp}):ITokenizerinterface +TokenizerRegistry(factories registered by name) +TokenizerPool(instances cached per name+params and shared across index builds, incremental inserts and queries).FTSConfig.tokenizerParams(unordered map) replaces the hardcodedjiebaDictDirfield; serialization is backward compatible (a magic marker distinguishes new catalogs from legacy ones, whose dict dir is folded intotokenizerParams["jieba_dict_dir"]).MeCab (Japanese) tokenizer:
third_party/mecab/(mecab 0.996, BSD-3) with the MSVC compatibility fixes needed for modern MSVC (missingWPATH_FORCEdefine,registerkeyword removal,std::binary_function, gatedunsigned long longstream operator, static-linkDLL_EXPORThandling).mecab-dict-index -f euc-jp -t utf-8), so no large dictionary files are committed.tokenizer := 'mecab'option withmecab_dict_dirparameter; default dictionary is copied next to the built extension like the jieba dict.fts_japanese.testcovering basic queries, incremental insert, and a custom dict dir.Bug fix — incremental insert used the wrong tokenizer:
createFTSIndexQueryrewrote the internal_CREATE_FTS_INDEXcall without forwardingtokenizer/jieba_dict_dir, so the index's internal config silently fell back to'simple'. Rows inserted after index creation were tokenized with whitespace splitting, so Chinese/Japanese terms were never indexed (queries could not match new rows). The parameters are now forwarded, with a regression test (ChineseIncrementalInsertinfts_chinese.test).Why it matters
simpletokenizer — affecting existing Chinese users today, not just the new Japanese path.Verification
Built with MSVC (Visual Studio 18 2026, Release) on Windows; all tests pass:
fts_chinese.test(Jieba) incl. new incremental-insert regression casefts_japanese.test(MeCab) — basic, incremental insert, custom dict dirfts_basic/error.testsuites unaffected (tokenizer error message updated in sync)Note: I could not run the full
.testsuite in CI here (test targets are not enabled in my local build config), but all touched paths are covered by the smoke tests above.Thank you for reviewing!