perf(search): a one- or two-letter last word is matched whole, not as a prefix
A 1-2 letter prefix matched most of the library and ts_rank scored every match: "m" took ~4-8 s on prod against ~150 ms now. The prefix match starts at three characters (MIN_PREFIX_LEN); shared by the YouTube feed and the Plex library search.
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
"""iso(): the single date/datetime→JSON serializer the routes share (R6 S1a)."""
|
||||
"""iso(): the single date/datetime→JSON serializer the routes share (R6 S1a); to_tsquery_str()."""
|
||||
|
||||
from datetime import date, datetime, timezone
|
||||
|
||||
from app.utils import iso, normalize_description
|
||||
from app.utils import iso, normalize_description, to_tsquery_str
|
||||
|
||||
|
||||
def test_none_maps_to_none():
|
||||
@@ -56,3 +56,19 @@ def test_normalize_description_single_line_unchanged():
|
||||
def test_normalize_description_folds_crlf_line_endings():
|
||||
# splitlines() folds CR/CRLF to \n — a documented, benign line-ending normalization.
|
||||
assert normalize_description("a\r\nb\r\n\r\nc") == "a\nb\nc"
|
||||
|
||||
|
||||
def test_tsquery_prefix_matches_a_last_word_of_three_or_more():
|
||||
assert to_tsquery_str("ti amo magyar") == "ti & amo & magyar:*"
|
||||
assert to_tsquery_str("min") == "min:*"
|
||||
|
||||
|
||||
def test_tsquery_matches_a_short_last_word_whole():
|
||||
# A 1-2 letter prefix made ts_rank score most of the library (5-8 s on prod, E31 S4e).
|
||||
assert to_tsquery_str("m") == "m"
|
||||
assert to_tsquery_str("minecraft 4k") == "minecraft & 4k"
|
||||
assert to_tsquery_str("ti amo m") == "ti & amo & m"
|
||||
|
||||
|
||||
def test_tsquery_without_a_word_is_none():
|
||||
assert to_tsquery_str("?! --") is None
|
||||
|
||||
Reference in New Issue
Block a user