redis-search 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +69 -0
- data/lib/redis_search/search.rb +2 -2
- metadata +66 -36
- data/README.textile +0 -55
data/README.markdown
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# RedisSearch
|
2
|
+
|
3
|
+
High performance real-time search (Support Chinese), index in Redis for Rails application
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
* Real-time search
|
8
|
+
* High performance
|
9
|
+
|
10
|
+
## Requirements
|
11
|
+
|
12
|
+
* Redis 2.2
|
13
|
+
* Libmmseg
|
14
|
+
|
15
|
+
## Install
|
16
|
+
|
17
|
+
in Rails application Gemfile
|
18
|
+
|
19
|
+
gem 'redis','2.1.1'
|
20
|
+
gem "rmmseg-cpp-huacnlee", "0.2.8"
|
21
|
+
gem 'redis-search', '0.1'
|
22
|
+
|
23
|
+
install bundlers
|
24
|
+
|
25
|
+
$ bundle install
|
26
|
+
|
27
|
+
## Configure
|
28
|
+
|
29
|
+
create file in: config/initializers/redis_search.rb
|
30
|
+
|
31
|
+
require "redis_search"
|
32
|
+
redis = Redis.new(:host => "127.0.0.1",:port => "6379")
|
33
|
+
redis.select("app_name.search")
|
34
|
+
RedisSearch.configure do |config|
|
35
|
+
config.redis = redis
|
36
|
+
end
|
37
|
+
|
38
|
+
## Usage
|
39
|
+
|
40
|
+
bind RedisSearch callback event, it will to rebuild search indexes when data create or update.
|
41
|
+
|
42
|
+
class Post
|
43
|
+
include Mongoid::Document
|
44
|
+
include RedisSearch
|
45
|
+
|
46
|
+
field :title
|
47
|
+
field :body
|
48
|
+
|
49
|
+
belongs_to :user
|
50
|
+
belongs_to :category
|
51
|
+
|
52
|
+
redis_search_index(:title_field => :title,
|
53
|
+
:ext_fields => [:category_name])
|
54
|
+
|
55
|
+
def category_name
|
56
|
+
self.category.name
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# GET /searchs?q=title
|
61
|
+
class SearchController < ApplicationController
|
62
|
+
def index
|
63
|
+
RedisSearch::Search.query(params[:q], :type => "Post")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
## Demo
|
68
|
+
|
69
|
+
You can try the search feature in [`zheye.org`](http://zheye.org)
|
data/lib/redis_search/search.rb
CHANGED
metadata
CHANGED
@@ -1,74 +1,104 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-search
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
version: "0.2"
|
6
10
|
platform: ruby
|
7
|
-
authors:
|
11
|
+
authors:
|
8
12
|
- Jason Lee
|
9
13
|
autorequire:
|
10
14
|
bindir: bin
|
11
15
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
16
|
+
|
17
|
+
date: 2011-08-17 00:00:00 +08:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
15
21
|
name: rmmseg-cpp-huacnlee
|
16
|
-
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
24
|
none: false
|
18
|
-
requirements:
|
25
|
+
requirements:
|
19
26
|
- - ~>
|
20
|
-
- !ruby/object:Gem::Version
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 7
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
- 2
|
32
|
+
- 8
|
21
33
|
version: 0.2.8
|
22
34
|
type: :runtime
|
23
|
-
|
24
|
-
|
25
|
-
- !ruby/object:Gem::Dependency
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
26
37
|
name: redis
|
27
|
-
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
28
40
|
none: false
|
29
|
-
requirements:
|
41
|
+
requirements:
|
30
42
|
- - ~>
|
31
|
-
- !ruby/object:Gem::Version
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 9
|
45
|
+
segments:
|
46
|
+
- 2
|
47
|
+
- 1
|
48
|
+
- 1
|
32
49
|
version: 2.1.1
|
33
50
|
type: :runtime
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
Rails application.
|
38
|
-
email:
|
51
|
+
version_requirements: *id002
|
52
|
+
description: High performance real-time search (Support Chinese), index in Redis for Rails application.
|
53
|
+
email:
|
39
54
|
- huacnlee@gmail.com
|
40
55
|
executables: []
|
56
|
+
|
41
57
|
extensions: []
|
58
|
+
|
42
59
|
extra_rdoc_files: []
|
43
|
-
|
60
|
+
|
61
|
+
files:
|
44
62
|
- lib/redis_search/base.rb
|
45
63
|
- lib/redis_search/config.rb
|
46
64
|
- lib/redis_search/search.rb
|
47
65
|
- lib/redis_search.rb
|
48
|
-
- README.
|
66
|
+
- README.markdown
|
67
|
+
has_rdoc: true
|
49
68
|
homepage: http://github.com/huacnlee/redis-search
|
50
69
|
licenses: []
|
70
|
+
|
51
71
|
post_install_message:
|
52
72
|
rdoc_options: []
|
53
|
-
|
73
|
+
|
74
|
+
require_paths:
|
54
75
|
- lib
|
55
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
77
|
none: false
|
57
|
-
requirements:
|
58
|
-
- -
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
|
61
|
-
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
hash: 3
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
version: "0"
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
86
|
none: false
|
63
|
-
requirements:
|
64
|
-
- -
|
65
|
-
- !ruby/object:Gem::Version
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
hash: 23
|
91
|
+
segments:
|
92
|
+
- 1
|
93
|
+
- 3
|
94
|
+
- 6
|
66
95
|
version: 1.3.6
|
67
96
|
requirements: []
|
97
|
+
|
68
98
|
rubyforge_project:
|
69
|
-
rubygems_version: 1.
|
99
|
+
rubygems_version: 1.6.2
|
70
100
|
signing_key:
|
71
101
|
specification_version: 3
|
72
|
-
summary: High performance real-time search (Support Chinese), index in Redis for Rails
|
73
|
-
application.
|
102
|
+
summary: High performance real-time search (Support Chinese), index in Redis for Rails application.
|
74
103
|
test_files: []
|
104
|
+
|
data/README.textile
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
h1. RedisSearch
|
2
|
-
|
3
|
-
High performance real-time search (Support Chinese), index in Redis for Rails application
|
4
|
-
|
5
|
-
h2. Features
|
6
|
-
|
7
|
-
* Real-time search
|
8
|
-
* High performance
|
9
|
-
|
10
|
-
h2. Requirements
|
11
|
-
|
12
|
-
* Redis 2.2
|
13
|
-
* Libmmseg
|
14
|
-
|
15
|
-
h2. Install
|
16
|
-
|
17
|
-
* gem install redis-search
|
18
|
-
|
19
|
-
h2. Configure
|
20
|
-
|
21
|
-
# config/initializers/redis_search.rb
|
22
|
-
require "redis_search"
|
23
|
-
redis = Redis.new(:host => redis_config[:host],:port => redis_config[:port])
|
24
|
-
redis.select("app_name.search")
|
25
|
-
RedisSearch.configure do |config|
|
26
|
-
config.redis = redis
|
27
|
-
end
|
28
|
-
|
29
|
-
h2. Usage
|
30
|
-
|
31
|
-
class Post
|
32
|
-
include Mongoid::Document
|
33
|
-
include RedisSearch
|
34
|
-
|
35
|
-
field :title
|
36
|
-
field :body
|
37
|
-
|
38
|
-
belongs_to :user
|
39
|
-
belongs_to :category
|
40
|
-
|
41
|
-
# bind RedisSearch callback event, it will to rebuild search indexes when data create or update.
|
42
|
-
redis_search_index(:title_field => :title,
|
43
|
-
:ext_fields => [:category_name])
|
44
|
-
|
45
|
-
def category_name
|
46
|
-
self.category.name
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
# GET /searchs?q=title
|
51
|
-
class SearchController < ApplicationController
|
52
|
-
def index
|
53
|
-
RedisSearch::Search.query(params[:q], :type => "Post")
|
54
|
-
end
|
55
|
-
end
|