Skip to content
Snippets Groups Projects

Dos0091629

Merged Matthieu BENOIST requested to merge DOS0091629 into master
2 files
+ 62
8
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -348,6 +348,7 @@ export class DatasetResearchService {
@@ -348,6 +348,7 @@ export class DatasetResearchService {
getAutoComplete(text: string): Observable<SearchCompletion[]> {
getAutoComplete(text: string): Observable<SearchCompletion[]> {
const options: SearchCompletion[] = [];
const options: SearchCompletion[] = [];
 
const titleOptions : SearchCompletion[] = [];
return this._elasticsearchService.getAutoComplete(text).pipe(
return this._elasticsearchService.getAutoComplete(text).pipe(
map((e) => {
map((e) => {
// We will loop over all the hits, look if an highlight have been found,
// We will loop over all the hits, look if an highlight have been found,
@@ -364,18 +365,32 @@ export class DatasetResearchService {
@@ -364,18 +365,32 @@ export class DatasetResearchService {
// We check if this text highlight already exists in the options array
// We check if this text highlight already exists in the options array
// We want a unique text in the list, no duplicata.
// We want a unique text in the list, no duplicata.
const found = options.some((el) => {
const found = options.some((el) => {
return el.text === highlight[key][0];
return el.text.toLowerCase() === highlight[key][0].toLowerCase();
});
});
if (!found && options.length < 5) {
const same = text.toLowerCase() === highlight[key][0].toLowerCase().replace(/<[^>]*>/g, '');;
searchOption['text'] = highlight[key][0];
options.push(new SearchCompletion(searchOption));
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;
}),
}),
);
);
}
}
Loading