#80, Migrate to flexsearch

This commit is contained in:
Alex Shpak
2019-10-20 19:02:32 +02:00
parent 4596f08e32
commit b4307e7c09
4 changed files with 50 additions and 43 deletions
+17 -11
View File
@@ -3,22 +3,28 @@
{{ range $index, $page := .Site.Pages }}
{{- if $index -}},{{- end }}
{
"idx": {{ $index }},
"href": "{{ $page.RelPermalink }}",
"title": {{ (partial "docs/title" $page) | jsonify }},
"content": {{ $page.Plain | jsonify }}
'idx': {{ $index }},
'href': '{{ $page.RelPermalink }}',
'title': {{ (partial "docs/title" $page) | jsonify }},
'content': {{ $page.Plain | jsonify }}
}
{{- end -}}
];
var index = new FlexSearch({
cache: true,
encode: 'balance',
/* tokenize: function(str) {
return str.replace(/[\x00-\x7F]/g, ' ').split('');
} */
});
pages.forEach(function(page, x) {
index.add(x, pages[x].content);
})
window.bookSearch = {
pages: pages,
idx: lunr(function() {
this.ref("idx");
this.field("title");
this.field("content");
pages.forEach(this.add, this);
}),
index: index,
}
})();