diff options
author | Alex Shpak <alex-shpak@users.noreply.github.com> | 2019-10-20 19:02:32 +0200 |
---|---|---|
committer | Alex Shpak <alex-shpak@users.noreply.github.com> | 2019-10-23 21:32:15 +0200 |
commit | b4307e7c094c3a556e267b136e591c146a41f12f (patch) | |
tree | c76047ef54bd7a15ec198f8d40542fc97afe39a7 /assets/search-data.js | |
parent | 4596f08e323ce7ddb67d86705387115bc7e03045 (diff) |
#80, Migrate to flexsearch
Diffstat (limited to 'assets/search-data.js')
-rw-r--r-- | assets/search-data.js | 28 |
1 files changed, 17 insertions, 11 deletions
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, } })(); |