【问题标题】:How do I use the trigram tokenizer/similarity option with Peewee and SQLite's FTS5?如何在 Peewee 和 SQLite 的 FTS5 中使用 trigram tokenizer/similarity 选项?
【发布时间】:2021-10-17 13:33:53
【问题描述】:

这个问题涉及如何将 FTS5 的 trigram tokenizer 与 Peewee 一起使用。

  1. official FTS5 documentation for SQLite cites support for trigram tokenization/similarity:

     > The experimental trigram tokenizer extends FTS5 to 
     > support substring matching in general, instead of the 
     > usual token matching. When using the trigram tokenizer
     > , a query or phrase token may match any sequence of 
     > characters within a row, not just a complete token.
     > 
     > CREATE VIRTUAL TABLE tri USING fts5(a, tokenize="trigram");
     > INSERT INTO tri VALUES('abcdefghij KLMNOPQRST uvwxyz');
    
  2. 我尝试使用 Peewee 设置基于 FTS 的课程。我更改了使用 trigram 标记器的选项:

     class Meta:
         db_table = 'fts_test_db'
         database = test_db
         options = {'tokenize': 'trigram', 'content': PrecedentPW}
    
  3. 当我尝试使用这些选项创建表时,会出现此错误:

     _db.create_tables([_fts], )
    
     >> peewee.OperationalError: no such tokenizer: trigram
    
  4. 但是,如果我将标记器选项更改为使用其他东西(例如“搬运工”),则不会引发错误。

如何在 Peewee 中使用 trigram 标记器?

【问题讨论】:

    标签: sqlite peewee fts5


    【解决方案1】:

    您可能需要自己编译标记器或确保您运行的是足够新的版本。在 Sqlite 3.34.0 之前,默认情况下不包含 trigram 标记器:https://www.sqlite.org/releaselog/3_34_0.html

    【讨论】:

    • 我明白了,谢谢。只是为了检查一下,Peewee 目前是在 SQLite 3.22 版还是其他版本上运行?
    • 它适用于任何 SQLite 版本。您可能只是看到系统 SQLite 的版本。
    猜你喜欢
    • 2023-03-06
    • 2021-09-26
    • 2022-07-14
    • 1970-01-01
    • 2016-11-02
    • 1970-01-01
    • 2021-05-06
    • 2014-03-22
    • 2021-10-09
    相关资源
    最近更新 更多