Resolve "Switch to proper full-text-search system"

This commit is contained in:
Eliot Berriot 2019-12-18 15:08:58 +01:00
parent 8556f137b1
commit 20311344d7
7 changed files with 159 additions and 8 deletions

View file

@ -84,11 +84,21 @@ def get_fts_query(query_string, fts_fields=["body_text"], model=None):
fk_field = model._meta.get_field(fk_field_name)
related_model = fk_field.related_model
subquery = related_model.objects.filter(
**{lookup: SearchQuery(query_string, search_type="raw")}
**{
lookup: SearchQuery(
query_string, search_type="raw", config="english_nostop"
)
}
).values_list("pk", flat=True)
new_query = Q(**{"{}__in".format(fk_field_name): list(subquery)})
else:
new_query = Q(**{field: SearchQuery(query_string, search_type="raw")})
new_query = Q(
**{
field: SearchQuery(
query_string, search_type="raw", config="english_nostop"
)
}
)
query = utils.join_queries_or(query, new_query)
return query