- optimize search returing the longest match. For example "tes test" return the "test" match

This commit is contained in:
Massimo Maggioni 2021-12-29 22:30:32 +01:00
parent ec45bfaea4
commit e12a299fd9

View File

@ -56,6 +56,10 @@ class Search {
/// clean input keywords list
private cleanKeywords(keywords: string[]) {
/// Sort keywords by their length
keywords.sort((a, b) => {
return b.length - a.length
});
for (let i=0; i < keywords.length; i++){
/// remove the white spaces
keywords[i]=keywords[i].trim();
@ -73,7 +77,6 @@ class Search {
const rawData = await this.getData();
let results: pageData[] = [];
if (keywords.length === 0) return;
keywords = this.cleanKeywords(keywords);