Search is one of the most ubiquitous features: almost every application needs some form of search at some point. Luckily, in the Rails realm, we have many established options that allow us to add the feature, from using a simple search scope with an ILIKE query to more complex options like pgsearch or even options like Elastic Search with the available adapters. In this article, we will learn how to add intelligent search in Rails using the Typesense gem to show the power of Typesense as a search engine and the simplicity of its integration into Rails. Let's start by understanding what Typesense is: What is Typesense? Typesense is a typo-tolerant search engine that's optimized for instant, typically under 50ms, search. Initially, when we think about search in Rails applications, we think about a layer on top of our database that's able to search records that exist in our database using the query criteria provided by the user. Ransack, the library Avo uses to handle search is a good example of this: it's built on top of Active Record and it can search and filter results in our database with some configuration. On the other hand, an alternative like Typesense is more akin to Elastic Search or Algolia than it is to Ransack or PGSearch: we create an index with records from our database or external data and then we use Typesense to query that index which produces the results. However, unlike Elastic Search, Typesense comes with sensible defaults for every config parameter which means it works out-of-the-box for most use cases. The other advantage it has over database search is that it's very performant: it can handle many concurrent search queries per second while returning results fast. Because of the way it's designed, Typesense should never be used as the primary data store of our application. It is meant to store a copy of the data which should be in our database. Typesense concepts The first concept to understand is that we interact with Typesense using a client whi...
First seen: 2025-10-11 09:36
Last seen: 2025-10-11 16:15