1document.addEventListener('DOMContentLoaded', function() { 2 let searchClient = algoliasearch(autocomplete_ajax_object.algolia_api_id, autocomplete_ajax_object.algolia_search_key); 3 let index = searchClient.initIndex(autocomplete_ajax_object.algolia_index_name); 4 let searchInputs = document.querySelectorAll('.ht-nav-search--box-text'); 5 6 let timeout; 7 searchInputs.forEach(function(searchInput){ 8 searchInput.addEventListener('input', function() { 9 let query = this.value; 10 11 // get the sibling .ht-nav-search-results inside the same parent 12 var resultsDiv = this.closest('.ht-nav-search--box').querySelector('.ht-nav-search-results'); 13 14 clearTimeout(timeout); 15 timeout = setTimeout(() => { 16 if (query.length > 1) { 17 searchProducts(query, resultsDiv); // pass it if needed 18 } else { 19 resultsDiv.innerHTML = ''; 20 } 21 }, 300); 22 }); 23 }); 24 25 function searchProducts(query, resultsDiv) { 26 index.search(query, { 27 hitsPerPage: 5 28 }).then(function(response) { 29 showResults(response.hits, resultsDiv); 30 }).catch(function(error) { 31 console.error('Search error:', error); 32 // resultsDiv.innerHTML = 'Search error'; 33 }); 34 } 35 36 function showResults(hits, resultsDiv) { 37 if (hits.length === 0) { 38 resultsDiv.innerHTML = 'No results found'; 39 return; 40 } 41 42 let html = ''; 43 hits.forEach(function(hit) { 44 html += ` 45 <a href="${hit.link}"> 46 <strong>${hit.title}</strong> 47 </a> 48 `; 49 }); 50 51 resultsDiv.innerHTML = html; 52 } 53});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.