foundation for user configurable search paramaters

This commit is contained in:
smilerz
2021-05-29 20:14:35 -05:00
parent 51cda4c2ff
commit 48f5642e04
5 changed files with 109 additions and 79 deletions

View File

@ -2,8 +2,10 @@ from django.conf import settings
from django.contrib.postgres.search import SearchVector
from django.core.management.base import BaseCommand
from django_scopes import scopes_disabled
from django.utils import translation
from django.utils.translation import gettext_lazy as _
from cookbook.managers import DICTIONARY
from cookbook.models import Recipe, Step
@ -16,12 +18,13 @@ class Command(BaseCommand):
self.stdout.write(self.style.WARNING(_('Only Postgress databases use full text search, no index to rebuild')))
try:
language = DICTIONARY.get(translation.get_language(), 'simple')
with scopes_disabled():
Recipe.objects.all().update(
name_search_vector=SearchVector('name__unaccent', weight='A'),
desc_search_vector=SearchVector('description__unaccent', weight='B')
name_search_vector=SearchVector('name__unaccent', weight='A', config=language),
desc_search_vector=SearchVector('description__unaccent', weight='B', config=language)
)
Step.objects.all().update(search_vector=SearchVector('instruction__unaccent', weight='B'))
Step.objects.all().update(search_vector=SearchVector('instruction__unaccent', weight='B', config=language))
self.stdout.write(self.style.SUCCESS(_('Recipe index rebuild complete.')))
except: