accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mwa...@apache.org
Subject [accumulo-website] branch master updated: Added search functionality to Accumulo website (#81)
Date Fri, 04 May 2018 19:08:28 GMT
This is an automated email from the ASF dual-hosted git repository.

mwalch pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/accumulo-website.git


The following commit(s) were added to refs/heads/master by this push:
     new b360e4c  Added search functionality to Accumulo website (#81)
b360e4c is described below

commit b360e4c3add1a7d94e7f1300139240de5c020be1
Author: Mike Walch <mwalch@apache.org>
AuthorDate: Fri May 4 15:08:25 2018 -0400

    Added search functionality to Accumulo website (#81)
    
    * Search results are limited to blog posts, release notes, and
      documentation for one Accumulo release
    * Search is implemented in browser using javascript and lunarjs
---
 _includes/nav.html |  1 +
 js/search.js       | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 pages/search.md    | 29 +++++++++++++++++++++++++++++
 search_data.json   | 22 ++++++++++++++++++++++
 4 files changed, 100 insertions(+)

diff --git a/_includes/nav.html b/_includes/nav.html
index 28c68d8..764499a 100644
--- a/_includes/nav.html
+++ b/_includes/nav.html
@@ -44,6 +44,7 @@
             <li><a href="{{ site.baseurl }}/related-projects">Related Projects</a></li>
           </ul>
         </li>
+        <li class="nav-link"><a href="{{ site.baseurl }}/search">Search</a></li>
       </ul>
       <ul class="nav navbar-nav navbar-right">
         <li class="dropdown">
diff --git a/js/search.js b/js/search.js
new file mode 100644
index 0000000..5501f85
--- /dev/null
+++ b/js/search.js
@@ -0,0 +1,48 @@
+jQuery(function() {
+
+  window.idx = lunr(function () {
+    this.field('id');
+    this.field('title');
+    this.field('content', { boost: 10 });
+    this.field('categories');
+  });
+
+  window.data = $.getJSON('/search_data.json');
+
+  window.data.then(function(loaded_data){
+    $.each(loaded_data, function(index, value){
+      window.idx.add($.extend({ "id": index }, value));
+    });
+  });
+
+  $("#site_search").submit(function(event){
+      event.preventDefault();
+      var query = $("#search_box").val();
+      var results = window.idx.search(query);
+      display_search_results(query, results);
+  });
+
+  function display_search_results(query, results) {
+    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!');
+      }
+    });
+  }
+});
diff --git a/pages/search.md b/pages/search.md
new file mode 100644
index 0000000..43b816a
--- /dev/null
+++ b/pages/search.md
@@ -0,0 +1,29 @@
+---
+title: Search
+permalink: /search/
+---
+
+Search results are limited to blog posts, release notes, and the 2.0 documentation.
+
+<div class="row">
+  <div class="col-lg-6">
+    <form action="get" id="site_search">
+      <div class="input-group">
+        <input class="form-control" type="text" id="search_box" placeholder="Search for...">
+        <span class="input-group-btn">
+          <button class="btn btn-default" type="button">Search</button>
+        </span>
+      </div>
+    </form>
+  </div>
+</div>
+
+<br/>
+
+<div id="search_status"></div>
+
+<table class="table table-striped" id="search_results"></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="/js/search.js"></script>
diff --git a/search_data.json b/search_data.json
new file mode 100644
index 0000000..91b0b62
--- /dev/null
+++ b/search_data.json
@@ -0,0 +1,22 @@
+---
+layout: null
+---
+{
+  {% for post in site.docs-2-0 %}
+    "{{ post.url | slugify }}": {
+      "title": "{{ post.title | xml_escape }}",
+      "content"	 : "{{post.content | strip_html | strip_newlines | remove:  "	" | escape
| remove: "\"}}",
+      "url": " {{ post.url | xml_escape }}",
+      "categories": "{% for category in post.categories %}{{ category }}{% unless forloop.last
%}, {% endunless %}{% endfor %}"
+    },
+  {% endfor %}
+  {% for post in site.posts %}
+    "{{ post.url | slugify }}": {
+      "title": "{{ post.title | xml_escape }}",
+      "content"	 : "{{post.content | strip_html | strip_newlines | remove:  "	" | escape
| remove: "\"}}",
+      "url": " {{ post.url | xml_escape }}",
+      "categories": "{% for category in post.categories %}{{ category }}{% unless forloop.last
%}, {% endunless %}{% endfor %}"
+    }
+    {% unless forloop.last %},{% endunless %}
+  {% endfor %}
+}

-- 
To stop receiving notification emails like this one, please contact
mwalch@apache.org.

Mime
View raw message