postgresql - Django psql full text search not matching un-stemmed word -
i'm running django 1.10.1 against postgres 9.4. staging server , dev environments have psql servers @ version 9.4.9 , production rds instance @ 9.4.7.
it seems searchvectorfield not storing search configuration given in production, though in staging , dev, , seems either version thing (unlikely, given version difference , worked on 9.3 in staging/dev) or fact production on rds instead of local on server.
i'm using custom configuration full-text search called unaccent
, looks this:
token | dictionaries -----------------+----------------------- asciihword | english_stem asciiword | english_stem email | simple file | simple float | simple host | simple hword | unaccent,english_stem hword_asciipart | english_stem hword_numpart | simple hword_part | unaccent,english_stem int | simple numhword | simple numword | simple sfloat | simple uint | simple url | simple url_path | simple version | simple word | unaccent,english_stem
unaccent installed in both environments, , works in both environments.
i'm storing search data in django.contrib.postgres.search.searchvectorfield
on writer
model:
class writer(models.model): #... search = searchvectorfield(blank=true)
that column updated following search vector:
writer_search_vector = (searchvector('first_name', 'last_name', 'display_name', config='unaccent', weight='a') + searchvector('raw_search_data', config='unaccent', weight='b'))
by following statement, runs periodically:
writer.objects.update(search=search_utils.writer_search_vector)
and, reason, configuration storing on staging server , in dev, not in production. e.g., code returns same results in environments:
in [3]: writer.objects.annotate(searchy=searchvector('last_name')).filter(searchy='kostenberger') out[3]: <queryset []> in [4]: writer.objects.annotate(searchy=searchvector('last_name', config='unaccent')).filter(searchy='kostenberger') out[4]: <queryset [<writer: andreas j. köstenberger>, <writer: margaret elizabeth köstenberger>]>
but in staging, following correct result if use stored vector:
in [5]: writer.objects.filter(search='kostenberger') out[5]: <queryset [<writer: andreas j. köstenberger>, <writer: margaret elizabeth köstenberger>]>
while in production, against rds instance, following, incorrect result:
in [5]: writer.objects.filter(search='kostenberger') out[5]: <queryset []>
and yet, in production still, unaccent works english_stem not, in match stemmed version of text (below), not original version (above):
in [6]: writer.objects.filter(search='kostenberg') out[6]: <queryset [<writer: margaret elizabeth köstenberger>, <writer: andreas j. köstenberger>]>
note database tables writer in 2 environments identical test.
any ideas why stored vector isn't working in production correct config, while if create vector on fly work?
on rds postgres, aren't allowed change default_text_search_config
parameter. so, have configure text search each query:
from django.contrib.postgres.search import searchrank, searchquery … search_query = searchquery(value='kostenberger', config='unaccent') writer.objects.filter(search=search_query)
Comments
Post a Comment