${escapeSearchFilterText(group)}
${itemsHtml}
`;
}).join('');
wrapper.addEventListener('change', function () {
const values = Array.from(wrapper.querySelectorAll('input[type="checkbox"]:checked')).map(input => input.value);
setSelectedSearchProfiles(values);
refreshGlobalSearchResults();
});
}
formContainer.parentNode.insertBefore(wrapper, formContainer.nextSibling);
}
const __cqSearchFilterObserver = new MutationObserver(ensureTopSearchProfileFilters);
try {
__cqSearchFilterObserver.observe(document.body, { childList: true, subtree: true });
} catch (e) {}
async function fetchSearchSections(query) {
const queryRaw = String(query || '').trim();
const queryTerms = tokenizeSearchQuery(queryRaw);
const queryKey = queryTerms.join(' ');
if (!queryKey || queryKey.length < CQ_SEARCH_MIN_CHARS) {
if (__cqSearchController) { try { __cqSearchController.abort(); } catch (e) {} }
__cqSearchInFlight = null;
return buildEmptySections();
}
const cacheKey = getSearchCacheKey(queryKey);
if (__cqSearchResultCache.has(cacheKey)) {
const cached = __cqSearchResultCache.get(cacheKey);
touchSearchCache(cacheKey, cached);
return cached;
}
if (__cqSearchInFlight && __cqSearchInFlight.query === queryKey) {
return __cqSearchInFlight.promise;
}
const client_accounting = "";
let url = '/portal/files/search-vertical.json?ticket=' + ticket + '&search=' + encodeURIComponent(queryKey);
if (client_accounting) {url += '&client_accounting=' + encodeURIComponent(client_accounting)};
if (Array.isArray(CQ_SEARCH_PROFILE_FILTERS) && CQ_SEARCH_PROFILE_FILTERS.length) {
const selectedProfiles = getSelectedSearchProfiles();
url += '&profiles=' + encodeURIComponent(selectedProfiles.length ? selectedProfiles.join(',') : '__none');
}
if (__cqSearchController) { try { __cqSearchController.abort(); } catch (e) {} }
__cqSearchController = new AbortController();
const mySeq = ++__cqSearchSeq;
const promise = (async () => {
try {
const response = await fetch(url, { signal: __cqSearchController.signal });
if (mySeq !== __cqSearchSeq) return buildEmptySections(); // ignore out-of-order results
if (!response.ok) return buildEmptySections();
const bundle = await response.json();
const sectionResults = buildSectionResults(bundle || {}, queryTerms);
touchSearchCache(cacheKey, sectionResults);
return sectionResults;
} catch (e) {
return buildEmptySections();
} finally {
if (__cqSearchInFlight && __cqSearchInFlight.query === queryKey) {
__cqSearchInFlight = null;
}
}
})();
__cqSearchInFlight = { query: queryKey, promise };
return promise;
}
const fetchSearchSectionsDebounced = debounceAsync(fetchSearchSections, CQ_SEARCH_DEBOUNCE_MS);
function getSectionItems(sectionKey) {
return async function ({ query }) {
const sections = await fetchSearchSectionsDebounced(query);
return sections[sectionKey] || [];
};
}
let __cqSearchScrollbarRaf = 0;
function scheduleSearchScrollbarUpdate() {
if (__cqSearchScrollbarRaf) return;
__cqSearchScrollbarRaf = window.requestAnimationFrame(() => {
__cqSearchScrollbarRaf = 0;
try { window.autoCompletePS?.update(); } catch (e) {}
});
}
function renderSearchItem(item, html) {
const hasImage = item.src && item.src.trim().length > 0;
const initials = String(item.name || '')
.split(/\s+/)
.filter(Boolean)
.slice(0, 2)
.map(part => part.charAt(0).toUpperCase())
.join('');
return html`