【问题标题】:Can I use InnoDB full text search to tokenize documents?我可以使用 InnoDB 全文搜索来标记文档吗?
【发布时间】:2020-02-02 18:11:57
【问题描述】:

我曾经认为,除非我们用 C 语言编写一些用户定义的函数,否则 SQL 无法处理非结构化数据(如文本)。但是,InnoDB 的全文搜索功能似乎已经完成了很多此类工作。

根据https://dev.mysql.com/doc/refman/5.6/en/innodb-fulltext-index.html,索引保存在名为FTS_00000..._00000..._INDEX_?的InnoDB表中。

我尝试运行 SELECT * FROM FTS_00000..._00000..._INDEX_1,希望看到每个文档中的标记(可能已经删除了停用词)。但是,我收到一条错误消息

ERROR 1146 (42S02): Table 'tf.FTS_0000000000000028_0000000000000030_INDEX_1' doesn't exist

即使select * from information_schema.INNODB_SYS_TABLES; 显示该表存在。

有谁知道如何获取插入全文索引的每个文档的标记?如果我能在以下数据模式中获取信息,那就太好了:

token_id   document_id   count
"apple"    103343        3
"orange"    9593         1
...

【问题讨论】:

    标签: mysql full-text-search innodb full-text-indexing fulltext-index


    【解决方案1】:

    仅仅因为 InnoDB 使用表作为内部数据结构并不意味着您可以使用 SQL 语句查询那些 FTS 表。它们不会出现在 INFORMATION_SCHEMA.TABLES 中。

    在创建表opening_lines(该手册页中给出的示例)后,我看到了:

    mysql> SELECT table_id, name, space FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES
        ->        WHERE name LIKE 'test/%';
    +----------+----------------------------------------------------+-------+
    | table_id | name                                               | space |
    +----------+----------------------------------------------------+-------+
    |       52 | test/FTS_000000000000002e_0000000000000085_INDEX_1 |    36 |
    |       53 | test/FTS_000000000000002e_0000000000000085_INDEX_2 |    37 |
    |       54 | test/FTS_000000000000002e_0000000000000085_INDEX_3 |    38 |
    |       55 | test/FTS_000000000000002e_0000000000000085_INDEX_4 |    39 |
    |       56 | test/FTS_000000000000002e_0000000000000085_INDEX_5 |    40 |
    |       57 | test/FTS_000000000000002e_0000000000000085_INDEX_6 |    41 |
    |       47 | test/FTS_000000000000002e_BEING_DELETED            |    31 |
    |       48 | test/FTS_000000000000002e_BEING_DELETED_CACHE      |    32 |
    |       49 | test/FTS_000000000000002e_CONFIG                   |    33 |
    |       50 | test/FTS_000000000000002e_DELETED                  |    34 |
    |       51 | test/FTS_000000000000002e_DELETED_CACHE            |    35 |
    |       46 | test/opening_lines                                 |    30 |
    +----------+----------------------------------------------------+-------+
    12 rows in set (0.00 sec)
    
    mysql> SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='test';
    +---------------+
    | TABLE_NAME    |
    +---------------+
    | opening_lines |
    +---------------+
    1 rows in set (0.00 sec)
    

    据我所知,根本无法直接查询 FTS 表。它们仅用于 InnoDB 的全文索引的内部实现。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-29
      相关资源
      最近更新 更多