Skip to content

Commit

Permalink
Update search-results.js
Browse files Browse the repository at this point in the history
  • Loading branch information
kailasnadh790 committed Mar 29, 2024
1 parent 69ee8f1 commit a781465
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cigaradvisor/blocks/search-results/search-results.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function filterData(searchTerms, data) {

searchTerms.forEach((term) => {
// eslint-disable-next-line max-len
const idx = (result.heading || result.title || result.description).toLowerCase().indexOf(term);
const idx = (result.heading || result.title || result.path.split('/').pop() || result.description).toLowerCase().indexOf(term);
if (idx < 0) return;
if (minIdx < idx) minIdx = idx;
});
Expand Down Expand Up @@ -54,7 +54,14 @@ async function handleSearch(searchValue, wrapper, limit) {
wrapper.prepend(searchSummary);
return;
}
const searchTerms = searchValue.toLowerCase().split(/\s+/).filter((term) => (!!term && term.length > 2));
const searchTerms = searchValue.toLowerCase().split(/\s+/).filter((term) => (!!term));
for (let i = 0; i < searchTerms.length; i += 1) {
if (searchTerms[i].length < 3) {
if (i + 1 < searchTerms.length) {
searchTerms[i] = `${searchTerms[i]} ${searchTerms[i + 1]}`;
}
}
}
const data = await getSearchIndexData();
const filteredData = filterData(searchTerms, data);

Expand Down

0 comments on commit a781465

Please sign in to comment.