From e55361d4768c0a58f539bac995053a857b40f226 Mon Sep 17 00:00:00 2001 From: Jacky Zhao Date: Sun, 31 Oct 2021 09:59:38 -0700 Subject: [PATCH] search patch --- layouts/partials/search.html | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/layouts/partials/search.html b/layouts/partials/search.html index 06a71dc4..62556a4c 100644 --- a/layouts/partials/search.html +++ b/layouts/partials/search.html @@ -177,10 +177,16 @@ limit: 5, } ]).then(searchResults => { - const titleIds = [...searchResults.filter(x => x.field === 'title')?.[0].result] ?? [] - const contentIds = [...searchResults.filter(x => x.field === 'content')?.[0].result] ?? [] - const allIds = [...titleIds, ...contentIds] - const finalResults = allIds.map(fetch) + const getByField = field => { + const results = searchResults.filter(x => x.field === field) + if (results.length === 0) { + return [] + } else { + return [...results[0].result] + } + } + const allIds = [...getByField('title'), ...getByField('content')] + const finalResults = allIds.map(fetch) // display if (finalResults.length === 0) {