Skip to content

Commit

Permalink
Stop treating the last token of a query string as a prefix token
Browse files Browse the repository at this point in the history
  • Loading branch information
kozlovsky committed Jan 16, 2023
1 parent 3164ab2 commit a1693f3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,21 @@ async def test_search_with_space(rest_api, metadata_store):
metadata_store.TorrentMetadata(title='abc defxyz', infohash=random_infohash())

s1 = to_fts_query("abc")
assert s1 == '"abc"*'
assert s1 == '"abc"'

s2 = to_fts_query("abc def")
assert s2 == '"abc" "def"*'
assert s2 == '"abc" "def"'

ss2 = to_fts_query(s2)
assert ss2 == s2

parsed = await do_request(rest_api, f'search?txt_filter={s1}', expected_code=200)
results = {item["name"] for item in parsed["results"]}
assert results == {'abc', 'abc.def', 'abc def', 'abc defxyz', 'abcxyz def'}
assert results == {'abc', 'abc.def', 'abc def', 'abc defxyz'}

parsed = await do_request(rest_api, f'search?txt_filter={s2}', expected_code=200)
results = {item["name"] for item in parsed["results"]}
assert results == {'abc.def', 'abc def', 'abc defxyz'} # but not 'abcxyz def'
assert results == {'abc.def', 'abc def'} # but not 'abcxyz def'


async def test_single_snippet_in_search(rest_api, metadata_store, knowledge_db):
Expand Down
6 changes: 3 additions & 3 deletions src/tribler/core/utilities/tests/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ def test_to_fts_query():
assert to_fts_query(None) is None
assert to_fts_query('') is None
assert to_fts_query(' ') is None
assert to_fts_query(' abc') == '"abc"*'
assert to_fts_query('abc def') == '"abc" "def"*'
assert to_fts_query('[abc, def]: xyz?!') == '"abc" "def" "xyz"*'
assert to_fts_query(' abc') == '"abc"'
assert to_fts_query('abc def') == '"abc" "def"'
assert to_fts_query('[abc, def]: xyz?!') == '"abc" "def" "xyz"'


def test_extract_tags():
Expand Down
2 changes: 1 addition & 1 deletion src/tribler/core/utilities/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def to_fts_query(text):
if not words:
return None

return ' '.join(words) + '*'
return ' '.join(words)


def show_system_popup(title, text):
Expand Down

0 comments on commit a1693f3

Please sign in to comment.