X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/801a05d2ff33bb8a3c1a46ea0c657825b2787fa7..refs/heads/f-docker-config:/src/search/utils.py diff --git a/src/search/utils.py b/src/search/utils.py index 6c0acf594..69263e707 100644 --- a/src/search/utils.py +++ b/src/search/utils.py @@ -1,28 +1,10 @@ -from django.db.models import Func -from django.contrib.postgres.search import SearchQuery, SearchVectorField +from django.conf import settings +from django.contrib.postgres.search import SearchQuery, SearchVector -class UnaccentSearchQuery(SearchQuery): - ''' - The idea is to run unaccent *after* the query is already passed through the language dictionary. - ''' - def as_sql(self, *args, **kwargs): - sql, params = super().as_sql(*args, **kwargs) - sql = f'unaccent({sql}::text)::tsquery' - return sql, params +# Deprecated +UnaccentSearchQuery = SearchQuery -class UnaccentSearchVector(Func): - ''' - We do the indexing twice, to account for non-diacritic versions. - For example: user enters 'róże' -> stem to 'róża' -> unaccent to 'roza'. - But user enters 'roze' -> stem leaves it as is, so we need original form in the vector. - ''' - function='to_tsvector' - template = '''unaccent( - %(function)s('polish', %(expressions)s)::text)::tsvector || - to_tsvector( - 'polish_simple', - unaccent(%(expressions)s) - )''' - output_field = SearchVectorField() +def UnaccentSearchVector(expression): + return SearchVector(expression, config=settings.SEARCH_CONFIG)