picky 3.6.10 → 3.6.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -156,27 +156,35 @@ module Picky
156
156
 
157
157
  result_id = generate_intermediate_result_id
158
158
 
159
- # Intersect and store.
159
+ # Little optimization.
160
160
  #
161
- intersected = client.zinterstore result_id, identifiers
162
-
163
- # Return clean and early if there has been no intersection.
161
+ # TODO Include in the scripting version as well.
164
162
  #
165
- if intersected.zero?
166
- client.del result_id
167
- return []
168
- end
163
+ if identifiers.size > 1
164
+ # Intersect and store.
165
+ #
166
+ intersected = client.zinterstore result_id, identifiers
169
167
 
170
- # Get the stored result.
171
- #
172
- results = client.zrange result_id, offset, (offset + amount)
168
+ # Return clean and early if there has been no intersection.
169
+ #
170
+ if intersected.zero?
171
+ client.del result_id
172
+ return []
173
+ end
173
174
 
174
- # Delete the stored result as it was only for temporary purposes.
175
- #
176
- # Note: I could also not delete it, but that
177
- # would not be clean at all.
178
- #
179
- client.del result_id
175
+ # Get the stored result.
176
+ #
177
+ results = client.zrange result_id, offset, (offset + amount)
178
+
179
+ # Delete the stored result as it was only for temporary purposes.
180
+ #
181
+ # Note: I could also not delete it, but that
182
+ # would not be clean at all.
183
+ #
184
+ client.del result_id
185
+ else
186
+ results = client.zrange identifiers.first, offset, (offset + amount)
187
+ end
180
188
 
181
189
  results
182
190
  end
@@ -25,9 +25,7 @@ module Picky
25
25
  res = db.execute "SELECT value FROM key_value WHERE key = ? LIMIT 1",
26
26
  key.to_s
27
27
 
28
- return nil unless res
29
-
30
- array = res.empty? ? [] : Yajl::Parser.parse(res.first.first)
28
+ array = res.blank? ? [] : Yajl::Parser.parse(res.first.first)
31
29
  DirectlyManipulable.make self, array, key
32
30
  array
33
31
  end
data/lib/picky/bundle.rb CHANGED
@@ -59,7 +59,7 @@ module Picky
59
59
  reset_backend
60
60
  end
61
61
  def identifier
62
- "#{category.identifier}:#{name}"
62
+ :"#{category.identifier}:#{name}"
63
63
  end
64
64
 
65
65
  # If no specific backend has been set,
@@ -127,11 +127,13 @@ module Picky
127
127
  def similar text
128
128
  code = similarity_strategy.encoded text
129
129
  similar_codes = code && @similarity[code]
130
- if similar_codes
131
- similar_codes = similar_codes.dup # TODO
130
+ if similar_codes.blank?
131
+ [] # Return a simple array.
132
+ else
133
+ similar_codes = similar_codes.dup
132
134
  similar_codes.delete text
135
+ similar_codes
133
136
  end
134
- similar_codes || []
135
137
  end
136
138
 
137
139
  # If a key format is set, use it, else delegate to the category.
@@ -7,21 +7,24 @@ module Picky
7
7
  def remove id
8
8
  # Is it anywhere?
9
9
  #
10
- syms = @realtime[id]
11
- return unless syms
10
+ str_or_syms = @realtime[id]
12
11
 
13
- syms.each do |sym|
14
- ids = @inverted[sym]
12
+ return if str_or_syms.blank?
13
+
14
+ str_or_syms.each do |str_or_sym|
15
+ ids = @inverted[str_or_sym]
15
16
  ids.delete id
16
17
 
17
18
  if ids.empty?
18
- @inverted.delete sym
19
- @weights.delete sym
19
+ @inverted.delete str_or_sym
20
+ @weights.delete str_or_sym
21
+
20
22
  # Since no element uses this sym anymore, we can delete the similarity for it.
21
23
  # TODO Not really. Since multiple syms can point to the same encoded.
22
- @similarity.delete self.similarity_strategy.encoded(sym)
24
+ #
25
+ @similarity.delete self.similarity_strategy.encoded(str_or_sym)
23
26
  else
24
- @weights[sym] = self.weights_strategy.weight_for ids.size
27
+ @weights[str_or_sym] = self.weights_strategy.weight_for ids.size
25
28
  end
26
29
  end
27
30
 
@@ -31,7 +34,7 @@ module Picky
31
34
  # Returns a reference to the array where the id has been added.
32
35
  #
33
36
  def add id, str_or_sym, where = :unshift
34
- str_or_syms = @realtime[id] || (@realtime[id] = [])
37
+ str_or_syms = @realtime[id] ||= []
35
38
 
36
39
  # Inverted.
37
40
  #
@@ -46,7 +49,7 @@ module Picky
46
49
 
47
50
  # TODO Introduce a new method?
48
51
  #
49
- ids = @inverted[str_or_sym] || (@inverted[str_or_sym] = []) # Ensures that we get an extended Array
52
+ ids = @inverted[str_or_sym] ||= []
50
53
  ids.send where, id
51
54
  end
52
55
 
