This is an automated email from the ASF dual-hosted git repository. domgarguilo pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/accumulo-website.git
The following commit(s) were added to refs/heads/main by this push: new 53eb13d2 Update search page dependencies (#399) 53eb13d2 is described below commit 53eb13d24aa9f99757f4e0d6891fb82d54044f12 Author: Dom G <domgargu...@apache.org> AuthorDate: Wed Aug 30 08:49:38 2023 -0400 Update search page dependencies (#399) * Update search page dependencies --------- Co-authored-by: Christopher Tubbs <ctubb...@apache.org> --- js/search.js | 61 ++++++++++++++++++++++++++++----------------------------- pages/search.md | 5 ++--- 2 files changed, 32 insertions(+), 34 deletions(-) diff --git a/js/search.js b/js/search.js index 5501f85a..2c6b1076 100644 --- a/js/search.js +++ b/js/search.js @@ -1,48 +1,47 @@ -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(); + 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); }); + } }); diff --git a/pages/search.md b/pages/search.md index 08262b8d..ed8608a9 100644 --- a/pages/search.md +++ b/pages/search.md @@ -22,8 +22,7 @@ Search results are limited to blog posts, release notes, and the 2.x documentati <div id="search_status"></div> -<table class="table table-striped" id="search_results"></table> +<table class="table table-striped"><tbody id="search_results"></tbody></table> -<script src="https://cdnjs.cloudflare.com/ajax/libs/lunr.js/1.0.0/lunr.min.js"></script> -<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> +<script src="https://unpkg.com/lunr@2.3.9/lunr.min.js"></script> <script src="/js/search.js"></script>