File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 11import pytest
22from sqlite_utils import Database
33from sqlite_utils .utils import sqlite3
4+ from unittest .mock import ANY
45
56search_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+
129156def test_enable_fts_table_names_containing_spaces (fresh_db ):
130157 table = fresh_db ["test" ]
131158 table .insert ({"column with spaces" : "in its name" })
You can’t perform that action at this time.
0 commit comments