百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

redis-search

> 后端框架
开源

已过时! 高性能实时前缀搜索,索引存储在 Redis 中,用于 Rails 应用程序

708 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

已过时! 高性能实时前缀搜索,索引存储在 Redis 中,用于 Rails 应用程序

Redis-Search (Deprecated! 不在维护!)

High performance real-time prefix search, indexes store in Redis for Rails application. 中文介绍和使用说明

NOTE!

There have more better ways you can choice!

下面的两种方式将是更好的选择:

  • Elasticsearch Prefix Query
  • PostgreSQL Prefix Search

Master Status

Features

  • Real-time search
  • High performance
  • 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

Requirements

  • Redis 2.2+

Install

gem 'redis-search'
$ bundle install

Configure

  • Create file in: config/initializers/redis-search.rb
…

Usage

  • Bind Redis::Search callback event, it will to rebuild search indices when data create or update.
class Post < ActiveRecord::Base
  include Redis::Search

  belongs_to :user
  belongs_to :category

  redis_search title_field: :title,
               score_field: :hits,
               condition_fields: [:user_id, :category_id],
               ext_fields: [:category_name]

  def category_name
    self.category.name
  end
end
class User < ActiveRecord::Base
  include Redis::Search

  serialize :alias_names, Array

  redis_search title_field: :name,
               alias_field: :alias_names,
               score_field: :followers_count,
               ext_fields: [:email, :tagline]
end
class SearchController < ApplicationController
  # GET /search_users?q=j
  def search_users
    Post.prefix_match(params[:q], conditions: { user_id: 12, category_id: 4 })
  end
end

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='User'

Customize the batch size:

$ rake redis_search:index:model CLASS='User' 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

Documentation

  • See Rdoc.info redis-search
  • Example App

Benchmark test

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

  • https://gist.github.com/1150933

Demo

Projects used redis-search:

  • redis-search-example - An example for show you how to use redis-search.
  • IMAX.im
  • Ruby China - Use for mention autocomplete.

License

  • MIT

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rubypinyinprefix-queryrailsredis

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架