From b4307e7c094c3a556e267b136e591c146a41f12f Mon Sep 17 00:00:00 2001 From: Alex Shpak Date: Sun, 20 Oct 2019 19:02:32 +0200 Subject: #80, Migrate to flexsearch --- assets/search-data.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'assets/search-data.js') diff --git a/assets/search-data.js b/assets/search-data.js index dee01f6..6848438 100644 --- a/assets/search-data.js +++ b/assets/search-data.js @@ -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, } })(); -- cgit v1.2.3