From 58ce62c1dab232ac5f75edd7780949c5ca7c5188 Mon Sep 17 00:00:00 2001 From: koilebeit Date: Thu, 24 Oct 2024 15:32:44 +0200 Subject: [PATCH 1/2] change lunr config --- _data/theme.yml | 2 +- _includes/js/lunr-js.html | 34 ++++++++++++++++++++++++---------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/_data/theme.yml b/_data/theme.yml index b4a4c27a..d0482c2c 100644 --- a/_data/theme.yml +++ b/_data/theme.yml @@ -83,7 +83,7 @@ timeline-child-objects: true # true / false - if true, and if child object has d data-child-objects: true # true / false - if true, child objects will appear linked in table on data page carousel-child-objects: true # true / false - if true, child objects will appear on homepage carousel browse-child-objects: false # true / false - if true, child objects will appear on browse page and child objects' metadata will populate cloud pages like Subjects page and Locations page, as well as featured terms boxes on the home page -search-child-objects: true # true / false - if true, child objects will appear on on search page along with parent objects +search-child-objects: false # true / false - if true, child objects will appear on on search page along with parent objects ########## diff --git a/_includes/js/lunr-js.html b/_includes/js/lunr-js.html index d7654c18..3e7b0035 100644 --- a/_includes/js/lunr-js.html +++ b/_includes/js/lunr-js.html @@ -14,25 +14,39 @@ this.field({{ f.field | jsonify }}) {% endfor %} - //this.pipeline.remove(lunr.trimmer) + this.pipeline.remove(lunr.trimmer) + this.pipeline.remove(lunr.stemmer); + // Add each item to the index, processing fields with semicolons for (var item in store) { - this.add({ - {% for f in index_fields %} - {{ f.field | jsonify }}: store[item][{{ f.field | jsonify }}], - {% endfor %} - id: item - }) + var indexedData = {}; + {% for f in index_fields %} + var fieldValue = store[item][{{ f.field | jsonify }}]; + if (fieldValue) { + // Split semicolon-separated values and join them with spaces + indexedData[{{ f.field | jsonify }}] = fieldValue.split(";").join(" "); + } + {% endfor %} + + // Add the indexed data to the Lunr index + this.add(Object.assign(indexedData, { id: item })); } }); - + /* search function */ function lunr_search () { var resultdiv = document.querySelector('#lunrResults'); - var query = document.querySelector('#lunrSearchBox').value;//.toLowerCase(); + var query = document.querySelector('#lunrSearchBox').value.toLowerCase(); /* basic search that supports operators */ - var result = idx.search(query); + // var result = idx.search(query); + + /* Enable trailing wildcard for partial matches */ + var result = idx.query(function (q) { + query.split(lunr.tokenizer.separator).forEach(function (term) { + q.term(term, { wildcard: lunr.Query.wildcard.TRAILING }); + }); + }); /* more fuzzy search, but doesn't support operators: var result = idx.query(function (q) { From 26bd503bb83795663a883458a5dddff53d155435 Mon Sep 17 00:00:00 2001 From: koilebeit Date: Thu, 24 Oct 2024 15:51:58 +0200 Subject: [PATCH 2/2] format files --- _includes/js/lunr-js.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/_includes/js/lunr-js.html b/_includes/js/lunr-js.html index 3e7b0035..3afdb7b6 100644 --- a/_includes/js/lunr-js.html +++ b/_includes/js/lunr-js.html @@ -27,20 +27,20 @@ indexedData[{{ f.field | jsonify }}] = fieldValue.split(";").join(" "); } {% endfor %} - + // Add the indexed data to the Lunr index this.add(Object.assign(indexedData, { id: item })); } }); - + /* search function */ function lunr_search () { var resultdiv = document.querySelector('#lunrResults'); var query = document.querySelector('#lunrSearchBox').value.toLowerCase(); /* basic search that supports operators */ // var result = idx.search(query); - + /* Enable trailing wildcard for partial matches */ var result = idx.query(function (q) { query.split(lunr.tokenizer.separator).forEach(function (term) {