DomGarguilo commented on code in PR #399: URL: https://github.com/apache/accumulo-website/pull/399#discussion_r1310223675
########## js/search.js: ########## @@ -1,48 +1,49 @@ -jQuery(function() { +jQuery(function () { - window.idx = lunr(function () { - this.field('id'); - this.field('title'); - this.field('content', { boost: 10 }); - this.field('categories'); - }); + $.getJSON('/search_data.json').then(function (loaded_data) { - window.data = $.getJSON('/search_data.json'); + window.idx = lunr(function () { + this.field('id'); + this.field('title'); + this.field('content', { boost: 10 }); + this.field('categories'); - window.data.then(function(loaded_data){ - $.each(loaded_data, function(index, value){ - window.idx.add($.extend({ "id": index }, value)); + for (var index in loaded_data) { + this.add($.extend({ "id": index }, loaded_data[index])); + } }); - }); - $("#site_search").submit(function(event){ + $("#site_search").submit(function (event) { event.preventDefault(); var query = $("#search_box").val(); var results = window.idx.search(query); - display_search_results(query, results); + display_search_results(query, results, loaded_data); + }); + }); - function display_search_results(query, results) { + function display_search_results(query, results, loaded_data) { var $search_status = $("#search_status"); var $search_results = $("#search_results"); - window.data.then(function(loaded_data) { - - if (results.length) { - $search_status.html('Found ' + results.length + ' results for "' + query + '"'); - $search_results.empty(); - results.forEach(function(result) { - var item = loaded_data[result.ref]; - var n = item.content.search(query) - 50 - if (n < 0) { - n = 0; - } - var appendString = '<tr><td><a href="' + item.url + '">' + item.title + '</a><td>' + item.content.substring(n, n+100) + '</tr>'; - $search_results.append(appendString); - }); - } else { - $search_status.html('No results found!'); + if (!results.length) { + $search_status.html('No results found!'); + return; + } + + $search_status.html('Found ' + results.length + ' results for "' + query + '"'); + $search_results.empty(); + $search_results.append('<tbody>'); Review Comment: I think I like that idea. I made those changes in e3082c1 and everything looks good. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@accumulo.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org