Files
gokrazy/docs/js/search-lunr.min.js
2025-11-16 20:05:24 +01:00

1 line
1.4 KiB
JavaScript

(function(){let e,t;function n(){function s(n){if(!window.lunr)return;t=n,e=lunr(function(){this.use(lunr.multiLanguage.apply(null,window.relearn.contentLangs)),this.ref("index"),this.field("title",{boost:15}),this.field("tags",{boost:10}),this.field("content",{boost:5}),this.pipeline.remove(lunr.stemmer),this.searchPipeline.remove(lunr.stemmer),t.forEach(function(e,t){e.index=t,this.add(e)},this)}),window.relearn.isSearchEngineReady=!0,window.relearn.executeInitialSearch()}if(window.relearn.index_js_url){var n=document.createElement("script");n.src=window.relearn.index_js_url,n.setAttribute("async",""),n.onload=function(){s(relearn_searchindex)},n.onerror=function(){console.error("Error getting Hugo index file")},document.head.appendChild(n)}}function s(n){function o(e){var t=[{len:-1,typos:1},{len:60,typos:2},{len:40,typos:3},{len:20,typos:4},{len:16,typos:3},{len:12,typos:2},{len:8,typos:1},{len:4,typos:0}];return[e+"^100",e+"*^10","*"+e+"^10",e+"~"+t.reduce(function(t,n){return e.length<n.len?n:t}).typos+"^1"]}if(!window.lunr)return[];n=n.replace(/[*:^~+-]/g," ");var s=lunr.tokenizer(n).reduce(function(e,t){return e.concat(o(t.str))},[]).join(" ");return!s||!e?[]:e.search(s).map(function(e){return{index:e.ref,matches:[n,...Object.keys(e.matchData.metadata)],page:t[e.ref]}})}window.relearn=window.relearn??{},window.relearn.search=window.relearn.search??{},window.relearn.search.adapter={init:n,search:s}})()