From 430586c9e26c2b915d0aa49d8f5378ca94977d0e Mon Sep 17 00:00:00 2001 From: Alessandro Cerioni <acerioni@grandlyon.com> Date: Thu, 25 Oct 2018 07:59:32 +0200 Subject: [PATCH] Improved phrase suggestion. --- .../services/elasticsearch.service.ts | 18 +++++++++++------- src/environments/environment.ts | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/app/geosource/services/elasticsearch.service.ts b/src/app/geosource/services/elasticsearch.service.ts index 2b2ff4d2..cab37974 100644 --- a/src/app/geosource/services/elasticsearch.service.ts +++ b/src/app/geosource/services/elasticsearch.service.ts @@ -283,8 +283,8 @@ export class ElasticsearchService { } /* - * This request will get one suggestion from the query text - * The suggest is based on metadata-fr.title property + * This request will get one phrase suggestion out of the query text + * cf. https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-phrase.html */ getSuggestion(query: string): Observable<SearchSuggestion> { return this._http.request<IElasticsearchResponse>('POST', this.url, { @@ -293,16 +293,20 @@ export class ElasticsearchService { text: query, suggestion: { phrase: { - field: 'data_and_metadata', + field: 'data_and_metadata.suggest', + // as only the very first suggestion will be used, let's limit the size of the results to 1: + size: 1, + max_errors: query.split(' ').length, highlight: { pre_tag: '<b><i>', post_tag: '</i></b>', }, + analyzer: 'my_search_analyzer', direct_generator: [{ - field: 'data_and_metadata', - suggest_mode: 'popular', - // prefix_length: 4, - min_word_length: 1, + field: 'data_and_metadata.suggest', + suggest_mode: 'missing', + prefix_length: 1, + min_word_length: 4, }], }, }, diff --git a/src/environments/environment.ts b/src/environments/environment.ts index f32fb6a4..57e69081 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -11,7 +11,7 @@ export const environment = { // ElasticSearch elasticsearchUrl: { - full: servicesProxyUrl + '/elasticsearch2/test-all-in-one-index.full.v8.quadtree', + full: servicesProxyUrl + '/elasticsearch2/test-all-in-one-index.full.v9.quadtree', meta: servicesProxyUrl + '/elasticsearch/*.meta', }, -- GitLab