From: mathieu Date: Tue, 26 Apr 2016 15:10:36 +0000 (+0200) Subject: Revue du mapping ES (utilisation startswith +coherent) X-Git-Tag: 1.6.2^2~15^2~8^2~1 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=3cd34ac3114be3a1d205f1e3ba9eb7e2e189dcd4;p=telemeta.git Revue du mapping ES (utilisation startswith +coherent) --- diff --git a/env/debug.env b/env/debug.env index a19e3477..7a9fbbcc 100644 --- a/env/debug.env +++ b/env/debug.env @@ -18,4 +18,4 @@ BROKER_URL=redis://broker:6379/0 # If this is True, all tasks will be executed locally by blocking until the task returns. CELERY_ALWAYS_EAGER=False -REINDEX=False +REINDEX=True diff --git a/telemeta/forms/haystack_form.py b/telemeta/forms/haystack_form.py index adb39e00..ceace2d8 100644 --- a/telemeta/forms/haystack_form.py +++ b/telemeta/forms/haystack_form.py @@ -193,13 +193,13 @@ class HayAdvanceForm(SearchForm): return self.no_query_found() if self.cleaned_data.get('q'): - sqs = sqs.filter(title__contains=self.cleaned_data['q']) + sqs = sqs.filter(title__startswith=self.cleaned_data['q']) if self.cleaned_data.get('code'): sqs = sqs.filter(code__contains=self.cleaned_data['code']) if self.cleaned_data.get('location'): - sqs = sqs.filter(location_principal__contains=self.cleaned_data['location']).filter_or(location_relation__contains=self.cleaned_data['location']) + sqs = sqs.filter(location_principal__startswith=self.cleaned_data['location']).filter_or(location_relation__startswith=self.cleaned_data['location']) if self.cleaned_data['ethnic_group']: if self.cleaned_data.get('ethnic_group') != '': diff --git a/telemeta/util/backend.py b/telemeta/util/backend.py index 489a61d1..374bd19c 100644 --- a/telemeta/util/backend.py +++ b/telemeta/util/backend.py @@ -5,11 +5,10 @@ from haystack.backends.elasticsearch_backend import * class CustomElasticBackend(ElasticsearchSearchBackend): def setup(self): - - DEFAULT_FIELD_MAPPING['analyzer']='space_lower_analyzer' + DEFAULT_FIELD_MAPPING['analyzer']='snowball_asciifolding_analyzer' eb = super(CustomElasticBackend, self) - eb.DEFAULT_SETTINGS.get('settings').get('analysis').get('analyzer')['space_lower_analyzer']=\ - {"type": "custom", "tokenizer": "whitespace", "filter": ["lowercase", "asciifolding"]} + eb.DEFAULT_SETTINGS.get('settings').get('analysis').get('analyzer')['snowball_asciifolding_analyzer']=\ + {"type": "custom", "tokenizer": "letter", "filter": ["lowercase", "stop", "asciifolding"]} eb.setup() @@ -29,5 +28,5 @@ class CustomElasticSearchQuery(ElasticsearchSearchQuery): class CustomElasticEngine(ElasticsearchSearchEngine): backend = CustomElasticBackend - query = CustomElasticSearchQuery# + query = CustomElasticSearchQuery diff --git a/telemeta/views/search.py b/telemeta/views/search.py index 26011183..10801655 100644 --- a/telemeta/views/search.py +++ b/telemeta/views/search.py @@ -177,7 +177,7 @@ def autocomplete(request): suggestions = [result.code for result in sqs] elif request.GET.get('attr', '') == "collectors": - sqs = sqs.filter(collectors__contains=request.GET.get('q', ''))[:10] + sqs = sqs.filter(collectors__startswith=request.GET.get('q', ''))[:10] suggestions = [result.collectors for result in sqs] else: suggestions = [] @@ -252,5 +252,5 @@ class BooleanSearchView(object): -class Erreur(Exception): - pass \ No newline at end of file +class Erreur(Exception):# + pass# \ No newline at end of file