redis-search 1.0.0.beta2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/lib/redis-search/base.rb +16 -10
- data/lib/redis-search/finder.rb +3 -1
- data/lib/redis-search/tasks.rb +4 -4
- data/lib/redis-search/version.rb +1 -1
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12ec25b07a9d7ffd659fbce03abddb49d0822667
|
4
|
+
data.tar.gz: 301390053cba3ac658d84e5c00e69c98467e17c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b2622a8e197aeb48566b9ef138b4fd83dd3cec4d91047ee8782516e039f6ddbf032c7d05d03c1a45c4d8642484905d955e88fe0722f5f2832cd6b43407720c0
|
7
|
+
data.tar.gz: 4e3c850559c3e9c5c7ec962c057a2d03e72184394f12a0976522669ecdbbda5b76cf6306bcd421326bd355ad6bf6d033a011bcdac07564c3d5add43256c64b94
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Redis-Search
|
2
2
|
|
3
|
-
High performance real-time search
|
3
|
+
High performance real-time prefix search, indexes store in Redis for Rails application.
|
4
4
|
|
5
5
|
[中文介绍和使用说明](https://github.com/huacnlee/redis-search/wiki/Usage-in-Chinese)
|
6
6
|
|
@@ -151,6 +151,7 @@ Projects used redis-search:
|
|
151
151
|
|
152
152
|
- [redis-search-example](https://github.com/huacnlee/redis-search-example) - An example for show you how to use redis-search.
|
153
153
|
- [IMAX.im](https://github.com/huacnlee/imax.im)
|
154
|
+
- [Ruby China](https://ruby-china.org) - Use for mention autocomplete.
|
154
155
|
|
155
156
|
## License
|
156
157
|
|
data/lib/redis-search/base.rb
CHANGED
@@ -3,6 +3,8 @@ class Redis
|
|
3
3
|
module Search
|
4
4
|
autoload :PinYin, 'ruby-pinyin'
|
5
5
|
|
6
|
+
DOT = '.'.freeze
|
7
|
+
|
6
8
|
extend ActiveSupport::Concern
|
7
9
|
|
8
10
|
included do
|
@@ -149,19 +151,11 @@ class Redis
|
|
149
151
|
count = 0
|
150
152
|
if ancestors.collect(&:to_s).include?('ActiveRecord::Base'.freeze)
|
151
153
|
find_in_batches(batch_size: batch_size) do |items|
|
152
|
-
items
|
153
|
-
item.redis_search_index_create
|
154
|
-
count += 1
|
155
|
-
print '.' if progressbar
|
156
|
-
end
|
154
|
+
_redis_search_reindex_items(items)
|
157
155
|
end
|
158
156
|
elsif included_modules.collect(&:to_s).include?('Mongoid::Document'.freeze)
|
159
157
|
all.each_slice(batch_size) do |items|
|
160
|
-
items
|
161
|
-
item.redis_search_index_create
|
162
|
-
count += 1
|
163
|
-
print '.' if progressbar
|
164
|
-
end
|
158
|
+
_redis_search_reindex_items(items)
|
165
159
|
end
|
166
160
|
else
|
167
161
|
puts 'skiped, not support this ORM in current.'
|
@@ -169,6 +163,18 @@ class Redis
|
|
169
163
|
|
170
164
|
count
|
171
165
|
end
|
166
|
+
|
167
|
+
private
|
168
|
+
|
169
|
+
def _redis_search_reindex_items(items)
|
170
|
+
items.each do |item|
|
171
|
+
item.redis_search_index_create
|
172
|
+
count += 1
|
173
|
+
print DOT if progressbar
|
174
|
+
item = nil
|
175
|
+
end
|
176
|
+
items = nil
|
177
|
+
end
|
172
178
|
end
|
173
179
|
end
|
174
180
|
end
|
data/lib/redis-search/finder.rb
CHANGED
@@ -8,6 +8,7 @@ class Redis
|
|
8
8
|
# type model name
|
9
9
|
# w search char
|
10
10
|
# :limit result limit
|
11
|
+
# :order result order
|
11
12
|
#
|
12
13
|
# h3. usage:
|
13
14
|
#
|
@@ -18,6 +19,7 @@ class Redis
|
|
18
19
|
def complete(type, w, options = {})
|
19
20
|
limit = options[:limit] || 10
|
20
21
|
conditions = options[:conditions] || []
|
22
|
+
order = options[:order] || 'desc'
|
21
23
|
return [] if (w.blank? && conditions.blank?) || type.blank?
|
22
24
|
|
23
25
|
prefix_matchs = []
|
@@ -88,7 +90,7 @@ class Redis
|
|
88
90
|
ids = config.redis.sort(temp_store_key,
|
89
91
|
limit: [0, limit],
|
90
92
|
by: mk_score_key(type, '*'),
|
91
|
-
order:
|
93
|
+
order: order)
|
92
94
|
return [] if ids.blank?
|
93
95
|
hmget(type, ids)
|
94
96
|
end
|
data/lib/redis-search/tasks.rb
CHANGED
@@ -31,13 +31,13 @@ namespace :redis_search do
|
|
31
31
|
exit(1)
|
32
32
|
end
|
33
33
|
|
34
|
-
klass =
|
35
|
-
batch = ENV['BATCH'].to_i
|
36
|
-
|
34
|
+
klass = Object.const_get((ENV['CLASS'].to_s)
|
35
|
+
batch = ENV['BATCH'].to_i || 1000
|
36
|
+
start = Time.now
|
37
37
|
puts "Redis-Search index data to Redis from [#{klass}]"
|
38
38
|
count = klass.redis_search_index_batch_create(batch, true)
|
39
39
|
puts ''
|
40
|
-
puts "Indexed #{count} rows | Time spend: #{(Time.now -
|
40
|
+
puts "Indexed #{count} rows | Time spend: #{(Time.now - start)}s"
|
41
41
|
puts 'Rebuild Index done.'
|
42
42
|
end
|
43
43
|
|
data/lib/redis-search/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-pinyin
|
@@ -58,8 +58,8 @@ dependencies:
|
|
58
58
|
- - ">="
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: 3.0.0
|
61
|
-
description:
|
62
|
-
|
61
|
+
description: High performance real-time prefix search, indexes store in Redis for
|
62
|
+
Rails application.
|
63
63
|
email:
|
64
64
|
- huacnlee@gmail.com
|
65
65
|
executables: []
|
@@ -93,12 +93,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
93
|
requirements:
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: '0'
|
97
97
|
requirements: []
|
98
98
|
rubyforge_project:
|
99
99
|
rubygems_version: 2.5.1
|
100
100
|
signing_key:
|
101
101
|
specification_version: 4
|
102
|
-
summary: High performance real-time search
|
103
|
-
for Rails applications.
|
102
|
+
summary: High performance real-time prefix search.
|
104
103
|
test_files: []
|