Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Lunr #1419

Merged
merged 2 commits into from
Dec 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 28 additions & 17 deletions assets/js/lunr-en.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ layout: null
---

var idx = lunr(function () {
this.field('title', {boost: 10})
this.field('title')
this.field('excerpt')
this.field('categories')
this.field('tags')
this.ref('id')
});

{% assign count = 0 %}
{% for c in site.collections %}
{% assign docs = c.docs | where_exp:'doc','doc.search != false' %}
{% for doc in docs %}
idx.add({
title: {{ doc.title | jsonify }},
excerpt: {{ doc.content | strip_html | truncatewords: 20 | jsonify }},
categories: {{ doc.categories | jsonify }},
tags: {{ doc.tags | jsonify }},
id: {{ count }}
});
{% assign count = count | plus: 1 %}
{% assign count = 0 %}
{% for c in site.collections %}
{% assign docs = c.docs | where_exp:'doc','doc.search != false' %}
{% for doc in docs %}
this.add({
title: {{ doc.title | jsonify }},
excerpt: {{ doc.content | strip_html | truncatewords: 20 | jsonify }},
categories: {{ doc.categories | jsonify }},
tags: {{ doc.tags | jsonify }},
id: {{ count }}
})
{% assign count = count | plus: 1 %}
{% endfor %}
{% endfor %}
{% endfor %}
});

console.log( jQuery.type(idx) );

Expand Down Expand Up @@ -56,8 +56,19 @@ var store = [
$(document).ready(function() {
$('input#search').on('keyup', function () {
var resultdiv = $('#results');
var query = $(this).val();
var result = idx.search(query);
var query = $(this).val().toLowerCase().replace(":", "");
var result =
idx.query(function (q) {
query.split(lunr.tokenizer.separator).forEach(function (term) {
q.term(term, { boost: 100 })
if(query.lastIndexOf(" ") != query.length-1){
q.term(term, { usePipeline: false, wildcard: lunr.Query.wildcard.TRAILING, boost: 10 })
}
if (term != ""){
q.term(term, { usePipeline: false, editDistance: 1, boost: 1 })
}
})
});
resultdiv.empty();
resultdiv.prepend('<p class="results__found">'+result.length+' {{ site.data.ui-text[site.locale].results_found | default: "Result(s) found" }}</p>');
for (var item in result) {
Expand Down
Loading