fix(search): tokenizer 变化时自动重建 FTS 索引#484
Open
Qiyuanqiii wants to merge 1 commit into
Open
Conversation
Collaborator
|
hank you for submitting this PR and participating in Tencent Rhino-bird Open-source Training Program! |
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.
关联 Issue
Related to #160
背景与定位
#160 的相关修复目前已经明确分工:
本 PR 不再扩展查询语法净化,而是处理另一条独立的持久化索引一致性问题:运行时 tokenizer 发生变化后,历史 FTS 索引仍保留旧 tokenizer 的写入结构。
问题根因
SQLite FTS5 表会跨进程重启持久化,但当前数据库没有记录索引写入时使用的 tokenizer。
当某次启动无法加载 jieba 时,中文内容会通过
unicode61fallback 按连续文本写入。后续启动恢复 jieba 后,查询侧会重新按词切分,但既有索引不会重建,因此“北京烤鸭”索引可能无法响应“烤鸭”子词查询。反向切换同样存在问题:使用 jieba 分词写入的索引,在后续降级为 fallback 查询整句时也可能无法命中。根因不是用户输入语法,而是持久化索引的写入 tokenizer 与当前查询 tokenizer 失配。
实现方案
fts_meta表,持久化 FTS 写入侧 tokenizer 指纹jieba-cut-for-search-v1与unicode61-raw-v1兼容性
当前 tokenizer 与已保存指纹一致时,不会触发额外重建。空数据库只记录当前指纹,不产生无意义的数据扫描。
本 PR 不包含:
因此它是持久化 SQLite FTS 索引的启动期自校准,不替代 #178,也不改变正常查询语义。
验证
1个文件、3项测试通过5个文件、70项测试通过git diff --check:通过定向测试覆盖
验证截图