mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-05 04:29:23 +02:00
Fix #994: use PostgreSQL full-text-search
This commit is contained in:
parent
8f0eabcb71
commit
b3d8d6a4da
6 changed files with 148 additions and 5 deletions
|
@ -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]
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue