Remove keyword sorts

This commit is contained in:
Jimmy Cai 2021-12-28 23:22:38 +00:00 committed by GitHub
parent dda0beadcb
commit 8f8249e3ae

View File

@ -98,14 +98,9 @@ class Search {
const rawData = await this.getData(); const rawData = await this.getData();
let results: pageData[] = []; let results: pageData[] = [];
/// Sort keywords by their length
keywords.sort((a, b) => {
return b.length - a.length
});
for (const item of rawData) { for (const item of rawData) {
let titleMatches: match[] = [], let titleMatches: match[] = [],
bodyMatches: match[] = []; contentMatches: match[] = [];
let result = { let result = {
...item, ...item,
@ -132,7 +127,7 @@ class Search {
} }
if (contentMatch) { if (contentMatch) {
bodyMatches.push({ contentMatches.push({
start: contentMatch.index, start: contentMatch.index,
end: contentMatch.index + contentMatch[0].length end: contentMatch.index + contentMatch[0].length
}); });
@ -143,12 +138,11 @@ class Search {
result.title = Search.processMatches(result.title, titleMatches).join(''); result.title = Search.processMatches(result.title, titleMatches).join('');
} }
console.log(bodyMatches); if (contentMatches.length > 0) {
if (bodyMatches.length > 0) { result.preview = Search.processMatches(result.content, contentMatches).join('');
result.preview = Search.processMatches(result.content, bodyMatches).join('');
} }
if (titleMatches.length > 0 || bodyMatches.length > 0) { if (titleMatches.length > 0 || contentMatches.length > 0) {
results.push(result); results.push(result);
} }
} }