Commit 0c25370f authored by Agate's avatar Agate 💬
Browse files

Fix #1196: Fixed broken search when using (, " or & chars

parent 6bd77f24
......@@ -60,9 +60,11 @@ def get_query(query_string, search_fields):
def get_fts_query(query_string, fts_fields=["body_text"], model=None):
search_type = "plain"
if query_string.startswith('"') and query_string.endswith('"'):
# we pass the query directly to the FTS engine
query_string = query_string[1:-1]
search_type = "raw"
else:
parts = query_string.replace(":", "").split(" ")
parts = ["{}:*".format(p) for p in parts if p]
......@@ -86,7 +88,7 @@ def get_fts_query(query_string, fts_fields=["body_text"], model=None):
subquery = related_model.objects.filter(
**{
lookup: SearchQuery(
query_string, search_type="raw", config="english_nostop"
query_string, search_type=search_type, config="english_nostop"
)
}
).values_list("pk", flat=True)
......@@ -95,7 +97,7 @@ def get_fts_query(query_string, fts_fields=["body_text"], model=None):
new_query = Q(
**{
field: SearchQuery(
query_string, search_type="raw", config="english_nostop"
query_string, search_type=search_type, config="english_nostop"
)
}
)
......
......@@ -1374,23 +1374,6 @@ def test_search_get_fts_advanced(logged_in_api_client, factories):
assert response.data == expected
def test_search_get_fts_stop_words(logged_in_api_client, factories):
artist = factories["music.Artist"](name="she")
factories["music.Artist"](name="something else")
url = reverse("api:v1:search")
expected = {
"artists": [serializers.ArtistWithAlbumsSerializer(artist).data],
"albums": [],
"tracks": [],
"tags": [],
}
response = logged_in_api_client.get(url, {"q": "sh"})
assert response.status_code == 200
assert response.data == expected
@pytest.mark.parametrize(
"route, factory_name",
[
......
Fixed broken search when using (, " or & chars (#1196)
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment