From 810f6b2ecbf1cdd552fc2733a0bdd5b2d0625596 Mon Sep 17 00:00:00 2001 From: Dan Allan Date: Fri, 26 Jan 2024 15:58:28 -0500 Subject: [PATCH] Fix oddity with plainto_tsquery vs to_tsquery --- tiled/_tests/test_queries.py | 6 ++++++ tiled/catalog/adapter.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tiled/_tests/test_queries.py b/tiled/_tests/test_queries.py index 00fd58374..7af19eebb 100644 --- a/tiled/_tests/test_queries.py +++ b/tiled/_tests/test_queries.py @@ -45,6 +45,9 @@ mapping["does_not_contain_z"] = ArrayAdapter.from_array( numpy.ones(10), metadata={"letters": list(string.ascii_lowercase[:-1])} ) +mapping["full_text_test_case"] = ArrayAdapter.from_array( + numpy.ones(10), metadata={"color": "purple"} +) mapping["specs_foo_bar"] = ArrayAdapter.from_array(numpy.ones(10), specs=["foo", "bar"]) mapping["specs_foo_bar_baz"] = ArrayAdapter.from_array( @@ -168,6 +171,9 @@ def cm(): cm = nullcontext with cm(): assert list(client.search(FullText("z"))) == ["z", "does_contain_z"] + # plainto_tsquery fails to find certain words, weirdly, so it is a useful + # test that we are using tsquery + assert list(client.search(FullText("purple"))) == ["full_text_test_case"] def test_regex(client): diff --git a/tiled/catalog/adapter.py b/tiled/catalog/adapter.py index 34196fade..984ff3a53 100644 --- a/tiled/catalog/adapter.py +++ b/tiled/catalog/adapter.py @@ -1008,7 +1008,7 @@ def full_text(query, tree): tsvector = func.jsonb_to_tsvector( cast("simple", REGCONFIG), orm.Node.metadata_, cast(["string"], JSONB) ) - condition = tsvector.op("@@")(func.to_tsquery(query.text)) + condition = tsvector.op("@@")(func.to_tsquery("simple", query.text)) # condition = tsvector.match(query.text) else: raise UnsupportedQueryType("full_text")