We have spent the past many weeks diving into topics related to what we like to call “Modern Persistence.” In those episodes we uncovered powerful techniques for persisting user data, querying data, observes changes to the data in views, reacting to database events with triggers, and we accomplished all of this with an eye on type-safety, schema-safety, and testability.
We are going to continue the theme of “Modern Persistence” for a little bit longer by exploring something that naturally comes up once your user has stored a whole bunch of data in your app: how can you efficiently search through it? Searching data sets is something that SQL excels at in general, but as your dataset gets large enough, or your search terms get complex enough, you need to start turning to other tools.
One of the most popular tools out there for this is known as “full-text search”, which is a technique that has been codified in many storage systems, such as MySQL, Postgres, Elasticsearch, and of course our beloved SQLite. Full-text search allows you to efficiently process many thousands of documents to search for phrases with some fancy bells and whistles. For example, it can rank documents based on how relevant they are to the search term, and it comes with a simple query syntax for searching complex terms, and it can even help you generate fragments of your documents with search terms highlighted in order to display it to your users.
We are going to cover most of this, but first let’s explore how we might approach searching our database from first principles. We are going to take the Reminders app that we have been building for multiple weeks, and we are going to add a search feature to it.
Let’s get started.