Adding a search page to a static site

HI
In case you are about to add a search to your static site, here is one way of doing it with anvil.

Goal

The ancient Buddhist texts were written in an early Indo script called Pali. There are translations out there, so starting with a main repository of translations I wanted to create a website of the entire Pali Canon plus English translations with a Pali and English search page.

Problem

There are about 8000 chapters in the early Pali amounting to over 470000 lines of text. Translation work is still incomplete, but of what there are, English translations would comprise of about 270000 lines. This being not-for-profit, anvil’s database quota is obviously not adequate.

Solution

A static site seems a solution as the English texts change rarely and the Pali text change not at all. The python Pelican static site generator was used to generate the nearly 8000 pages.

But what of search?

Let’s spend $5 a month for a 25G virtual machine, install PostgreSQL to house all the lines of text in a database. Why PostgresQL?

PostgresQL has beautiful full text search for English texts. However, this cannot be used for the Pali, as the full text search pre-supposes a contemporary dictionary, of which, Pali has none.

PostgresQL can again come to the rescue using trigrams (splitting a word into sequences of 3 letters).

Still need a public facing API on our virtual machine though… Enter PostgresT, a open source way of adding a http API to your database.

Finally… let’s use anvil for the search page. Anvil has an easy way of accessing APIs in the client, so now, no server code is needed. (The static pages can be hosted anywhere.)

Let’s add the css into anvil’s assets. Let’s make sure that a line of text found on the search page has an easy reference to its page. Done.

Result

A search term is entered. Anvil displays the lines of text where it is found. Click a reference on one of the lines and that transfers you to the static site with the line at the top of the page.

Anvil Search Page

Thank you Anvil, Pelican, PostgresQL, PostgresT and Caprover (by helping me stick them all together)!

4 Likes