1jQuery(function() { 2 // Initalize lunr with the fields it will be searching on. I've given title 3 // a boost of 10 to indicate matches on this field are more important. 4 window.idx = lunr(function () { 5 this.field('id'); 6 this.field('title', { boost: 10 }); 7 this.field('author'); 8 this.field('category'); 9 }); 10 11 // Download the data from the JSON file we generated 12 window.data = $.getJSON('/css/search_data.json'); 13 14 // Wait for the data to load and add it to lunr 15 window.data.then(function(loaded_data){ 16 $.each(loaded_data, function(index, value){ 17 window.idx.add( 18 $.extend({ "id": index }, value) 19 ); 20 }); 21 }); 22 23 // Event when search action triggered 24 $("#site_search_do").click(function(){ 25 var query = $("#search_box").val(); // Get the value for the text field 26 var results = window.idx.search(query); // Get lunr to perform a search 27 display_search_results(results); // Hand the results off to be displayed 28 }); 29 30 $("#search_box").keydown(function(e) { 31 if (e.which == 13) { 32 $("#site_search_do").click(); 33 return false; 34 } 35 }) 36 37 function display_search_results(results) { 38 var $search_results = $("#search_results"); 39 40 // Wait for data to load 41 window.data.then(function(loaded_data) { 42 43 // Are there any results? 44 if (results.length) { 45 $search_results.empty(); // Clear any old results 46 47 // Iterate over the results 48 results.forEach(function(result) { 49 var item = loaded_data[result.ref]; 50 51 // Build a snippet of HTML for this result 52 var appendString = '<li><a href="' + item.url + '">' + item.title + '</a></li>'; 53 54 // Add it to the results 55 $search_results.append(appendString); 56 }); 57 } else { 58 $search_results.html('<li>No results found</li>'); 59 } 60 }); 61 } 62});
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.