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