Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/postgrest/src/postgrest/_async/request_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,7 @@ def text_search(
elif type_ == "web_search":
type_part = "w"
config_part = f"({options.get('config')})" if options.get("config") else ""
self.request.params = self.request.params.add(
column, f"{type_part}fts{config_part}.{query}"
)
self.filter(column, f"{type_part}fts{config_part}", query)

return AsyncQueryRequestBuilder(self.request)

Expand Down
4 changes: 1 addition & 3 deletions src/postgrest/src/postgrest/_sync/request_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,7 @@ def text_search(
elif type_ == "web_search":
type_part = "w"
config_part = f"({options.get('config')})" if options.get("config") else ""
self.request.params = self.request.params.add(
column, f"{type_part}fts{config_part}.{query}"
)
self.filter(column, f"{type_part}fts{config_part}", query)

return SyncQueryRequestBuilder(self.request)

Expand Down
30 changes: 30 additions & 0 deletions src/postgrest/tests/_async/test_request_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,36 @@ def test_delete_with_select(self, request_builder: AsyncRequestBuilder):


class TestTextSearch:
@pytest.mark.parametrize(
"mode,operator",
[
(None, "fts"),
("plain", "plfts"),
("phrase", "phfts"),
("web_search", "wfts"),
],
)
@pytest.mark.parametrize("config", [None, "english"])
@pytest.mark.parametrize("negate", [False, True])
def test_negation_is_applied_only_to_text_search(
self, request_builder: AsyncRequestBuilder, mode, operator, config, negate
):
selected = request_builder.select("content")
if negate:
selected = selected.not_

builder = selected.text_search(
"content", "fat cat", {"type": mode, "config": config}
)

expected_operator = ("not." if negate else "") + operator
if config:
expected_operator += f"({config})"
assert builder.request.params["content"] == f"{expected_operator}.fat cat"
assert not selected.negate_next
selected.eq("published", "true")
assert builder.request.params["published"] == "eq.true"

def test_text_search(self, request_builder: AsyncRequestBuilder):
builder = request_builder.select("catchphrase").text_search(
"catchphrase",
Expand Down
30 changes: 30 additions & 0 deletions src/postgrest/tests/_sync/test_request_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,36 @@ def test_delete_with_select(self, request_builder: SyncRequestBuilder):


class TestTextSearch:
@pytest.mark.parametrize(
"mode,operator",
[
(None, "fts"),
("plain", "plfts"),
("phrase", "phfts"),
("web_search", "wfts"),
],
)
@pytest.mark.parametrize("config", [None, "english"])
@pytest.mark.parametrize("negate", [False, True])
def test_negation_is_applied_only_to_text_search(
self, request_builder: SyncRequestBuilder, mode, operator, config, negate
):
selected = request_builder.select("content")
if negate:
selected = selected.not_

builder = selected.text_search(
"content", "fat cat", {"type": mode, "config": config}
)

expected_operator = ("not." if negate else "") + operator
if config:
expected_operator += f"({config})"
assert builder.request.params["content"] == f"{expected_operator}.fat cat"
assert not selected.negate_next
selected.eq("published", "true")
assert builder.request.params["published"] == "eq.true"

def test_text_search(self, request_builder: SyncRequestBuilder):
builder = request_builder.select("catchphrase").text_search(
"catchphrase",
Expand Down