redis-search 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.markdown CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  High performance real-time search (Support Chinese), index in Redis for Rails application
4
4
 
5
+ [中文介绍和使用说明](https://github.com/huacnlee/redis-search/wiki/Usage-in-Chinese)
6
+
5
7
  ## Status
6
8
 
7
9
  [![CI Status](https://secure.travis-ci.org/huacnlee/redis-search.png)](http://travis-ci.org/huacnlee/redis-search)
@@ -26,9 +28,10 @@ in Rails application Gemfile
26
28
 
27
29
  gem 'redis','>= 2.1.1'
28
30
  gem 'chinese_pinyin', '0.4.1'
31
+ # add rmmseg if you need search by segment words
29
32
  gem 'rmmseg-cpp-huacnlee', '0.2.9'
30
33
  gem 'redis-namespace','~> 1.1.0'
31
- gem 'redis-search', '0.6.3'
34
+ gem 'redis-search', '0.7.1'
32
35
 
33
36
  install bundlers
34
37
 
@@ -51,6 +54,8 @@ create file in: config/initializers/redis_search.rb
51
54
  config.redis = redis
52
55
  config.complete_max_length = 100
53
56
  config.pinyin_match = true
57
+ # use rmmseg, true to disable it, it can save memroy
58
+ config.disable_rmmseg = false
54
59
  end
55
60
 
56
61
  ## Usage
@@ -124,4 +129,4 @@ There is my performance test result.
124
129
 
125
130
  ## Demo
126
131
 
127
- You can try the search feature in [`zheye.org`](http://zheye.org) | [`shu.im`](http://shu.im)
132
+ You can try the search feature in [`zheye.org`](http://zheye.org) | [`ruby-china`](http://ruby-china.org) | [`shu.im`](http://shu.im)
@@ -34,7 +34,6 @@ class Redis
34
34
  exts
35
35
  end
36
36
 
37
- # after_create :redis_search_index_create
38
37
  def redis_search_index_create
39
38
  s = Search::Index.new(:title => self.#{title_field},
40
39
  :id => self.id,
@@ -46,11 +45,13 @@ class Redis
46
45
  s.save
47
46
  # release s
48
47
  s = nil
48
+ true
49
49
  end
50
50
 
51
51
  before_destroy :redis_search_index_destroy
52
52
  def redis_search_index_destroy
53
53
  Search::Index.remove(:id => self.id, :title => self.#{title_field}, :type => self.class.to_s)
54
+ true
54
55
  end
55
56
 
56
57
  def redis_search_index_need_reindex
@@ -85,13 +86,15 @@ class Redis
85
86
  if self.redis_search_index_need_reindex
86
87
  Search::Index.remove(:id => self.id, :title => self.#{title_field}_was, :type => self.class.to_s)
87
88
  end
89
+ true
88
90
  end
89
91
 
90
92
  after_save :redis_search_index_update
91
93
  def redis_search_index_update
92
- if self.redis_search_index_need_reindex
94
+ if self.redis_search_index_need_reindex or self.new_record?
93
95
  self.redis_search_index_create
94
96
  end
97
+ true
95
98
  end
96
99
  )
97
100
  end
@@ -1,5 +1,4 @@
1
1
  # coding: utf-8
2
- require "rmmseg"
3
2
  class Redis
4
3
  module Search
5
4
  class << self
@@ -7,6 +6,12 @@ class Redis
7
6
 
8
7
  def configure
9
8
  yield self.config ||= Config.new
9
+
10
+ if not self.config.disable_rmmseg
11
+ require "rmmseg"
12
+ # loading RMMSeg chinese word dicts.
13
+ RMMSeg::Dictionary.load_dictionaries
14
+ end
10
15
  end
11
16
  end
12
17
 
@@ -25,14 +30,15 @@ class Redis
25
30
  # When you search "de" will -> 得|的|德...
26
31
  # When you search "得" will -> "de" -> 得|的|德...
27
32
  attr_accessor :pinyin_match
33
+ # Disable RMMSeg, if you don't need, disable this will save memory. (true|false) default = true
34
+ attr_accessor :disable_rmmseg
28
35
 
29
36
  def initialize
30
37
  self.debug = false
31
38
  self.redis = nil
32
39
  self.complete_max_length = 100
33
40
  self.pinyin_match = false
34
- # loading RMMSeg chinese word dicts.
35
- RMMSeg::Dictionary.load_dictionaries
41
+ self.disable_rmmseg = false
36
42
  end
37
43
  end
38
44
  end
@@ -1,6 +1,5 @@
1
1
  # coding: utf-8
2
2
  require 'chinese_pinyin'
3
-
4
3
  class Redis
5
4
  module Search
6
5
  # use rmmseg to split words
@@ -165,7 +164,7 @@ class Redis
165
164
  end
166
165
 
167
166
  # 根据需要的数量取出 ids
168
- ids = Redis::Search.config.redis.sort(temp_store_key,
167
+ ids = Search.config.redis.sort(temp_store_key,
169
168
  :limit => [0,limit],
170
169
  :by => Search.mk_score_key(type,"*"),
171
170
  :order => "desc")
@@ -182,6 +181,9 @@ class Redis
182
181
 
183
182
  private
184
183
  def self._split(text)
184
+ # return chars if disabled rmmseg
185
+ return text.split("") if Search.config.disable_rmmseg
186
+
185
187
  algor = RMMSeg::Algorithm.new(text)
186
188
  words = []
187
189
  loop do
@@ -193,7 +195,7 @@ class Redis
193
195
  end
194
196
 
195
197
  def self.warn(msg)
196
- return if not Search.config.debug
198
+ return if not Redis::Search.config.debug
197
199
  msg = "\e[33m[Redis::Search] #{msg}\e[0m"
198
200
  if defined?(Rails) == 'constant' && Rails.class == Class
199
201
  ::Rails.logger.warn(msg)
@@ -203,7 +205,7 @@ class Redis
203
205
  end
204
206
 
205
207
  def self.info(msg)
206
- return if not Search.config.debug
208
+ return if not Redis::Search.config.debug
207
209
  msg = "\e[32m[Redis::Search] #{msg}\e[0m"
208
210
  if defined?(Rails) == 'constant' && Rails.class == Class
209
211
  ::Rails.logger.debug(msg)
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.7.0
4
+ version: 0.7.1
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-17 00:00:00.000000000Z
12
+ date: 2012-03-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chinese_pinyin
16
- requirement: &2156513140 !ruby/object:Gem::Requirement
16
+ requirement: &70187052370880 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,21 +21,10 @@ dependencies:
21
21
  version: 0.3.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2156513140
25
- - !ruby/object:Gem::Dependency
26
- name: rmmseg-cpp-huacnlee
27
- requirement: &2156512660 !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: 0.2.8
33
- type: :runtime
34
- prerelease: false
35
- version_requirements: *2156512660
24
+ version_requirements: *70187052370880
36
25
  - !ruby/object:Gem::Dependency
37
26
  name: redis-namespace
38
- requirement: &2156512200 !ruby/object:Gem::Requirement
27
+ requirement: &70187052368920 !ruby/object:Gem::Requirement
39
28
  none: false
40
29
  requirements:
41
30
  - - ~>
@@ -43,10 +32,10 @@ dependencies:
43
32
  version: 1.0.2
44
33
  type: :runtime
45
34
  prerelease: false
46
- version_requirements: *2156512200
35
+ version_requirements: *70187052368920
47
36
  - !ruby/object:Gem::Dependency
48
37
  name: redis
49
- requirement: &2156511720 !ruby/object:Gem::Requirement
38
+ requirement: &70187052364560 !ruby/object:Gem::Requirement
50
39
  none: false
51
40
  requirements:
52
41
  - - ! '>='
@@ -54,7 +43,7 @@ dependencies:
54
43
  version: 2.1.1
55
44
  type: :runtime
56
45
  prerelease: false
57
- version_requirements: *2156511720
46
+ version_requirements: *70187052364560
58
47
  description: High performance real-time search (Support Chinese), index in Redis for
59
48
  Rails application.
60
49
  email:
@@ -91,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
80
  version: 1.3.6
92
81
  requirements: []
93
82
  rubyforge_project:
94
- rubygems_version: 1.8.6
83
+ rubygems_version: 1.8.11
95
84
  signing_key:
96
85
  specification_version: 3
97
86
  summary: High performance real-time search (Support Chinese), index in Redis for Rails