diff --git a/api/src/pcapi/routes/backoffice/chronicles/blueprint.py b/api/src/pcapi/routes/backoffice/chronicles/blueprint.py index 2165071bbf8..7327ab6c27e 100644 --- a/api/src/pcapi/routes/backoffice/chronicles/blueprint.py +++ b/api/src/pcapi/routes/backoffice/chronicles/blueprint.py @@ -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): diff --git a/api/tests/routes/backoffice/chronicles_test.py b/api/tests/routes/backoffice/chronicles_test.py index 0875f0e15eb..c4b69fc541d 100644 --- a/api/tests/routes/backoffice/chronicles_test.py +++ b/api/tests/routes/backoffice/chronicles_test.py @@ -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])