mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-14 12:34:10 +02:00
enable_fts(), populate_fts() and search() methods
This commit is contained in:
parent
c446e22f34
commit
f4907f6df5
4 changed files with 100 additions and 1 deletions
37
tests/test_enable_fts.py
Normal file
37
tests/test_enable_fts.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
from .fixtures import fresh_db
|
||||
import pytest
|
||||
|
||||
search_records = [
|
||||
{"text": "tanuki are tricksters", "country": "Japan", "not_searchable": "foo"},
|
||||
{"text": "racoons are trash pandas", "country": "USA", "not_searchable": "bar"},
|
||||
]
|
||||
|
||||
|
||||
def test_enable_fts(fresh_db):
|
||||
table = fresh_db["searchable"]
|
||||
table.insert_all(search_records)
|
||||
assert ["searchable"] == fresh_db.tables
|
||||
table.enable_fts(["text", "country"])
|
||||
assert [
|
||||
"searchable",
|
||||
"searchable_fts",
|
||||
"searchable_fts_segments",
|
||||
"searchable_fts_segdir",
|
||||
"searchable_fts_docsize",
|
||||
"searchable_fts_stat",
|
||||
] == fresh_db.tables
|
||||
assert [("tanuki are tricksters", "Japan", "foo")] == table.search("tanuki")
|
||||
assert [("racoons are trash pandas", "USA", "bar")] == table.search("usa")
|
||||
assert [] == table.search("bar")
|
||||
|
||||
|
||||
def test_populate_fts(fresh_db):
|
||||
table = fresh_db["populatable"]
|
||||
table.insert(search_records[0])
|
||||
table.enable_fts(["text", "country"])
|
||||
assert [] == table.search("trash pandas")
|
||||
table.insert(search_records[1])
|
||||
assert [] == table.search("trash pandas")
|
||||
# Now run populate_fts to make this record available
|
||||
table.populate_fts(["text", "country"])
|
||||
assert [("racoons are trash pandas", "USA", "bar")] == table.search("usa")
|
||||
Loading…
Add table
Add a link
Reference in a new issue