picky 4.5.3 → 4.5.4
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/lib/picky/query/allocation.rb +3 -10
- data/lib/picky/query/allocations.rb +2 -2
- data/lib/picky/query/boosts.rb +1 -1
- data/lib/picky/query/combination.rb +0 -8
- data/lib/picky/query/combinations.rb +5 -5
- data/lib/picky/query/indexes.rb +4 -2
- data/lib/picky/query/token.rb +2 -0
- data/spec/functional/allocations_uniq_by_definition_spec.rb +36 -0
- data/spec/lib/query/allocation_spec.rb +7 -7
- data/spec/lib/query/combination_spec.rb +17 -17
- data/spec/lib/query/combinations_spec.rb +7 -7
- data/spec/lib/query/indexes_spec.rb +2 -2
- metadata +19 -17
@@ -23,23 +23,16 @@ module Picky
|
|
23
23
|
def initialize index, combinations
|
24
24
|
@combinations = combinations
|
25
25
|
|
26
|
-
# Could this be rewritten?
|
26
|
+
# TODO Could this be rewritten?
|
27
27
|
#
|
28
28
|
@result_identifier = index.result_identifier
|
29
29
|
@backend = index.backend
|
30
30
|
end
|
31
31
|
|
32
|
-
def hash
|
33
|
-
@combinations.hash
|
34
|
-
end
|
35
|
-
# def eql? other
|
36
|
-
# self.class == other.class && combinations.eql?(other.combinations)
|
37
|
-
# end
|
38
|
-
|
39
32
|
# Asks the backend for the total score and
|
40
33
|
# adds the boosts to it.
|
41
34
|
#
|
42
|
-
# THINK Can the combinations be empty?
|
35
|
+
# TODO THINK Can the combinations be empty?
|
43
36
|
#
|
44
37
|
def calculate_score weights
|
45
38
|
@score ||= if @combinations.empty?
|
@@ -52,7 +45,7 @@ module Picky
|
|
52
45
|
|
53
46
|
# Asks the backend for the (intersected) ids.
|
54
47
|
#
|
55
|
-
# THINK Can the combinations be empty?
|
48
|
+
# TODO THINK Can the combinations be empty?
|
56
49
|
#
|
57
50
|
def calculate_ids amount, offset
|
58
51
|
return [] if @combinations.empty?
|
@@ -138,7 +138,7 @@ module Picky
|
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
141
|
-
def uniq
|
141
|
+
def uniq!
|
142
142
|
@allocations.uniq!
|
143
143
|
end
|
144
144
|
|
@@ -154,7 +154,7 @@ module Picky
|
|
154
154
|
# ]
|
155
155
|
#
|
156
156
|
def to_result
|
157
|
-
@allocations.map
|
157
|
+
@allocations.map { |allocation| allocation.to_result }.compact
|
158
158
|
end
|
159
159
|
|
160
160
|
# Simply inspects the internal allocations.
|
data/lib/picky/query/boosts.rb
CHANGED
@@ -61,7 +61,7 @@ module Picky
|
|
61
61
|
# Note: Maybe make combinations comparable to Symbols?
|
62
62
|
#
|
63
63
|
def boost_for combinations
|
64
|
-
boost_for_categories combinations.map
|
64
|
+
boost_for_categories combinations.map { |combination| combination.category_name }
|
65
65
|
end
|
66
66
|
|
67
67
|
# A Weights instance is == to another if
|
@@ -51,14 +51,6 @@ module Picky
|
|
51
51
|
@identifier ||= "#{bundle.identifier}:inverted:#{token.text}"
|
52
52
|
end
|
53
53
|
|
54
|
-
# Note: Required for uniq!
|
55
|
-
#
|
56
|
-
# THINK Ok with category or is the bundle needed?
|
57
|
-
#
|
58
|
-
def hash
|
59
|
-
[token, category].hash
|
60
|
-
end
|
61
|
-
|
62
54
|
# Combines the category names with the original names.
|
63
55
|
# [
|
64
56
|
# [:title, 'Flarbl', :flarbl],
|
@@ -22,12 +22,12 @@ module Picky
|
|
22
22
|
@combinations = combinations
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
# Sums up the weights of the combinations.
|
26
|
+
#
|
27
|
+
# Note: Optimized sum(&:weight) away – ~3% improvement.
|
28
|
+
#
|
29
29
|
def score
|
30
|
-
@combinations.
|
30
|
+
@combinations.inject(0) { |total, combination| total + combination.weight }
|
31
31
|
end
|
32
32
|
def boost_for weights
|
33
33
|
weights.boost_for @combinations
|
data/lib/picky/query/indexes.rb
CHANGED
@@ -62,9 +62,11 @@ module Picky
|
|
62
62
|
def prepared_allocations_for tokens, weights = {}, amount = nil
|
63
63
|
allocations = allocations_for tokens
|
64
64
|
|
65
|
-
# Remove double allocations.
|
65
|
+
# Removed: Remove potential double allocations.
|
66
66
|
#
|
67
|
-
allocations.
|
67
|
+
# Note: allocations are unique by definition.
|
68
|
+
#
|
69
|
+
# allocations.uniq! unless tokens.uniq?
|
68
70
|
|
69
71
|
# Score the allocations using weights as bias.
|
70
72
|
#
|
data/lib/picky/query/token.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
# This spec exists to prove that it is unnecessary
|
6
|
+
# to call allocations.uniq! when putting together results.
|
7
|
+
#
|
8
|
+
describe 'uniqueness of allocations' do
|
9
|
+
|
10
|
+
it 'is already uniq' do
|
11
|
+
index = Picky::Index.new :already_uniq do
|
12
|
+
category :category1
|
13
|
+
category :category2
|
14
|
+
category :category3
|
15
|
+
end
|
16
|
+
|
17
|
+
thing = Struct.new(:id, :category1, :category2, :category3)
|
18
|
+
index.add thing.new(1, 'text1', 'text2', 'text3')
|
19
|
+
|
20
|
+
try = Picky::Search.new index do
|
21
|
+
max_allocations 100
|
22
|
+
end
|
23
|
+
|
24
|
+
# Picky finds three categories.
|
25
|
+
#
|
26
|
+
try.search('text*').ids.should == [1,1,1]
|
27
|
+
|
28
|
+
# Picky finds 9 possible allocations.
|
29
|
+
#
|
30
|
+
try.search('text* text*').ids.should == [1,1,1]*3
|
31
|
+
|
32
|
+
# Picky finds 27 possible allocations.
|
33
|
+
#
|
34
|
+
try.search('text* text* text*', 100).ids.should == [1,1,1]*3*3
|
35
|
+
end
|
36
|
+
end
|
@@ -9,13 +9,13 @@ describe Picky::Query::Allocation do
|
|
9
9
|
@allocation = described_class.new @index, @combinations
|
10
10
|
end
|
11
11
|
|
12
|
-
describe "hash" do
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
12
|
+
# describe "hash" do
|
13
|
+
# it "delegates to the combinations" do
|
14
|
+
# @combinations.should_receive(:hash).once.with
|
15
|
+
#
|
16
|
+
# @allocation.hash
|
17
|
+
# end
|
18
|
+
# end
|
19
19
|
|
20
20
|
describe "to_s" do
|
21
21
|
before(:each) do
|
@@ -23,23 +23,23 @@ describe Picky::Query::Combination do
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
describe 'hash' do
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
26
|
+
# describe 'hash' do
|
27
|
+
# it 'should hash the token and the bundle' do
|
28
|
+
# @combination.hash.should == [@token, @category].hash
|
29
|
+
# end
|
30
|
+
# it 'should distinguish two combinations sufficiently' do
|
31
|
+
# category1 = stub :category,
|
32
|
+
# :identifier => 'some_category_identifier1'
|
33
|
+
#
|
34
|
+
# category2 = stub :category,
|
35
|
+
# :identifier => 'some_category_identifier2'
|
36
|
+
#
|
37
|
+
# combination1 = described_class.new @token, category1
|
38
|
+
# combination2 = described_class.new @token, category2
|
39
|
+
#
|
40
|
+
# combination1.hash.should_not == combination2.hash
|
41
|
+
# end
|
42
|
+
# end
|
43
43
|
|
44
44
|
describe 'to_result' do
|
45
45
|
context 'functional with qualifier' do
|
@@ -47,13 +47,13 @@ describe Picky::Query::Combinations do
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
describe 'hash' do
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
50
|
+
# describe 'hash' do
|
51
|
+
# it "delegates to the combinations array" do
|
52
|
+
# @combinations_ary.should_receive(:hash).once.with
|
53
|
+
#
|
54
|
+
# @combinations.hash
|
55
|
+
# end
|
56
|
+
# end
|
57
57
|
|
58
58
|
describe 'remove' do
|
59
59
|
before(:each) do
|
@@ -91,14 +91,14 @@ describe Picky::Query::Indexes do
|
|
91
91
|
indexes.stub! :allocations_for => @allocations
|
92
92
|
end
|
93
93
|
it 'calls the right method in order' do
|
94
|
-
@allocations.should_receive(:uniq).once.ordered.with()
|
94
|
+
# @allocations.should_receive(:uniq!).once.ordered.with()
|
95
95
|
@allocations.should_receive(:calculate_score).once.ordered.with(:some_weights)
|
96
96
|
@allocations.should_receive(:sort!).once.ordered.with()
|
97
97
|
|
98
98
|
indexes.prepared_allocations_for :some_tokens, :some_weights
|
99
99
|
end
|
100
100
|
it 'calls the right method in order' do
|
101
|
-
@allocations.should_receive(:uniq).once.ordered.with()
|
101
|
+
# @allocations.should_receive(:uniq!).once.ordered.with()
|
102
102
|
@allocations.should_receive(:calculate_score).once.ordered.with({})
|
103
103
|
@allocations.should_receive(:sort!).once.ordered.with()
|
104
104
|
|
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.5.
|
4
|
+
version: 4.5.4
|
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: 2012-07-
|
12
|
+
date: 2012-07-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70333809340140 !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: *
|
24
|
+
version_requirements: *70333809340140
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: picky-client
|
27
|
-
requirement: &
|
27
|
+
requirement: &70333809339480 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 4.5.
|
32
|
+
version: 4.5.4
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70333809339480
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: text
|
38
|
-
requirement: &
|
38
|
+
requirement: &70333809338840 !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: *
|
46
|
+
version_requirements: *70333809338840
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: multi_json
|
49
|
-
requirement: &
|
49
|
+
requirement: &70333809338380 !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: *
|
57
|
+
version_requirements: *70333809338380
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: activesupport
|
60
|
-
requirement: &
|
60
|
+
requirement: &70333809337880 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '3.0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70333809337880
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: procrastinate
|
71
|
-
requirement: &
|
71
|
+
requirement: &70333809353740 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0.4'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70333809353740
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: rack_fast_escape
|
82
|
-
requirement: &
|
82
|
+
requirement: &70333809353360 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :runtime
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70333809353360
|
91
91
|
description: Fast Ruby semantic text search engine with comfortable single field interface.
|
92
92
|
email: florian.hanke+picky@gmail.com
|
93
93
|
executables:
|
@@ -242,6 +242,7 @@ files:
|
|
242
242
|
- spec/aux/picky/cli_spec.rb
|
243
243
|
- spec/category_realtime_spec.rb
|
244
244
|
- spec/ext/performant_spec.rb
|
245
|
+
- spec/functional/allocations_uniq_by_definition_spec.rb
|
245
246
|
- spec/functional/backends/file_spec.rb
|
246
247
|
- spec/functional/backends/memory_bundle_realtime_spec.rb
|
247
248
|
- spec/functional/backends/memory_json_utf8_spec.rb
|
@@ -396,6 +397,7 @@ test_files:
|
|
396
397
|
- spec/aux/picky/cli_spec.rb
|
397
398
|
- spec/category_realtime_spec.rb
|
398
399
|
- spec/ext/performant_spec.rb
|
400
|
+
- spec/functional/allocations_uniq_by_definition_spec.rb
|
399
401
|
- spec/functional/backends/file_spec.rb
|
400
402
|
- spec/functional/backends/memory_bundle_realtime_spec.rb
|
401
403
|
- spec/functional/backends/memory_json_utf8_spec.rb
|