I’ve had lunr working in my Hugo site for a long time but recently discovered it broken, not returning results, and I’m working backward to understand what went wrong.
Hugo version is 0.76.0
Lunr is 2.2.1
config.toml includes:
[outputs]
home = [“HTML”, “RSS”, “JSON”]
page = [“HTML”]
section = [“HTML”, “RSS”]
an index.json file is generated in the site root: public/index.json
the contents of index.json are valid JSON
the problem appears to be that the index.json loaded for query processing is empty. The script the gets the index is:
// Initialize lunrjs using our generated index file
function initLunr() {
console.log("initLunr: " + "{{ "index.json" | absURL }}");
$.getJSON("{{ "index.json" | absURL }}")
.done(function(index) {
pagesIndex = index;
console.log("index:", index);
lunrIndex = lunr(function() {
this.field("title", { boost: 10 });
this.field("categories", { boost: 5 });
this.field("keywords");
this.field("content");
this.field("uri");
this.ref("uri");
pagesIndex.forEach(function (page) {
this.add(page)
}, this)
});
})
.fail(function(jqxhr, textStatus, error) {
var err = textStatus + ", " + error;
console.error("Error fetching Hugo search index JSON file:", err);
});
}
Here’s the console log showing that we’re attempting to load the index from the site root:
And here’s that URL loaded in a browser window
Note that it is a 200 response of an empty set - just [ ].
Here’s the public directory to the site, showing the index.json file at root.
What do I do next to tease more information out of this situation?