【发布时间】:2017-08-14 19:24:12
【问题描述】:
我有一个表格,其中包含 30 万条使用字母数字、数字、点、下划线和方括号 [] 的字符串记录。
我使用对 sqlite3 的 FTS5 扩展来启用对该表的快速搜索。 这就是我创建 FTS 虚拟表的方式:
database = sqlite3.connect("mydb.db")
db_cursor = database.cursor()
db_cursor.execute("create virtual table field_names USING fts5 (full_path)")
我在循环中使用以下代码添加约 30 万条记录:
database.execute("insert into field_names(full_path) values (?)", (field_path,))
样本记录:
a.extbootrecord.field_db0
a.extbootrecord.field_db1
a.extbootrecord.field_db8
a.extbootrecord.field_db9
a.extbootrecord.field_db10
a.extbootrecord.field_db11
a.extbootrecord.field_db12
a.extbootrecord.field_db15
使用以下查询:
db_cursor.execute("select full_path from field_names where field_names = '\"%s\"'" % search_phrase)
return_list = list()
entries = db_cursor.fetchmany(100)
while entries:
return_list.extend([entry[0] for entry in entries])
entries = db_cursor.fetchmany(100)
使用以下search_phrase 会产生以下结果:
-
ext:没什么 -
extbootrecord:所有记录 -
extbootrecrd.:所有记录 -
extbootrecord.fie:没什么 -
extbootrecord.field: 所有记录 -
extbootrecord.field_db1:只有a.extbootrecord.field_db1记录,我希望 field_db1, field_db10, field_db11... 被返回
似乎我缺少一些 FTS 配置来使用 .、_ 和 0-9 作为令牌的一部分作为有效字符。
我尝试在创建语句中使用 tokenize = \"unicode61 tokenchars '_.'\" 配置 FTS 标记器,但没有成功。
我错过了什么?
【问题讨论】:
标签: python-3.x sqlite full-text-search fts5