MihaiValentin / lunr-languages

A collection of languages stemmers and stopwords for Lunr Javascript library
Other
431 stars 163 forks source link

How to do use it in jekyll blog? #18

Open yefeiyu opened 8 years ago

yefeiyu commented 8 years ago

I finished jekyll-lunr-js-search https://github.com/slashdotdash/jekyll-lunr-js-search, but didn't understand how to build the lunr-languages in my blog. my search.md is :


---
layout: default
title: Search
permalink: /search/

---
<div id="search">
  <form action="/search" method="get">
    <input type="text" id="search-query" name="q" placeholder="Search" autocomplete="off">
  </form>
</div>

<script src="/js/jquery-1.9.1.min.js" type="text/javascript" charset="utf-8"></script>
<script src="/js/require.js"></script>
<script src="/js/lunr.stemmer.support.js"></script>
<script src="/js/lunr.jp.js"></script>
<script src="/js/lunr.min.js" type="text/javascript" charset="utf-8"></script>
<script src="/js/mustache.js" type="text/javascript" charset="utf-8"></script>
<script src="/js/date.format.js" type="text/javascript" charset="utf-8"></script>
<script src="/js/URI.min.js" type="text/javascript" charset="utf-8"></script>
<script src="/js/jquery.lunr.search.js" type="text/javascript" charset="utf-8"></script>

<section id="search-results" style="display: none;">
  <p>Search results</p>
  <div class="entries">
  </div>
</section>

<script type="text/javascript">
  $(function() {
    $('#search-query').lunrSearch({
      indexUrl  : '/js/index.json',           // url for the .json file containing search index data// URL of the `search.json` index data for your site
      results   : '#search-results',          // selector for containing search results element// jQuery selector for the search results container
      template  : '#search-results-template', // selector for Mustache.js template// jQuery selector for the Mustache.js template
      titleMsg  : '<h1>Search results<h1>',   // message attached in front of results (can be empty)
      emptyMsg  : '<p>Nothing found.</p>'     // shown message if search returns no results
      entries:  '.entries',                 // jQuery selector for the element to contain the results list, must be a child of the results element above.   
    });
  });
</script>

<script src="/js/search.min.js" type="text/javascript" charset="utf-8"></script>

<script type="text/javascript">
var idx = lunr(function () {
    // use the language (jp)
    this.use(lunr.jp);
    // then, the normal lunr index initialization
    this.field('title', { boost: 10 });
    this.field('body');
});
</script>
<script type="text/javascript">
require(['js/lunr.js', 'js/lunr.stemmer.support.js', 'js/lunr.jp.js'], function(lunr, stemmerSupport, jp) {
    // since the stemmerSupport and de add keys on the lunr object, we'll pass it as reference to them
    // in the end, we will only need lunr.
    stemmerSupport(lunr); // adds lunr.stemmerSupport
    jp(lunr); // adds lunr.de key
    // at this point, lunr can be used
    var idx = lunr(function () {
        // use the language (jp)
        this.use(lunr.jp);
        // then, the normal lunr index initialization
        this.field('title', { boost: 10 })
        this.field('body')
    });
});
</script>
{% raw %}
<script id="search-results-template" type="text/mustache">
  {{#entries}}
    <article>
      <h2>
        {{#date}}<small><time datetime="{{pubdate}}" pubdate>{{displaydate}}</time></small>{{/date}}
        <a href="{{url}}">{{title}}</a>
      </h2>
      {{#is_post}}
      <ul>
{{#tags}} <small> {{.}} </small>{{/tags}}
      </ul>
      {{/is_post}}
    </article>
  {{/entries}}
</script>
{% endraw %}

please help me, thank you.