@@ -69,12 +72,12 @@ module Picky
69
72
  #
70
73
  def add_similarity str_or_sym, where = :unshift
71
74
  if encoded = self.similarity_strategy.encoded(str_or_sym)
72
- similarity = @similarity[encoded] || (@similarity[encoded] = []) # Ensures that we get an extended Array
75
+ similars = @similarity[encoded] ||= []
73
76
 
74
77
  # Not completely correct, as others will also be affected, but meh.
75
78
  #
76
- similarity.delete str_or_sym if similarity.include? str_or_sym
77
- similarity.send where, str_or_sym
79
+ similars.delete str_or_sym if similars.include? str_or_sym
80
+ similars.send where, str_or_sym
78
81
  end
79
82
  end
80
83
 
@@ -96,8 +99,7 @@ module Picky
96
99
  clear_realtime
97
100
  @inverted.each_pair do |str_or_sym, ids|
98
101
  ids.each do |id|
99
- str_or_syms = @realtime[id]
100
- str_or_syms = (@realtime[id] = []) unless str_or_syms # TODO Nicefy.
102
+ str_or_syms = @realtime[id] ||= []
101
103
  @realtime[id] << str_or_sym unless str_or_syms.include? str_or_sym
102
104
  end
103
105
  end
@@ -136,7 +136,7 @@ module Picky
136
136
  # Identifier for technical output.
137
137
  #
138
138
  def identifier
139
- "#{@index.identifier}:#{name}"
139
+ :"#{@index.identifier}:#{name}"
140
140
  end
141
141
 
142
142
  #
data/lib/picky/console.rb CHANGED
@@ -7,7 +7,7 @@ module Picky
7
7
  #
8
8
  class Console
9
9
 
10
- def self.start *args
10
+ def self.start args = ARGV
11
11
  irb = 'irb'
12
12
 
13
13
  require 'optparse'
@@ -46,7 +46,7 @@ module Picky
46
46
  # The identifier for this combination.
47
47
  #
48
48
  def identifier
49
- "#{category.bundle_for(token).identifier}:#{token.identifier}"
49
+ @identifier ||= "#{category.bundle_for(token).identifier}:inverted:#{token.text}"
50
50
  end
51
51
 
52
52
  # Note: Required for uniq!
@@ -54,7 +54,7 @@ module Picky
54
54
  # TODO Ok with category or is the bundle needed?
55
55
  #
56
56
  def hash
57
- [token.to_s, category].hash
57
+ [token, category].hash
58
58
  end
59
59
 
60
60
  # Combines the category names with the original names.
@@ -71,7 +71,7 @@ module Picky
71
71
  # "exact title:Peter*:peter"
72
72
  #
73
73
  def to_s
74
- "#{category.bundle_for(token).identifier} #{to_result.join(':')}"
74
+ "#{category.bundle_for(token).identifier}(#{to_result.join(':')})"
75
75
  end
76
76
 
77
77
  end
@@ -54,6 +54,12 @@ module Picky
54
54
  @combinations.map &:to_result
55
55
  end
56
56
 
57
+ #
58
+ #
59
+ def to_s
60
+ @combinations.to_s
61
+ end
62
+
57
63
  end
58
64
 
59
65
  end
@@ -25,6 +25,9 @@ module Picky
25
25
  :dump,
26
26
  :load,
27
27
 
28
+ :bundle_for,
29
+ :build_realtime_mapping,
30
+
28
31
  :to => :@category
29
32
 
30
33
  def initialize category
@@ -17,16 +17,16 @@ describe Picky::Bundle do
17
17
  backend: Picky::Backends::Memory.new
18
18
  end
19
19
 
20
- it 'is by default an SQLite Array' do
20
+ it 'is by default a Hash' do
21
21
  @bundle.realtime.should be_kind_of(Hash)
22
22
  end
23
- it 'is by default an SQLite Array' do
23
+ it 'is by default a Hash' do
24
24
  @bundle.inverted.should be_kind_of(Hash)
25
25
  end
26
- it 'is by default an SQLite Value' do
26
+ it 'is by default a Hash' do
27
27
  @bundle.weights.should be_kind_of(Hash)
28
28
  end
29
- it 'is by default an SQLite Array' do
29
+ it 'is by default a Hash' do
30
30
  @bundle.similarity.should be_kind_of(Hash)
31
31
  end
32
32
 
@@ -58,7 +58,7 @@ describe 'Search#max_allocations' do
58
58
 
59
59
  performance_of do
60
60
  try_again.search('hello world')
61
- end.should < (threshold*2/3)
61
+ end.should < (threshold*7/9)
62
62
  end
63
63
 
64
64
  end
@@ -10,6 +10,18 @@ describe Picky::Backends::Redis::DirectlyManipulable do
10
10
  list
11
11
  end
12
12
 
13
+ context 'problem cases' do
14
+ it 'does not dup its special abilities' do
15
+ list = [1,2]
16
+ described_class.make backend, list, 'some:key'
17
+ dupped_list = list.dup
18
+
19
+ client.should_receive(:zadd).never
20
+
21
+ dupped_list << 1
22
+ end
23
+ end
24
+
13
25
  context 'stubbed backend' do
