From: Radek Czajka Date: Wed, 4 Nov 2026 00:17:24 +0000 (+0100) Subject: deploy fixes X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/ee795f5687da5bcebd40cda3dc1db80ffef7b05a?ds=sidebyside;hp=-c deploy fixes --- ee795f5687da5bcebd40cda3dc1db80ffef7b05a diff --git a/scripts/nginx.conf b/scripts/nginx.conf index 872f1a273..561a5d4e4 100644 --- a/scripts/nginx.conf +++ b/scripts/nginx.conf @@ -35,7 +35,7 @@ server { location /api/ { add_header 'Access-Control-Allow-Origin' '*' always; - add_header 'Access-Control-Allow-Methods' 'GE, POST, PUT, DELETE' always; + add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE' always; add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type' always; add_header 'Access-Control-Expose-Headers' 'Link' always; diff --git a/src/search/utils.py b/src/search/utils.py index 77ff1ae11..69263e707 100644 --- a/src/search/utils.py +++ b/src/search/utils.py @@ -1,31 +1,10 @@ from django.conf import settings -from django.db.models import Func -from django.contrib.postgres.search import SearchQuery, SearchVectorField +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) - if settings.SEARCH_USE_UNACCENT: - 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' - if settings.SEARCH_USE_UNACCENT: - template = f'''unaccent( - %(function)s('{settings.SEARCH_CONFIG}', %(expressions)s)::text)::tsvector || - to_tsvector( - '{settings.SEARCH_CONFIG_SIMPLE}', - unaccent(%(expressions)s) - )''' - output_field = SearchVectorField() +def UnaccentSearchVector(expression): + return SearchVector(expression, config=settings.SEARCH_CONFIG)