mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-09 18:14:09 +02:00
include_rank parameter for Table.search
* Add `include_rank` parameter to `Table.search` * Test for .search(include_rank) * Docs for table.search(include_rank) https://github.com/simonw/sqlite-utils/pull/628 Refs #480 --------- Co-authored-by: Simon Willison <swillison@gmail.com>
This commit is contained in:
parent
42230709f7
commit
7423296ec7
3 changed files with 33 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import pytest
|
||||
from sqlite_utils import Database
|
||||
from sqlite_utils.utils import sqlite3
|
||||
from unittest.mock import ANY
|
||||
|
||||
search_records = [
|
||||
{
|
||||
|
|
@ -126,6 +127,32 @@ def test_search_where_args_disallows_query(fresh_db):
|
|||
)
|
||||
|
||||
|
||||
def test_search_include_rank(fresh_db):
|
||||
table = fresh_db["t"]
|
||||
table.insert_all(search_records)
|
||||
table.enable_fts(["text", "country"], fts_version="FTS5")
|
||||
results = list(table.search("are", include_rank=True))
|
||||
assert results == [
|
||||
{
|
||||
"rowid": 1,
|
||||
"text": "tanuki are running tricksters",
|
||||
"country": "Japan",
|
||||
"not_searchable": "foo",
|
||||
"rank": ANY,
|
||||
},
|
||||
{
|
||||
"rowid": 2,
|
||||
"text": "racoons are biting trash pandas",
|
||||
"country": "USA",
|
||||
"not_searchable": "bar",
|
||||
"rank": ANY,
|
||||
},
|
||||
]
|
||||
assert isinstance(results[0]["rank"], float)
|
||||
assert isinstance(results[1]["rank"], float)
|
||||
assert results[0]["rank"] < results[1]["rank"]
|
||||
|
||||
|
||||
def test_enable_fts_table_names_containing_spaces(fresh_db):
|
||||
table = fresh_db["test"]
|
||||
table.insert({"column with spaces": "in its name"})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue