Skip to content

Commit 9a5256e

Browse files
committed
Test for .search(include_rank)
Refs #628 (comment)
1 parent 381cc73 commit 9a5256e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/test_fts.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22
from sqlite_utils import Database
33
from sqlite_utils.utils import sqlite3
4+
from unittest.mock import ANY
45

56
search_records = [
67
{
@@ -126,6 +127,32 @@ def test_search_where_args_disallows_query(fresh_db):
126127
)
127128

128129

130+
def test_search_include_rank(fresh_db):
131+
table = fresh_db["t"]
132+
table.insert_all(search_records)
133+
table.enable_fts(["text", "country"], fts_version="FTS5")
134+
results = list(table.search("are", include_rank=True))
135+
assert results == [
136+
{
137+
"rowid": 1,
138+
"text": "tanuki are running tricksters",
139+
"country": "Japan",
140+
"not_searchable": "foo",
141+
"rank": ANY,
142+
},
143+
{
144+
"rowid": 2,
145+
"text": "racoons are biting trash pandas",
146+
"country": "USA",
147+
"not_searchable": "bar",
148+
"rank": ANY,
149+
},
150+
]
151+
assert isinstance(results[0]["rank"], float)
152+
assert isinstance(results[1]["rank"], float)
153+
assert results[0]["rank"] < results[1]["rank"]
154+
155+
129156
def test_enable_fts_table_names_containing_spaces(fresh_db):
130157
table = fresh_db["test"]
131158
table.insert({"column with spaces": "in its name"})

0 commit comments

Comments
 (0)