Fix #994: use PostgreSQL full-text-search

This commit is contained in:
Eliot Berriot 2019-12-16 17:46:32 +01:00
parent 8f0eabcb71
commit b3d8d6a4da
No known key found for this signature in database
GPG key ID: 6B501DFD73514E14
6 changed files with 148 additions and 5 deletions

View file

@ -1,5 +1,6 @@
import re
from django.contrib.postgres.search import SearchQuery
from django.db.models import Q
@ -56,6 +57,17 @@ def get_query(query_string, search_fields):
return query
def get_fts_query(query_string):
if not query_string.startswith('"') and not query_string.endswith('"'):
parts = query_string.split(" ")
parts = ["{}:*".format(p) for p in parts if p]
if not parts:
return Q(pk=None)
query_string = "&".join(parts)
return Q(body_text=SearchQuery(query_string, search_type="raw"))
def filter_tokens(tokens, valid):
return [t for t in tokens if t["key"] in valid]