redis-search 0.6.2 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +10 -6
- data/lib/redis/search/base.rb +5 -0
- data/lib/redis/search/config.rb +3 -0
- data/lib/redis/search/finder.rb +16 -4
- data/lib/redis/search/index.rb +3 -0
- metadata +20 -9
data/README.markdown
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
High performance real-time search (Support Chinese), index in Redis for Rails application
|
4
4
|
|
5
|
+
## Status
|
6
|
+
|
7
|
+
[![CI Status](https://secure.travis-ci.org/huacnlee/redis-search.png)](http://travis-ci.org/huacnlee/redis-search)
|
8
|
+
|
5
9
|
## Features
|
6
10
|
|
7
11
|
* Real-time search
|
@@ -19,10 +23,10 @@ High performance real-time search (Support Chinese), index in Redis for Rails ap
|
|
19
23
|
|
20
24
|
in Rails application Gemfile
|
21
25
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
+
gem 'redis','>= 2.1.1'
|
27
|
+
gem 'chinese_pinyin', '0.4.1'
|
28
|
+
gem 'rmmseg-cpp-huacnlee', '0.2.9'
|
29
|
+
gem 'redis-search', '0.6.2'
|
26
30
|
|
27
31
|
install bundlers
|
28
32
|
|
@@ -33,9 +37,9 @@ install bundlers
|
|
33
37
|
create file in: config/initializers/redis_search.rb
|
34
38
|
|
35
39
|
require "redis-search"
|
40
|
+
# don't forget change namespace
|
36
41
|
redis = Redis.new(:host => "127.0.0.1",:port => "6379")
|
37
|
-
|
38
|
-
redis.select(3)
|
42
|
+
redis = Redis::Namespace.new("your_app_name:redis_search", :redis => redis)
|
39
43
|
Redis::Search.configure do |config|
|
40
44
|
config.redis = redis
|
41
45
|
config.complete_max_length = 100
|
data/lib/redis/search/base.rb
CHANGED
@@ -73,6 +73,11 @@ class Redis
|
|
73
73
|
|
74
74
|
after_update :redis_search_index_remove
|
75
75
|
def redis_search_index_remove
|
76
|
+
# DEBUG info
|
77
|
+
# puts '>>>>>>>>>>>>>>>>>>>>>>'
|
78
|
+
# puts self.redis_search_index_need_reindex
|
79
|
+
# puts self.#{title_field}_was
|
80
|
+
# puts self.#{title_field}
|
76
81
|
if self.redis_search_index_need_reindex
|
77
82
|
Search::Index.remove(:id => self.id, :title => self.#{title_field}_was, :type => self.class.to_s)
|
78
83
|
end
|
data/lib/redis/search/config.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
require "rmmseg"
|
2
3
|
class Redis
|
3
4
|
module Search
|
4
5
|
class << self
|
@@ -30,6 +31,8 @@ class Redis
|
|
30
31
|
self.redis = nil
|
31
32
|
self.complete_max_length = 100
|
32
33
|
self.pinyin_match = false
|
34
|
+
# loading RMMSeg chinese word dicts.
|
35
|
+
RMMSeg::Dictionary.load_dictionaries
|
33
36
|
end
|
34
37
|
end
|
35
38
|
end
|
data/lib/redis/search/finder.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
require "rmmseg"
|
3
2
|
require 'chinese_pinyin'
|
4
3
|
|
5
4
|
class Redis
|
@@ -21,6 +20,7 @@ class Redis
|
|
21
20
|
# * Redis::Search.complete("Tag","red") => ["Redis", "Redmine"]
|
22
21
|
# * Redis::Search.complete("Tag","redi") => ["Redis"]
|
23
22
|
def self.complete(type, w, options = {})
|
23
|
+
return [] if w.blank? or type.blank?
|
24
24
|
limit = options[:limit] || 10
|
25
25
|
|
26
26
|
prefix_matchs = []
|
@@ -155,11 +155,23 @@ class Redis
|
|
155
155
|
end
|
156
156
|
|
157
157
|
def self.warn(msg)
|
158
|
-
|
158
|
+
return if not Search.config.debug
|
159
|
+
msg = "\e[33m[Redis::Search] #{msg}\e[0m"
|
160
|
+
if defined?(Rails) == 'constant' && Rails.class == Class
|
161
|
+
::Rails.logger.warn(msg)
|
162
|
+
else
|
163
|
+
puts msg
|
164
|
+
end
|
159
165
|
end
|
160
166
|
|
161
167
|
def self.info(msg)
|
162
|
-
|
168
|
+
return if not Search.config.debug
|
169
|
+
msg = "\e[32m[Redis::Search] #{msg}\e[0m"
|
170
|
+
if defined?(Rails) == 'constant' && Rails.class == Class
|
171
|
+
::Rails.logger.debug(msg)
|
172
|
+
else
|
173
|
+
puts msg
|
174
|
+
end
|
163
175
|
end
|
164
176
|
|
165
177
|
# 生成 uuid,用于作为 hashes 的 field, sets 关键词的值
|
@@ -181,7 +193,7 @@ class Redis
|
|
181
193
|
return result if ids.blank?
|
182
194
|
Redis::Search.config.redis.hmget(type,*ids).each do |r|
|
183
195
|
begin
|
184
|
-
result << JSON.parse(r)
|
196
|
+
result << JSON.parse(r) if !r.blank?
|
185
197
|
rescue => e
|
186
198
|
Search.warn("Search.query failed: #{e}")
|
187
199
|
end
|
data/lib/redis/search/index.rb
CHANGED
@@ -44,6 +44,9 @@ class Redis
|
|
44
44
|
Redis::Search.config.redis.srem(key, options[:id])
|
45
45
|
Redis::Search.config.redis.del(Search.mk_score_key(type,options[:id]))
|
46
46
|
end
|
47
|
+
|
48
|
+
# remove set for prefix index key
|
49
|
+
Redis::Search.config.redis.srem(Search.mk_sets_key(type,options[:title]),options[:id])
|
47
50
|
end
|
48
51
|
|
49
52
|
private
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-10-
|
12
|
+
date: 2011-10-14 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: chinese_pinyin
|
16
|
-
requirement: &
|
16
|
+
requirement: &2156524340 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.3.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2156524340
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rmmseg-cpp-huacnlee
|
27
|
-
requirement: &
|
27
|
+
requirement: &2156523860 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,21 @@ dependencies:
|
|
32
32
|
version: 0.2.8
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2156523860
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: redis-namespace
|
38
|
+
requirement: &2156523400 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.0.2
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2156523400
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
48
|
name: redis
|
38
|
-
requirement: &
|
49
|
+
requirement: &2156522920 !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ! '>='
|
@@ -43,7 +54,7 @@ dependencies:
|
|
43
54
|
version: 2.1.1
|
44
55
|
type: :runtime
|
45
56
|
prerelease: false
|
46
|
-
version_requirements: *
|
57
|
+
version_requirements: *2156522920
|
47
58
|
description: High performance real-time search (Support Chinese), index in Redis for
|
48
59
|
Rails application.
|
49
60
|
email:
|
@@ -80,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
91
|
version: 1.3.6
|
81
92
|
requirements: []
|
82
93
|
rubyforge_project:
|
83
|
-
rubygems_version: 1.8.
|
94
|
+
rubygems_version: 1.8.6
|
84
95
|
signing_key:
|
85
96
|
specification_version: 3
|
86
97
|
summary: High performance real-time search (Support Chinese), index in Redis for Rails
|