mirror of
https://github.com/CaiJimmy/hugo-theme-stack.git
synced 2025-04-29 20:13:31 +08:00
- optimize search returing the longest match. For example "tes test" return the "test" match
This commit is contained in:
parent
ec45bfaea4
commit
e12a299fd9
@ -56,6 +56,10 @@ class Search {
|
|||||||
|
|
||||||
/// clean input keywords list
|
/// clean input keywords list
|
||||||
private cleanKeywords(keywords: string[]) {
|
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++){
|
for (let i=0; i < keywords.length; i++){
|
||||||
/// remove the white spaces
|
/// remove the white spaces
|
||||||
keywords[i]=keywords[i].trim();
|
keywords[i]=keywords[i].trim();
|
||||||
@ -73,7 +77,6 @@ class Search {
|
|||||||
const rawData = await this.getData();
|
const rawData = await this.getData();
|
||||||
let results: pageData[] = [];
|
let results: pageData[] = [];
|
||||||
|
|
||||||
|
|
||||||
if (keywords.length === 0) return;
|
if (keywords.length === 0) return;
|
||||||
keywords = this.cleanKeywords(keywords);
|
keywords = this.cleanKeywords(keywords);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user