From: Mathieu Date: Sun, 3 Apr 2016 16:11:11 +0000 (+0200) Subject: Fix contains + ngram_field X-Git-Tag: 1.6.2^2~15^2~10^2~28 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=760014f708b7100a3017ede6636a95a9048c1eb2;p=telemeta.git Fix contains + ngram_field --- diff --git a/app/deploy/app.sh b/app/deploy/app.sh index ddfba3f7..37b13b9f 100644 --- a/app/deploy/app.sh +++ b/app/deploy/app.sh @@ -27,6 +27,9 @@ sh $app/deploy/wait.sh # waiting for available database python $app/wait.py +#fix contains haystack elasticsearch +cd /opt/miniconda/lib/python2.7/site-packages/haystack/backends && sed -i "s/'contains': u'%s'/'contains': u'*%s*'/g" elasticsearch_backend.py && cd $app + # django init python $manage syncdb --noinput python $manage migrate --noinput @@ -34,6 +37,7 @@ python $manage bower_install -- --allow-root python $manage collectstatic --noinput python $manage telemeta-create-admin-user python $manage telemeta-create-boilerplate +python $manage rebuild_index --noinput if [ $DEBUG = "False" ] then diff --git a/app/sandbox/settings.py b/app/sandbox/settings.py index c31f79c7..080ccb03 100644 --- a/app/sandbox/settings.py +++ b/app/sandbox/settings.py @@ -302,7 +302,7 @@ from worker import app HAYSTACK_CONNECTIONS = { 'default': { - 'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine', + 'ENGINE': 'telemeta.util.backend.CustomElasticEngine', 'URL': 'http://search:9200/', 'INDEX_NAME': 'haystack', 'INLUDE_SPELLING': True, diff --git a/telemeta/forms/haystack_form.py b/telemeta/forms/haystack_form.py index 49017cff..99a6b74f 100644 --- a/telemeta/forms/haystack_form.py +++ b/telemeta/forms/haystack_form.py @@ -27,7 +27,6 @@ from haystack.query import SearchQuerySet from datetime import date from django.utils.translation import ugettext_lazy as _ - class HaySearchForm(FacetedSearchForm): q = forms.CharField(required=False, widget=forms.TextInput(attrs={'class': 'form-control', 'type' : 'text'})) diff --git a/telemeta/util/backend.py b/telemeta/util/backend.py new file mode 100644 index 00000000..8c882536 --- /dev/null +++ b/telemeta/util/backend.py @@ -0,0 +1,13 @@ +from haystack.backends.elasticsearch_backend import * + +class CustomElasticBackend(ElasticsearchSearchBackend): + + def setup(self): + FIELD_MAPPINGS.get('edge_ngram')['search_analyzer']="standard"; + FIELD_MAPPINGS.get('ngram')['search_analyzer']="standard"; + eb = super(CustomElasticBackend, self) + eb.DEFAULT_SETTINGS.get('settings').get('analysis').get('filter').get('haystack_ngram')['max_gram']=30 + eb.setup() + +class CustomElasticEngine(ElasticsearchSearchEngine): + backend = CustomElasticBackend \ No newline at end of file