Skip to content

Commit

Permalink
(PC-34405)[BO] fix: search in chronicles with special char like a colon
Browse files Browse the repository at this point in the history
  • Loading branch information
rpaoloni-pass committed Feb 5, 2025
1 parent 28c3e5a commit 4ca7740
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion api/src/pcapi/routes/backoffice/chronicles/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ def list_chronicles() -> utils.BackofficeResponse:
if form.search_type.data in (forms.SearchType.ALL.name, forms.SearchType.CHRONICLE_CONTENT.name):
q_filters.append(
sa.and_(
chronicles_models.Chronicle.__content_ts_vector__.match(w, postgresql_regconfig="french")
chronicles_models.Chronicle.__content_ts_vector__.op("@@")(sa.func.plainto_tsquery("french", w))
for w in form.q.data.split(" ")
if len(w) > 1
)
)
if form.search_type.data in (forms.SearchType.ALL.name, forms.SearchType.PRODUCT_NAME.name):
Expand Down
20 changes: 20 additions & 0 deletions api/tests/routes/backoffice/chronicles_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,26 @@ def test_search_by_content(self, authenticated_client):
assert len(rows) == 1
assert rows[0]["ID"] == str(chronicle_to_find.id)

def test_search_by_content_with_colon(self, authenticated_client):
chronicle_to_find = chronicles_factories.ChronicleFactory(
content="Deux hommes, et même dix, peuvent bien en craindre un",
)
chronicles_factories.ChronicleFactory()
with assert_num_queries(self.expected_num_queries):
response = authenticated_client.get(
url_for(
self.endpoint,
q="HomMe : bien",
research_type="CHRONICLE_CONTENT",
),
)
assert response.status_code == 200

rows = html_parser.extract_table_rows(response.data)

assert len(rows) == 1
assert rows[0]["ID"] == str(chronicle_to_find.id)

def test_search_by_product_name(self, authenticated_client):
product = offers_factories.ProductFactory(name="My super product")
chronicle_with_product = chronicles_factories.ChronicleFactory(products=[product])
Expand Down

0 comments on commit 4ca7740

Please sign in to comment.