feat: update to flexsearch v0.7.1
This commit is contained in:
parent
93f7598f87
commit
1589916e58
|
@ -64,37 +64,54 @@ Source:
|
|||
|
||||
(function(){
|
||||
|
||||
var index = new FlexSearch({
|
||||
preset: 'score',
|
||||
cache: true,
|
||||
doc: {
|
||||
var index = new FlexSearch.Document({
|
||||
tokenize: "forward",
|
||||
cache: 100,
|
||||
document: {
|
||||
id: 'id',
|
||||
field: [
|
||||
'title',
|
||||
'description',
|
||||
'content',
|
||||
],
|
||||
store: [
|
||||
'href',
|
||||
'title',
|
||||
'description',
|
||||
"href", "title", "description"
|
||||
],
|
||||
},
|
||||
index: ["title", "description", "content"]
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Not yet supported: https://github.com/nextapps-de/flexsearch#complex-documents
|
||||
|
||||
/*
|
||||
var docs = [
|
||||
{{ range $index, $page := (where .Site.Pages "Section" "docs") -}}
|
||||
{
|
||||
id: {{ $index }},
|
||||
href: "{{ .RelPermalink | relURL }}",
|
||||
href: "{{ .Permalink }}",
|
||||
title: {{ .Title | jsonify }},
|
||||
description: {{ .Params.description | jsonify }},
|
||||
content: {{ .Content | jsonify }}
|
||||
},
|
||||
{{ end -}}
|
||||
];
|
||||
*/
|
||||
|
||||
index.add(docs);
|
||||
// https://discourse.gohugo.io/t/range-length-or-last-element/3803/2
|
||||
|
||||
{{ $list := (where .Site.Pages "Section" "docs") -}}
|
||||
{{ $len := (len $list) -}}
|
||||
|
||||
index.add(
|
||||
{{ range $index, $element := $list -}}
|
||||
{
|
||||
id: {{ $index }},
|
||||
href: "{{ .Permalink }}",
|
||||
title: {{ .Title | jsonify }},
|
||||
description: {{ .Params.description | jsonify }},
|
||||
content: {{ .Content | jsonify }}
|
||||
})
|
||||
{{ if ne (add $index 1) $len -}}
|
||||
.add(
|
||||
{{ end -}}
|
||||
{{ end -}}
|
||||
;
|
||||
|
||||
userinput.addEventListener('input', show_results, true);
|
||||
suggestions.addEventListener('click', accept_suggestion, true);
|
||||
|
@ -102,13 +119,13 @@ Source:
|
|||
function show_results(){
|
||||
|
||||
var value = this.value;
|
||||
var results = index.search(value, 5);
|
||||
var results = index.search(value, { limit: 5, index: ["content"], enrich: true });
|
||||
var entry, childs = suggestions.childNodes;
|
||||
var i = 0, len = results.length;
|
||||
|
||||
suggestions.classList.remove('d-none');
|
||||
|
||||
results.forEach(function(page) {
|
||||
results.forEach(function(results) {
|
||||
|
||||
entry = document.createElement('div');
|
||||
|
||||
|
@ -118,9 +135,11 @@ Source:
|
|||
t = entry.querySelector('span:first-child'),
|
||||
d = entry.querySelector('span:nth-child(2)');
|
||||
|
||||
a.href = page.href;
|
||||
t.textContent = page.title;
|
||||
d.textContent = page.description;
|
||||
// console.log(results);
|
||||
|
||||
a.href = results.result[i].doc.href;
|
||||
t.textContent = results.result[i].doc.title;
|
||||
d.textContent = results.result[i].doc.description;
|
||||
|
||||
suggestions.appendChild(entry);
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<div class="col-lg-9 col-xl-8 text-center">
|
||||
<p class="lead">{{ .Params.lead | safeHTML }}</p>
|
||||
<a class="btn btn-primary btn-lg px-4 mb-2" href="{{ "docs/prologue/introduction/" | relURL }}" role="button">Get started</a>
|
||||
<p class="meta">Open-source MIT Licensed. <a href="https://github.com/h-enk/doks">GitHub v{{ .Site.Data.doks.version }}</a></p>
|
||||
<p class="meta">Open-source MIT Licensed. <a href="https://github.com/h-enk/doks">GitHub v{{ $data := getJSON "https://raw.githubusercontent.com/h-enk/doks/master/package.json" }}{{ $data.version }}</a></p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
{{ end -}}
|
||||
|
||||
{{ if .Site.Params.options.flexSearch -}}
|
||||
{{ $flexSearch := resources.Get "js/vendor/flexsearch/dist/flexsearch.min.js" -}}
|
||||
{{ $flexSearch := resources.Get "js/vendor/flexsearch/dist/flexsearch.bundle.js" -}}
|
||||
{{ $slice = $slice | append $flexSearch -}}
|
||||
{{ end -}}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
"clipboard": "^2.0",
|
||||
"eslint": "^7.29",
|
||||
"exec-bin": "^1.0.0",
|
||||
"flexsearch": "^0.6",
|
||||
"flexsearch": "^0.7",
|
||||
"highlight.js": "^11.0",
|
||||
"hugo-installer": "^3.0.1",
|
||||
"instant.page": "^5.1",
|
||||
|
@ -4465,9 +4465,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"node_modules/flexsearch": {
|
||||
"version": "0.6.32",
|
||||
"resolved": "https://registry.npmjs.org/flexsearch/-/flexsearch-0.6.32.tgz",
|
||||
"integrity": "sha512-EF1BWkhwoeLtbIlDbY/vDSLBen/E5l/f1Vg7iX5CDymQCamcx1vhlc3tIZxIDplPjgi0jhG37c67idFbjg+v+Q==",
|
||||
"version": "0.7.1",
|
||||
"resolved": "https://registry.npmjs.org/flexsearch/-/flexsearch-0.7.1.tgz",
|
||||
"integrity": "sha512-+nuTYgqWMA8JawcReboPniMuvy0ClxqU66oMh4YzNiQQrbzH6VdJZMF/kzAEPnpL64FiZfbGRixv+cz5YponhA==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/for-in": {
|
||||
|
@ -13484,9 +13484,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"flexsearch": {
|
||||
"version": "0.6.32",
|
||||
"resolved": "https://registry.npmjs.org/flexsearch/-/flexsearch-0.6.32.tgz",
|
||||
"integrity": "sha512-EF1BWkhwoeLtbIlDbY/vDSLBen/E5l/f1Vg7iX5CDymQCamcx1vhlc3tIZxIDplPjgi0jhG37c67idFbjg+v+Q==",
|
||||
"version": "0.7.1",
|
||||
"resolved": "https://registry.npmjs.org/flexsearch/-/flexsearch-0.7.1.tgz",
|
||||
"integrity": "sha512-+nuTYgqWMA8JawcReboPniMuvy0ClxqU66oMh4YzNiQQrbzH6VdJZMF/kzAEPnpL64FiZfbGRixv+cz5YponhA==",
|
||||
"dev": true
|
||||
},
|
||||
"for-in": {
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
"eslint": "^7.29",
|
||||
"exec-bin": "^1.0.0",
|
||||
"hugo-installer": "^3.0.1",
|
||||
"flexsearch": "^0.6",
|
||||
"flexsearch": "^0.7",
|
||||
"highlight.js": "^11.0",
|
||||
"instant.page": "^5.1",
|
||||
"katex": "^0.13",
|
||||
|
|
Loading…
Reference in New Issue