-
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enable_fts(), populate_fts() and search() methods
- Loading branch information
Simon Willison
committed
Jul 31, 2018
1 parent
c446e22
commit f4907f6
Showing
4 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import io | ||
import os | ||
|
||
VERSION = "0.3.1" | ||
VERSION = "0.4" | ||
|
||
|
||
def get_long_description(): | ||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") |