summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authord42 <d42@users.noreply.github.com>2018-04-28 00:06:06 +0200
committerd42 <d42@users.noreply.github.com>2018-04-28 00:10:33 +0200
commit8538821c2481a9101e9e9e29058dac6f1770bb22 (patch)
treee51b770d702083407c14c608141f2ae6482c7ab0
parentcbe2cce61bb86a4a6bcf6002ccbc6ac83e04f549 (diff)
downloadspejstore-8538821c2481a9101e9e9e29058dac6f1770bb22.tar.gz
spejstore-8538821c2481a9101e9e9e29058dac6f1770bb22.tar.bz2
spejstore-8538821c2481a9101e9e9e29058dac6f1770bb22.zip
search contains
-rw-r--r--storage/views.py7
1 files changed, 3 insertions, 4 deletions
diff --git a/storage/views.py b/storage/views.py
index 2b62122..dafe2b4 100644
--- a/storage/views.py
+++ b/storage/views.py
@@ -6,6 +6,7 @@ from django.http import Http404, JsonResponse
from django.contrib.admin.models import LogEntry
from django_select2.views import AutoResponseView
from django.db import connection
+from django.db.models import Q
from storage.models import Item, Label
@@ -41,15 +42,13 @@ def apply_smart_search(query, objects):
if not general_term:
return objects
- objects = objects.annotate(
- search=SearchVector('name', 'description', 'props', config='simple'),
- )
general_term = ' '.join(general_term)
objects = objects.annotate(
+ search=SearchVector('name', 'description', 'props', config='simple'),
similarity=TrigramSimilarity('name', general_term)
).filter(
- similarity__gte=0.15
+ Q(similarity__gte=0.15) | Q(search__contains=general_term)
).order_by('-similarity')
return objects