Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions assets/js/flexsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,10 @@ document.addEventListener("DOMContentLoaded", function () {
}
resultsElement.classList.remove('hx:hidden');

const pageResults = window.pageIndex.search(query, 5, { enrich: true, suggest: true })[0]?.result || [];
// Configurable search limits with sensible defaults
const maxPageResults = parseInt('{{- site.Params.search.flexsearch.maxPageResults | default 20 -}}', 10);
const maxSectionResults = parseInt('{{- site.Params.search.flexsearch.maxSectionResults | default 10 -}}', 10);
const pageResults = window.pageIndex.search(query, maxPageResults, { enrich: true, suggest: true })[0]?.result || [];

const results = [];
const pageTitleMatches = {};
Expand All @@ -327,12 +330,13 @@ document.addEventListener("DOMContentLoaded", function () {
const result = pageResults[i];
pageTitleMatches[i] = 0;

// Show the top 5 results for each page
const sectionResults = window.sectionIndex.search(query, 5, { enrich: true, suggest: true, tag: { 'pageId': `page_${result.id}` } })[0]?.result || [];
const sectionResults = window.sectionIndex.search(query,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to pass the limit here as the second argument?

{ enrich: true, suggest: true, tag: { 'pageId': `page_${result.id}` } })[0]?.result || [];
let isFirstItemOfPage = true
const occurred = {}

for (let j = 0; j < sectionResults.length; j++) {
const nResults = Math.min(sectionResults.length, maxSectionResults);
for (let j = 0; j < nResults; j++) {
const { doc } = sectionResults[j]
const isMatchingTitle = doc.display !== undefined
if (isMatchingTitle) {
Expand Down