14
26
  before(:each) do
15
27
  backend.stub! :[]
@@ -16,7 +16,7 @@ describe Picky::Bundle do
16
16
 
17
17
  describe 'identifier' do
18
18
  it 'is correct' do
19
- bundle.identifier.should == 'some_index:some_category:some_name'
19
+ bundle.identifier.should == :'some_index:some_category:some_name'
20
20
  end
21
21
  end
22
22
 
@@ -73,7 +73,7 @@ describe Picky::Bundle do
73
73
 
74
74
  describe 'identifier' do
75
75
  it 'should return a specific identifier' do
76
- @bundle.identifier.should == 'some_index:some_category:some_name'
76
+ @bundle.identifier.should == :'some_index:some_category:some_name'
77
77
  end
78
78
  end
79
79
 
@@ -11,8 +11,8 @@ describe Picky::Bundle do
11
11
  let(:bundle) { described_class.new :some_name, @category, @weights, :some_partial, @similarity }
12
12
 
13
13
  describe 'identifier' do
14
- it 'is correct' do
15
- bundle.identifier.should == 'some_index:some_category:some_name'
14
+ it 'should return a specific identifier' do
15
+ bundle.identifier.should == :'some_index:some_category:some_name'
16
16
  end
17
17
  end
18
18
 
@@ -35,12 +35,6 @@ describe Picky::Bundle do
35
35
  end
36
36
  end
37
37
 
38
- describe 'identifier' do
39
- it 'should return a specific identifier' do
40
- bundle.identifier.should == 'some_index:some_category:some_name'
41
- end
42
- end
43
-
44
38
  describe 'dump' do
45
39
  it 'should trigger dumps' do
46
40
  bundle.stub! :timed_exclaim
@@ -19,13 +19,13 @@ describe Picky::Query::Combination do
19
19
  it "shows the combination's info" do
20
20
  @token.stub! :to_result => :token_result
21
21
 
22
- @combination.to_s.should == 'bundle_name some_category_name:token_result'
22
+ @combination.to_s.should == 'bundle_name(some_category_name:token_result)'
23
23
  end
24
24
  end
25
25
 
26
26
  describe 'hash' do
27
27
  it 'should hash the token and the bundle' do
28
- @combination.hash.should == [@token.to_s, @category].hash
28
+ @combination.hash.should == [@token, @category].hash
29
29
  end
30
30
  end
31
31
 
@@ -49,7 +49,7 @@ describe Picky::Query::Combination do
49
49
 
50
50
  describe 'identifier' do
51
51
  it 'should get the category name from the bundle' do
52
- @combination.identifier.should == "bundle_name:similarity:some_text"
52
+ @combination.identifier.should == "bundle_name:inverted:some_text"
53
53
  end
54
54
  end
55
55
 
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: 3.6.10
4
+ version: 3.6.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-11-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70314739778860 !ruby/object:Gem::Requirement
16
+ requirement: &70356380283200 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,21 +21,21 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70314739778860
24
+ version_requirements: *70356380283200
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: picky-client
27
- requirement: &70314739778280 !ruby/object:Gem::Requirement
27
+ requirement: &70356380282520 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
31
31
  - !ruby/object:Gem::Version
32
- version: 3.6.10
32
+ version: 3.6.11
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70314739778280
35
+ version_requirements: *70356380282520
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rack
38
- requirement: &70314739777820 !ruby/object:Gem::Requirement
38
+ requirement: &70356380282100 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70314739777820
46
+ version_requirements: *70356380282100
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rack_fast_escape
49
- requirement: &70314739777360 !ruby/object:Gem::Requirement
49
+ requirement: &70356380281640 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70314739777360
57
+ version_requirements: *70356380281640
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: text
60
- requirement: &70314739776940 !ruby/object:Gem::Requirement
60
+ requirement: &70356380281200 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70314739776940
68
+ version_requirements: *70356380281200
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: yajl-ruby
71
- requirement: &70314739776520 !ruby/object:Gem::Requirement
71
+ requirement: &70356380280720 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70314739776520
79
+ version_requirements: *70356380280720
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: activesupport
82
- requirement: &70314739776020 !ruby/object:Gem::Requirement
82
+ requirement: &70356380280220 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '3.0'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *70314739776020
90
+ version_requirements: *70356380280220
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: unicorn
93
- requirement: &70314739775600 !ruby/object:Gem::Requirement
93
+ requirement: &70356380279800 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :runtime
100
100
  prerelease: false
101
- version_requirements: *70314739775600
101
+ version_requirements: *70356380279800
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: sinatra
104
- requirement: &70314739775120 !ruby/object:Gem::Requirement
104
+ requirement: &70356380279340 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,7 +109,7 @@ dependencies:
109
109
  version: '0'
110
110
  type: :runtime
111
111
  prerelease: false
112
- version_requirements: *70314739775120
112
+ version_requirements: *70356380279340
113
113
  description: Fast Ruby semantic text search engine with comfortable single field interface.
114
114
  email: florian.hanke+picky@gmail.com
115
115
  executables: