Skip to content
Snippets Groups Projects
Commit 81c591b2 authored by Matthieu BENOIST's avatar Matthieu BENOIST
Browse files

Merge branch 'DOS0091629' into 'master'

Dos0091629

See merge request !125
parents 0f4a1128 89097850
Branches
Tags
1 merge request!125Dos0091629
Pipeline #12491 canceled
......@@ -348,6 +348,7 @@ export class DatasetResearchService {
getAutoComplete(text: string): Observable<SearchCompletion[]> {
const options: SearchCompletion[] = [];
const titleOptions : SearchCompletion[] = [];
return this._elasticsearchService.getAutoComplete(text).pipe(
map((e) => {
// We will loop over all the hits, look if an highlight have been found,
......@@ -364,18 +365,32 @@ export class DatasetResearchService {
// We check if this text highlight already exists in the options array
// We want a unique text in the list, no duplicata.
const found = options.some((el) => {
return el.text === highlight[key][0];
return el.text.toLowerCase() === highlight[key][0].toLowerCase();
});
if (!found && options.length < 5) {
searchOption['text'] = highlight[key][0];
options.push(new SearchCompletion(searchOption));
const same = text.toLowerCase() === highlight[key][0].toLowerCase().replace(/<[^>]*>/g, '');;
if (!same && !found ) {
if (key === 'metadata-fr.title' || key === 'content-fr.title') {
searchOption['text'] = highlight[key][0];
titleOptions.push(new SearchCompletion(searchOption));
}
else {
searchOption['text'] = highlight[key][0];
options.push(new SearchCompletion(searchOption));
}
}
});
}
});
}
return options;
const results = titleOptions.concat(options);
if (results.length > 5) {
results.length = 5;
}
return results;
}),
);
}
......
......@@ -192,6 +192,9 @@ export class ElasticsearchService {
],
},
},
collapse: {
field: 'uuid.keyword',
},
highlight: {
order: 'score',
pre_tags: ['<b>'],
......@@ -199,15 +202,26 @@ export class ElasticsearchService {
highlight_query: {
query_string: {
query: regex,
fields: ['data_and_metadata', 'content-fr.title', 'content-fr.plaintext'],
fields: [
'metadata-fr.title^7',
'data-fr.properties^4',
'metadata-fr.abstract^6',
'metadata-fr.keyword^5',
'metadata-fr.lineage^4',
'content-fr.title^5',
'content-fr.excerpt^3',
'content-fr.plaintext^3'
],
analyzer: 'my_search_analyzer',
// fields: ['data_and_metadata', 'content-fr.title', 'content-fr.plaintext'],
// analyzer: 'my_search_analyzer',
fuzziness: 'AUTO',
minimum_should_match: '90%',
},
},
// Rules to construct the highlight fragments
fields: {
'*data-fr.*': {
'data-fr.*': {
fragment_size: 50,
fragmenter: 'span',
type: 'unified',
......@@ -220,6 +234,20 @@ export class ElasticsearchService {
fragment_size: 50,
number_of_fragments: 5,
},
'metadata-fr.title': {
number_of_fragments: 0,
},
'metadata-fr.keyword': {
number_of_fragments: 0,
},
'metadata-fr.abstract': {
fragment_size: 50,
number_of_fragments: 5,
},
'metadata-fr.lineage': {
fragment_size: 50,
number_of_fragments: 5,
},
},
},
};
......@@ -227,10 +255,21 @@ export class ElasticsearchService {
request.query.bool.must.push({
multi_match: {
query: regex,
fields: ['content-fr.title', 'content-fr.plaintext', 'data_and_metadata'],
fields: [
'metadata-fr.title^7',
'data-fr.properties^4',
'metadata-fr.abstract^6',
'metadata-fr.keyword^5',
'metadata-fr.lineage^4',
'content-fr.title^5',
'content-fr.excerpt^3',
'content-fr.plaintext^3'
],
},
});
console.log(request);
return this._http.request<IElasticsearchResponse>('POST', this.elasticSearchUrl, {
body: request,
withCredentials: true,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment