Skip to content
High performance real-time search (Support Chinese), indexes store in Redis for Rails application
Find file
Latest commit 46d8d57 @huacnlee update readme
Failed to load latest commit information.
lib Add support for STI
spec Add support for STI
.gitignore update readme
.rspec Add travis support
.travis.yml remove 1.9.3 test on travis Release 0.9.7
Gemfile Test Rails 4
Gemfile.lock Pipelined query for finder.
LICENSE Add License update readme
Rakefile Trailing whitespace
redis-search.gemspec Release 0.9.7


High performance real-time search (Support Chinese), index in Redis for Rails application



You can try the search feature in |

And there is an Example App to show you how to use redis-search.

Master Status

CI Status


  • Real-time search
  • High performance
  • Segment words search and prefix match search
  • Support match with alias
  • Support ActiveRecord and Mongoid
  • Sort results by one field
  • Homophone search, pinyin search
  • Search as pinyin first chars
  • Conditions support


  • Redis 2.2+


  1. In Rails application Gemfile

    gem 'ruby-pinyin'
    gem 'redis-search'
    $ bundle install


  • Create file in: config/initializers/redis_search.rb

    require "redis"
    require "redis-namespace"
    require "redis-search"
    # don't forget change namespace
    redis = => "",:port => "6379")
    # We suggest you use a special db in Redis, when you need to clear all data, you can use flushdb command to clear them.
    # Give a special namespace as prefix for Redis key, when your have more than one project used redis-search, this config will make them work fine.
    redis ="your_app_name:redis_search", :redis => redis)
    Redis::Search.configure do |config|
      config.redis = redis
      config.complete_max_length = 100
      config.pinyin_match = true
      # use rmmseg, true to disable it, it can save memroy
      config.disable_rmmseg = false


  • Bind Redis::Search callback event, it will to rebuild search indices when data create or update.

    class Post
      include Mongoid::Document
      include Redis::Search
      field :title
      field :body
      field :hits
      belongs_to :user
      belongs_to :category
      redis_search_index(:title_field => :title,
                         :score_field => :hits,
                         :condition_fields => [:user_id, :category_id],
                         :ext_fields => [:category_name])
      def category_name
    class User
      include Mongoid::Document
      include Redis::Search
      field :name
      field :alias_names, :type => Array
      field :tagline
      field :email
      field :followers_count
      redis_search_index(:title_field => :name,
                         :alias_field => :alias_names,
                         :prefix_index_enable => true,
                         :score_field => :followers_count,
                         :ext_fields => [:email,:tagline])
    class SearchController < ApplicationController
      # GET /searchs?q=title
      def index
        Redis::Search.query("Post", params[:q], :conditions => {:user_id => 12})
      # GET /search_users?q=j
      def search_users
        Redis::Search.complete("Post", params[:q], :conditions => {:user_id => 12, :category_id => 4})

Index data to Redis

Specify Model

Redis-Search index data to Redis from your model (pass name as CLASS environment variable).

$ rake redis_search:index:model CLASS='MyModel'

Customize the batch size:

$ rake redis_search:index:model CLASS='MyModel' BATCH=100

All Models

Redis-Search all index data to Redis from app/models (or use DIR environment variabl).

$ rake redis_search:index DIR=app/models

Customize the batch size:

$ rake redis_search:index DIR=app/models BATCH=100


Benchmark test

You can run the rake command (see Rakefile) to make test. There is my performance test result.


  • MIT
Something went wrong with that request. Please try again.