• This repository has been archived on 06/Mar/2018
  • Stars
    star
    712
  • Rank 63,602 (Top 2 %)
  • Language
    Ruby
  • License
    MIT License
  • Created about 13 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Deprecated! High performance real-time prefix search, indexes store in Redis for Rails application

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!

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

Master Status

Gem Version CI Status CodeCov

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
require "redis"
require "redis-namespace"
require "redis-search"

# don't forget change namespace
redis = Redis.new(host: '127.0.0.1', port: '6379')
# We suggest you use a special db in Redis, when you need to clear all data, you can use `flushdb` command to cleanup.
redis.select(3)
# 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 = Redis::Namespace.new("your_app_name:redis_search", redis: redis)
Redis::Search.configure do |config|
  config.redis = redis
  config.complete_max_length = 100
  config.pinyin_match = true
end

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

Benchmark test

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

Demo

Projects used redis-search:

License

  • MIT

More Repositories

1

rails-settings-cached

Global settings for your Rails application.
Ruby
1,005
star
2

flora-kit

💐 基于 shadowsocks-go 做的完善实现,自动网络分流,完全兼容 Surge 的配置文件。
Go
898
star
3

autocorrect

A linter and formatter to help you to improve copywriting, correct spaces, words, and punctuations between CJK (Chinese, Japanese, Korean).
Rust
887
star
4

rucaptcha

Captcha Gem for Rails, which generates captcha image by Rust.
Ruby
686
star
5

quora

Quora.com like project with Ruby on Rails (不再维护)
JavaScript
684
star
6

init.d

⚙️ Batch scripts for Rails production environment install on Ubuntu Server.
678
star
7

bluedoc

An open-source document management tool for enterprise self host.
Ruby
626
star
8

social-share-button

Helper for add social share feature in your Rails app. Twitter, Facebook, Weibo, Douban ...
CoffeeScript
581
star
9

PokemonGoMove

Pokemon GO iOS GPS Emulator - NO Jailbreak needed, lets you play the game on your Mac :)
Python
412
star
10

imax.im

🎬 Source code of IMAX.im
Ruby
366
star
11

mediom

Forum web application, an example for from Rails to Go (Revel)
Go
355
star
12

jquery.qeditor

This is a simple WYSIWYG editor with jQuery.
CoffeeScript
259
star
13

carrierwave-aliyun

阿里云 OSS Ruby 上传组件,基于 Carrierwave
Ruby
195
star
14

auto-correct

Automatically add whitespace between CJK (Chinese, Japanese, Korean) and half-width characters (alphabetical letters, numerical digits and symbols).
Ruby
142
star
15

activestorage-aliyun

Wraps the Aliyun OSS as an Active Storage service.
Ruby
131
star
16

sails

Create a Thrift Server use like Rails
Ruby
71
star
17

turbolinks-prefetch

Turbolinks extends for prefetch links to speeds up your website.
JavaScript
70
star
18

personlab

我博客的源代码,这个代码较老,不推荐拿来学习
Ruby
69
star
19

vimmate

Custom vim like Textmate for Ruby on Rails development
Vim Script
69
star
20

mongoid_auto_increment_id

Override id field to MySQL like auto increment for Mongoid.
Ruby
65
star
21

hello-go

入门 Go 编写应用
Go
57
star
22

pasite

Share your sources code on the web, see the http://pasite.org
Ruby
55
star
23

zed-theme-macos-classic

A macOS native style theme for Zed, let it same like native app in macOS.
JavaScript
49
star
24

sql-builder

A simple SQL builder for generate SQL for non-ActiveRecord supports databases
Ruby
36
star
25

rails-activestorage-example

Rails use Active Storage the right way
Ruby
30
star
26

redmine-theme-innerboard

Innerboard theme for Redmine
26
star
27

cocoaout

Auto build and release tool for Cocoa projects.
Ruby
25
star
28

enumize

Extend ActiveRecord::Enum for add more helpful methods.
Ruby
24
star
29

jquery.lazyimg

Image lazy load plugin for jQuery, fork from jquery.unveil to improve performance with huge DOMs.
CoffeeScript
23
star
30

gitlab-mail-receiver

The way of allow your GitLab support Email receive and parse the email content, and find Issue/MergeRequest to create reply.
Ruby
23
star
31

redis-search-example

An example for use redis-search gem
JavaScript
23
star
32

ip-location

通过淘宝 IP 库查询 IP 所在地域位置 http://ip.taobao.com
Ruby
18
star
33

mongoid_taggable_on

Taggable on custom fields for Mongoid
Ruby
16
star
34

vscode-macos-classic.theme

macOS Classic theme for Visual Studio Code
Makefile
15
star
35

backup-aliyun

Aliyun OSS storage with Backup
Ruby
12
star
36

jdialog

a jQuery popup window plugin
JavaScript
12
star
37

html-pipeline.cr

HTML processing filters and utilities for Crystal.
Crystal
11
star
38

vue-rails-example

Use Vue.js in Rails 6 example
Ruby
9
star
39

actiontext-lite

Lite version of ActionText
Ruby
7
star
40

autocorrect-action

GitHub action for use AutoCorrect as lint
Shell
6
star
41

zed-extension-action

GitHub Action for automatically bump Zed Extensions version after a release.
JavaScript
6
star
42

docker-rails

Deploy Rails via Docker example
Ruby
5
star
43

booklib

php + Codeigniter Library management tool
PHP
4
star
44

vscode-blackboard-plus.theme

Visual Studio Code - Blackboard Plus Theme
4
star
45

zed-csv

CSV support for Zed
Rust
4
star
46

remarkdown

This is extends of Markdown lib from Crystal Stdlib for Support Markdown GFM.
Crystal
4
star
47

huacnlee.github.io

Ruby
3
star
48

vscode-autocorrect

AutoCorrect for VS Code
TypeScript
3
star
49

sidekiq-activerecord-shard

Sidekiq middleware to supports ActiveRecord 7 shard
Ruby
3
star
50

autocorrect-idea-plugin

AutoCorrect Plugin for IntelliJ IDEA
Kotlin
2
star
51

auto-booking-park

Shell
2
star
52

jselectdate

jQuery date choice control with dropdown list
JavaScript
2
star
53

capistrano-upload-configs

Capistrano plugin for Upload local config files to remote, and create soft link.
Ruby
2
star
54

zed-autocorrect

AutoCorrect for Zed
Rust
2
star
55

micro-web-simple

Go
1
star
56

jimagelink

模拟yupoo的缩略图上的小图标效果的jQuery插件
JavaScript
1
star
57

jcaches

client side cache with Javascript
JavaScript
1
star
58

yjs-server

JavaScript
1
star
59

Light-Classic.tmTheme

Improve of TextMate Light Theme from Mac Classic
1
star