How to Add PostgreSQL Full-text Search to Ruby Apps and Optimize Its Performance
In this post, we describe how to implement a built-in PostgreSQL full-text search and add it to your Ruby on Rails application. We demonstrate how it works on a test application that searches articles by a title, content, the author’s name, and comments.
In addition, we explain how to speed up search by eliminating excessive join queries that greatly slow down the system’s performance. Visit this GitHub page to read the article and view code samples.
include PgSearch pg_search_scope :search, against: [:title, :content], associated_against: { author: :name, comments: :content }, using: { tsearch: { dictionary: 'english', any_word: true, prefix: true } }
Further reading
- Deploying a Rails 5 App with MongoDB, Redis, and CarrierWave to IBM Bluemix
- Accessing an External Database Storage from a Bluemix-Based Ruby App