Almost all web sites have a “search” button for searching for contents in a website.
As a temporary solution I am using the Goggle custom search, but I wonder if there is a simple way to do this using Go. Like:
Fetching all html sites (already in memory using Golang web server?)
Search and analyze contents within tags from a form input.
Usually I’d just ask the database, if you set up your indices correctly, even full text search is quite efficient.
But in general the solution is very dependent on your implementation of the server itself… If you haven’t stored something in the database you can’t really ask it
Usually one wants to search the dynamic data that is filled into the template, rather then the static stuff surrounding that.
So from my point of view, searching the templates doesn’t make sense. But if you really want to, then build yourself an index over the searchable area of the templates and use that index for searches. You’ll probably need to study DB implementation to get that part right.
But I do not know what you have built and how it works, therefore I tell you what one usually would do.
And you said you have “templates”, which usually on itself do not contain useful searchable data, but a page skeleton instead. While the content comes from somewhere else. You still haven’t said where it what this somewhere else is.
Well, you can use templates in at least two ways. Data driven or “plain html”. I decided to start with “plain html”. So I guess I did chose an old way. The data is in the template itself.
<div class="container">
<div class="submenu">
{{template "sub_form"}}
</div>
<div class="content">
<h1>Lorem ipsum</h1>
<p>Lorem ipsum etc Lorem ipsum etc Lorem ipsum etc Lorem ipsum etc </p>
<br><br>
</div></div>
This approach makes it harder to maintain everything in the long run. It is probably easier to have a database containing the contents. But as I said already, if you stick to your current approach you’ll need to manually maintain an index over the searchable content of your pages, as you probably do not want to find articles containing the <article>-tags when you search for the word “article”.
In that case it is, but you should consider the quality of the results as well. But I would choose either Bleeve or Riot in your case because you have small amount of data. And like someone said, you should either index just contents or strip out html before indexing.