MCPcopy Create free account
hub / github.com/FastFlowLM/FastFlowLM / renderResults

Function renderResults

docs/script.js:286–337  ·  view source on GitHub ↗
(results, query)

Source from the content-addressed store, hash-verified

284 };
285
286 const renderResults = (results, query) => {
287 docsSearchResults.innerHTML = "";
288
289 if (!query || query.length < 2) {
290 hideResults();
291 return;
292 }
293
294 if (!results || results.length === 0) {
295 docsSearchResults.innerHTML =
296 '<div class="docs-search__empty">No matches found.</div>';
297 docsSearchResults.classList.add("is-visible");
298 return;
299 }
300
301 const fragment = document.createDocumentFragment();
302
303 results.forEach((page) => {
304 const item = document.createElement("a");
305 item.className = "docs-search__item";
306 item.href = page.url;
307
308 const titleEl = document.createElement("div");
309 titleEl.className = "docs-search__item-title";
310 titleEl.textContent = page.title;
311
312 const snippetEl = document.createElement("div");
313 snippetEl.className = "docs-search__item-snippet";
314
315 const content = page.content || "";
316 const lower = content.toLowerCase();
317 const idx = lower.indexOf(query.toLowerCase());
318
319 if (idx !== -1) {
320 const start = Math.max(0, idx - 40);
321 const end = Math.min(content.length, idx + query.length + 60);
322 let snippet = content.slice(start, end).trim();
323 if (start > 0) snippet = "…" + snippet;
324 if (end < content.length) snippet = snippet + "…";
325 snippetEl.textContent = snippet;
326 } else {
327 snippetEl.textContent = content.slice(0, 120).trim() + "…";
328 }
329
330 item.appendChild(titleEl);
331 item.appendChild(snippetEl);
332 fragment.appendChild(item);
333 });
334
335 docsSearchResults.appendChild(fragment);
336 docsSearchResults.classList.add("is-visible");
337 };
338
339 const loadIndex = async () => {
340 if (indexLoaded || indexLoading) return;

Callers 1

performSearchFunction · 0.85

Calls 1

hideResultsFunction · 0.85

Tested by

no test coverage detected