picky 4.12.10 → 4.12.11

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.
@@ -164,10 +164,10 @@ module Picky
164
164
  # Just checked once on the first call.
165
165
  #
166
166
  if redis_with_scripting?
167
- @@ids_script = "local intersected = redis.call('zinterstore', ARGV[1], #(KEYS), unpack(KEYS)); if intersected == 0 then redis.call('del', ARGV[1]); return {}; end local results = redis.call('zrange', ARGV[1], tonumber(ARGV[2]), tonumber(ARGV[3])); redis.call('del', ARGV[1]); return results;"
167
+ @ids_script = "local intersected = redis.call('zinterstore', ARGV[1], #(KEYS), unpack(KEYS)); if intersected == 0 then redis.call('del', ARGV[1]); return {}; end local results = redis.call('zrange', ARGV[1], tonumber(ARGV[2]), tonumber(ARGV[3])); redis.call('del', ARGV[1]); return results;"
168
168
 
169
169
  require 'digest/sha1'
170
- @@ids_sent_once = nil
170
+ @ids_script_hash = nil
171
171
 
172
172
  # Overrides _this_ method.
173
173
  #
@@ -190,6 +190,15 @@ module Picky
190
190
  #
191
191
  ids combinations, amount, offset
192
192
  end
193
+
194
+ # # TODO
195
+ # #
196
+ # def add id, str_or_sym, weight_strategy, similarity_strategy, where
197
+ #
198
+ #
199
+ # weight = weight_strategy.weight_for ids.size
200
+ # similar = similarity_strategy.encode str_or_sym
201
+ # end
193
202
 
194
203
  # Generate a multiple host/process safe result id.
195
204
  #
@@ -224,27 +233,35 @@ module Picky
224
233
  #
225
234
  begin
226
235
  if identifiers.size > 1
227
- client.evalsha @@ids_sent_once,
228
- identifiers.size,
229
- *identifiers,
230
- generate_intermediate_result_id,
231
- offset,
232
- (offset + amount)
236
+ if @ids_script_hash
237
+ # Reuse script already installed in Redis.
238
+ #
239
+ client.evalsha @ids_script_hash,
240
+ identifiers,
241
+ [
242
+ generate_intermediate_result_id,
243
+ offset,
244
+ (offset + amount)
245
+ ]
246
+ else
247
+ # Install script in Redis.
248
+ #
249
+ @ids_script_hash = Digest::SHA1.hexdigest @ids_script
250
+ client.eval @ids_script,
251
+ identifiers,
252
+ [
253
+ generate_intermediate_result_id,
254
+ offset,
255
+ (offset + amount)
256
+ ]
257
+ end
233
258
  else
259
+ # No complex calculation necessary.
260
+ #
234
261
  client.zrange identifiers.first,
235
262
  offset,
236
263
  (offset + amount)
237
264
  end
238
- rescue RuntimeError => e
239
- # Make the server have a SHA-1 for the script.
240
- #
241
- @@ids_sent_once = Digest::SHA1.hexdigest @@ids_script
242
- client.eval @@ids_script,
243
- identifiers.size,
244
- *identifiers,
245
- generate_intermediate_result_id,
246
- offset,
247
- (offset + amount)
248
265
  end
249
266
  end
250
267
  end
@@ -474,7 +474,7 @@ describe "Realtime Indexing" do
474
474
  end
475
475
  end
476
476
 
477
- context 'special index' do
477
+ context 'with Redis backend' do
478
478
  let(:index) do
479
479
  Picky::Index.new(:books) do
480
480
  backend Picky::Backends::Redis.new(realtime: true)
@@ -493,6 +493,20 @@ describe "Realtime Indexing" do
493
493
  it 'finds the first entry' do
494
494
  books.search('title:Titl').ids.should == ['one']
495
495
  end
496
+
497
+ it 'finds the first entry' do
498
+ books.search('author:author title:Titl').ids.should == ['one']
499
+ end
500
+
501
+ it 'finds the first entry' do
502
+ books.search('Author Titl').ids.should == ['one']
503
+ end
504
+
505
+ it 'finds the first entry the second time, too' do
506
+ books.search('author:author title:Titl')
507
+
508
+ books.search('author:author title:Titl').ids.should == ['one']
509
+ end
496
510
 
497
511
  it 'allows removing a single category and leaving the others alone' do
498
512
  index[:title].remove 'one'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: picky
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.12.10
4
+ version: 4.12.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 4.12.10
37
+ version: 4.12.11
38
38
  type: :development
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 4.12.10
45
+ version: 4.12.11
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: text
48
48
  requirement: !ruby/object:Gem::Requirement