Search in Hugo Server

Now while I’ll be the first to admit this will probably be outside the scope of Hugo’s intended purpose, there are benefits to having search built into Hugo without having to use JS. This obviously won’t work if serving the content using NGINX or another web server, unless someone builds an external cross-platform app just for searching. I personally would like to see this, but ideally site search using JSON would be better as part of the browser itself.

However, I am looking to distribute my site using Git and hopefully have users serve the content locally using Hugo Server. Therefore, this could be part of the Hugo Server. Using the key/value and Hugo you could even filter searches based on specific keys or sections of a site. Additionally, Hugo Server could be made fully “production” ready, if it isn’t already.

There may be a way to create a placeholder for another search server, and then have it populate the search results within the Hugo template, but I’m not having any luck finding an easy to implement solution. If anyone has suggestions on how to do this, please let me know.

Have you looked at Lunr.js? It’s JavaScript, but the processing all happens in the browser, so it’s fully compatible with running Hugo server. You just need to generate a JSON file with the content you want indexed.

Second lunr.js. It’s super simple to implement and does work within the development server provided by hugo server.

Thanks… I have Fuse.js working well already, but was looking for something that would work in a browser that doesn’t support JavaScript.

I’m not even sure how that would work. If the results are hard-coded into the page/site, you’d need JavaScript to filter through them based on the search. If you call out to some service for the results, you need JavaScript to dynamically build the list. The only way to not use JavaScript is to embed a search engine in an iFrame and display their results, which just offloads the work to them.

For Hugo to provide search processing as a back end server, it would also need to create the results page(s) based on that search, which means creating The Hugo Way to do search and making people build templates that fit that. Also, that would be creating dynamic sites (since the result pages are built just before sending them to the user), which would go against Hugo being a static site generator.

Hugo server is really meant to test site changes before they get published and should remain limited to that, IMO. There are plenty of good static file servers out there - Hugo’s devs don’t need to split their focus by implementing one too.