mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2025-05-19 00:04:11 +00:00
lunr: improve multiterm search #407
This commit is contained in:
parent
57b73a5f47
commit
6a20332b51
2 changed files with 4 additions and 4 deletions
|
@ -1 +1 @@
|
||||||
7.1.1+8debc83a770553885b78318e2651a127a82d2b0c
|
7.1.1+57b73a5f47d69d695fba57ec966ae7dd25400a66
|
|
@ -57,7 +57,7 @@ Each array item needs the following layout:
|
||||||
let lunrIndex, pagesIndex;
|
let lunrIndex, pagesIndex;
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
function initLunrIndex( index ){
|
function initIndex( index ){
|
||||||
pagesIndex = index;
|
pagesIndex = index;
|
||||||
// Set up Lunr by declaring the fields we use
|
// Set up Lunr by declaring the fields we use
|
||||||
// Also provide their boost level for the ranking
|
// Also provide their boost level for the ranking
|
||||||
|
@ -93,7 +93,7 @@ function init() {
|
||||||
js.src = index_js_url;
|
js.src = index_js_url;
|
||||||
js.setAttribute("async", "");
|
js.setAttribute("async", "");
|
||||||
js.onload = function(){
|
js.onload = function(){
|
||||||
initLunrIndex(relearn_searchindex);
|
initIndex(relearn_searchindex);
|
||||||
};
|
};
|
||||||
js.onerror = function(e){
|
js.onerror = function(e){
|
||||||
console.error('Error getting Hugo index file');
|
console.error('Error getting Hugo index file');
|
||||||
|
@ -129,7 +129,7 @@ function search(term) {
|
||||||
term = term.replace( /[*:^~+-]/g, ' ' );
|
term = term.replace( /[*:^~+-]/g, ' ' );
|
||||||
var searchTerm = lunr.tokenizer( term ).reduce( function(a,token){return a.concat(searchPatterns(token.str))}, []).join(' ');
|
var searchTerm = lunr.tokenizer( term ).reduce( function(a,token){return a.concat(searchPatterns(token.str))}, []).join(' ');
|
||||||
return !searchTerm || !lunrIndex ? [] : lunrIndex.search(searchTerm).map(function(result) {
|
return !searchTerm || !lunrIndex ? [] : lunrIndex.search(searchTerm).map(function(result) {
|
||||||
return { index: result.ref, matches: Object.keys(result.matchData.metadata), page: pagesIndex[ result.ref ] };
|
return { index: result.ref, matches: [ term, ...Object.keys(result.matchData.metadata) ], page: pagesIndex[ result.ref ] };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue