search contains

This commit is contained in:
d42 2018-04-28 00:06:06 +02:00
parent cbe2cce61b
commit 8538821c24
1 changed files with 3 additions and 4 deletions

View File

@ -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