picky 3.5.0 → 3.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/picky/bundle.rb +37 -4
- data/lib/picky/bundle_indexed.rb +12 -8
- data/lib/picky/bundle_indexing.rb +6 -26
- data/lib/picky/bundle_realtime.rb +26 -16
- data/lib/picky/category_indexing.rb +1 -3
- data/lib/picky/category_realtime.rb +1 -1
- data/lib/picky/character_substituters/west_european.rb +4 -4
- data/lib/picky/generators/partial/infix.rb +0 -47
- data/lib/picky/generators/partial/none.rb +0 -6
- data/lib/picky/generators/partial/substring.rb +0 -47
- data/lib/picky/generators/similarity/double_metaphone.rb +3 -3
- data/lib/picky/generators/similarity/metaphone.rb +3 -3
- data/lib/picky/generators/similarity/phonetic.rb +12 -24
- data/lib/picky/generators/similarity/soundex.rb +3 -3
- data/lib/picky/generators/weights/constant.rb +46 -0
- data/lib/picky/generators/weights/dynamic.rb +37 -0
- data/lib/picky/generators/weights/logarithmic.rb +0 -10
- data/lib/picky/generators/weights/runtime.rb +41 -0
- data/lib/picky/loader.rb +3 -3
- data/lib/picky/query/allocations.rb +2 -1
- data/lib/picky/query/tokens.rb +0 -10
- data/spec/lib/category_indexed_spec.rb +1 -1
- data/spec/lib/character_substituters/west_european_spec.rb +11 -13
- data/spec/lib/generators/partial/infix_spec.rb +161 -161
- data/spec/lib/generators/partial/none_spec.rb +3 -3
- data/spec/lib/generators/partial/postfix_spec.rb +109 -109
- data/spec/lib/generators/partial/substring_spec.rb +190 -190
- data/spec/lib/generators/similarity/double_metaphone_spec.rb +38 -38
- data/spec/lib/generators/similarity/metaphone_spec.rb +38 -38
- data/spec/lib/generators/similarity/soundex_spec.rb +38 -38
- data/spec/lib/generators/weights/constant_spec.rb +37 -0
- data/spec/lib/generators/weights/dynamic_spec.rb +27 -0
- data/spec/lib/generators/weights/logarithmic_spec.rb +10 -15
- data/spec/lib/indexed/bundle_spec.rb +3 -2
- data/spec/lib/indexed/wrappers/bundle/calculation_spec.rb +8 -8
- data/spec/lib/indexing/bundle_spec.rb +5 -3
- data/spec/specific/dynamic_weights_spec.rb +44 -0
- metadata +36 -28
- data/lib/picky/generators/base.rb +0 -19
@@ -13,48 +13,48 @@ describe Picky::Generators::Similarity::DoubleMetaphone do
|
|
13
13
|
@similarity.encoded(text).should == expected
|
14
14
|
end
|
15
15
|
end
|
16
|
-
def self.it_should_generate_from index, expected
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
16
|
+
# def self.it_should_generate_from index, expected
|
17
|
+
# it "should generate #{expected.inspect} correctly from #{index.inspect}" do
|
18
|
+
# @similarity.generate_from(index).should == expected
|
19
|
+
# end
|
20
|
+
# end
|
21
21
|
|
22
22
|
it_should_encode :meier, :MR
|
23
23
|
it_should_encode :grossberger, :KRSP
|
24
24
|
it_should_encode :hadelbla, :HTLP
|
25
25
|
|
26
|
-
it_should_generate_from({}, {})
|
27
|
-
it_should_generate_from({ :maier => nil, :meier => nil }, :MR => [:maier, :meier]) # should be correctly ordered
|
28
|
-
it_should_generate_from({ :maier => nil, :meier => nil, :hallaballa => nil }, :MR => [:maier, :meier], :HLPL => [:hallaballa])
|
29
|
-
it_should_generate_from({ :susan => nil, :susanne => nil, :bruderer => nil }, :SSN => [:susan, :susanne], :PRTR => [:bruderer])
|
30
|
-
|
31
|
-
describe 'with reduced amount' do
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
describe 'hashify' do
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
context 'integration' do
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
26
|
+
# it_should_generate_from({}, {})
|
27
|
+
# it_should_generate_from({ :maier => nil, :meier => nil }, :MR => [:maier, :meier]) # should be correctly ordered
|
28
|
+
# it_should_generate_from({ :maier => nil, :meier => nil, :hallaballa => nil }, :MR => [:maier, :meier], :HLPL => [:hallaballa])
|
29
|
+
# it_should_generate_from({ :susan => nil, :susanne => nil, :bruderer => nil }, :SSN => [:susan, :susanne], :PRTR => [:bruderer])
|
30
|
+
|
31
|
+
# describe 'with reduced amount' do
|
32
|
+
# before(:each) do
|
33
|
+
# @similarity = described_class.new(1)
|
34
|
+
# end
|
35
|
+
# it_should_generate_from({ :maier => nil, :meier => nil }, :MR => [:maier])
|
36
|
+
# it_should_generate_from({ :susan => nil, :susanne => nil, :bruderer => nil }, :SSN => [:susan], :PRTR => [:bruderer])
|
37
|
+
# end
|
38
|
+
|
39
|
+
# describe 'hashify' do
|
40
|
+
# it 'should turn an empty list into an empty hash' do
|
41
|
+
# @similarity.send(:hashify, []).should == {}
|
42
|
+
# end
|
43
|
+
# it 'should turn the list into an unordered similarity' do
|
44
|
+
# @similarity.send(:hashify, [:meier, :maier]).should == { :MR => [:meier, :maier] }
|
45
|
+
# end
|
46
|
+
# it 'should turn the list into a encoded hash' do
|
47
|
+
# @similarity.send(:hashify, [:meier, :maier, :peter]).should == { :MR => [:meier, :maier], :PTR => [:peter] }
|
48
|
+
# end
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
# context 'integration' do
|
52
|
+
# it 'should return the right ordered array' do
|
53
|
+
# index = @similarity.generate_from :meier => nil, :maier => nil, :mairai => nil, :mair => nil, :meira => nil
|
54
|
+
# code = @similarity.encoded :maier
|
55
|
+
#
|
56
|
+
# index[code].should == [:mair, :maier, :meier, :meira, :mairai]
|
57
|
+
# end
|
58
|
+
# end
|
59
59
|
|
60
60
|
end
|
@@ -13,48 +13,48 @@ describe Picky::Generators::Similarity::Metaphone do
|
|
13
13
|
@similarity.encoded(text).should == expected
|
14
14
|
end
|
15
15
|
end
|
16
|
-
def self.it_should_generate_from index, expected
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
16
|
+
# def self.it_should_generate_from index, expected
|
17
|
+
# it "should generate #{expected.inspect} correctly from #{index.inspect}" do
|
18
|
+
# @similarity.generate_from(index).should == expected
|
19
|
+
# end
|
20
|
+
# end
|
21
21
|
|
22
22
|
it_should_encode :meier, :MR
|
23
23
|
it_should_encode :grossberger, :KRSBRJR
|
24
24
|
it_should_encode :hadelbla, :HTLBL
|
25
25
|
|
26
|
-
it_should_generate_from({}, {})
|
27
|
-
it_should_generate_from({ :maier => nil, :meier => nil }, :MR => [:maier, :meier]) # should be correctly ordered
|
28
|
-
it_should_generate_from({ :maier => nil, :meier => nil, :hallaballa => nil }, :MR => [:maier, :meier], :HLBL => [:hallaballa])
|
29
|
-
it_should_generate_from({ :susan => nil, :susanne => nil, :bruderer => nil }, :SSN => [:susan, :susanne], :BRTRR => [:bruderer])
|
30
|
-
|
31
|
-
describe 'with reduced amount' do
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
describe 'hashify' do
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
context 'integration' do
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
26
|
+
# it_should_generate_from({}, {})
|
27
|
+
# it_should_generate_from({ :maier => nil, :meier => nil }, :MR => [:maier, :meier]) # should be correctly ordered
|
28
|
+
# it_should_generate_from({ :maier => nil, :meier => nil, :hallaballa => nil }, :MR => [:maier, :meier], :HLBL => [:hallaballa])
|
29
|
+
# it_should_generate_from({ :susan => nil, :susanne => nil, :bruderer => nil }, :SSN => [:susan, :susanne], :BRTRR => [:bruderer])
|
30
|
+
|
31
|
+
# describe 'with reduced amount' do
|
32
|
+
# before(:each) do
|
33
|
+
# @similarity = described_class.new(1)
|
34
|
+
# end
|
35
|
+
# it_should_generate_from({ :maier => nil, :meier => nil }, :MR => [:maier])
|
36
|
+
# it_should_generate_from({ :susan => nil, :susanne => nil, :bruderer => nil }, :SSN => [:susan], :BRTRR => [:bruderer])
|
37
|
+
# end
|
38
|
+
#
|
39
|
+
# describe 'hashify' do
|
40
|
+
# it 'should turn an empty list into an empty hash' do
|
41
|
+
# @similarity.send(:hashify, []).should == {}
|
42
|
+
# end
|
43
|
+
# it 'should turn the list into an unordered similarity' do
|
44
|
+
# @similarity.send(:hashify, [:meier, :maier]).should == { :MR => [:meier, :maier] }
|
45
|
+
# end
|
46
|
+
# it 'should turn the list into a encoded hash' do
|
47
|
+
# @similarity.send(:hashify, [:meier, :maier, :peter]).should == { :MR => [:meier, :maier], :PTR => [:peter] }
|
48
|
+
# end
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
# context 'integration' do
|
52
|
+
# it 'should return the right ordered array' do
|
53
|
+
# index = @similarity.generate_from :meier => nil, :maier => nil, :mairai => nil, :mair => nil, :meira => nil
|
54
|
+
# code = @similarity.encoded :maier
|
55
|
+
#
|
56
|
+
# index[code].should == [:mair, :maier, :meier, :meira, :mairai]
|
57
|
+
# end
|
58
|
+
# end
|
59
59
|
|
60
60
|
end
|
@@ -13,48 +13,48 @@ describe Picky::Generators::Similarity::Soundex do
|
|
13
13
|
@similarity.encoded(text).should == expected
|
14
14
|
end
|
15
15
|
end
|
16
|
-
def self.it_should_generate_from index, expected
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
16
|
+
# def self.it_should_generate_from index, expected
|
17
|
+
# it "should generate #{expected.inspect} correctly from #{index.inspect}" do
|
18
|
+
# @similarity.generate_from(index).should == expected
|
19
|
+
# end
|
20
|
+
# end
|
21
21
|
|
22
22
|
it_should_encode :meier, :M600
|
23
23
|
it_should_encode :grossberger, :G621
|
24
24
|
it_should_encode :hadelbla, :H341
|
25
25
|
|
26
|
-
it_should_generate_from({}, {})
|
27
|
-
it_should_generate_from({ :maier => nil, :meier => nil }, :M600 => [:maier, :meier]) # should be correctly ordered
|
28
|
-
it_should_generate_from({ :maier => nil, :meier => nil, :hallaballa => nil }, :M600 => [:maier, :meier], :H414 => [:hallaballa])
|
29
|
-
it_should_generate_from({ :susan => nil, :susanne => nil, :bruderer => nil }, :S250 => [:susan, :susanne], :B636 => [:bruderer])
|
30
|
-
|
31
|
-
describe 'with reduced amount' do
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
describe 'hashify' do
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
context 'integration' do
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
26
|
+
# it_should_generate_from({}, {})
|
27
|
+
# it_should_generate_from({ :maier => nil, :meier => nil }, :M600 => [:maier, :meier]) # should be correctly ordered
|
28
|
+
# it_should_generate_from({ :maier => nil, :meier => nil, :hallaballa => nil }, :M600 => [:maier, :meier], :H414 => [:hallaballa])
|
29
|
+
# it_should_generate_from({ :susan => nil, :susanne => nil, :bruderer => nil }, :S250 => [:susan, :susanne], :B636 => [:bruderer])
|
30
|
+
|
31
|
+
# describe 'with reduced amount' do
|
32
|
+
# before(:each) do
|
33
|
+
# @similarity = described_class.new(1)
|
34
|
+
# end
|
35
|
+
# it_should_generate_from({ :maier => nil, :meier => nil }, :M600 => [:maier])
|
36
|
+
# it_should_generate_from({ :susan => nil, :susanne => nil, :bruderer => nil }, :S250 => [:susan], :B636 => [:bruderer])
|
37
|
+
# end
|
38
|
+
|
39
|
+
# describe 'hashify' do
|
40
|
+
# it 'should turn an empty list into an empty hash' do
|
41
|
+
# @similarity.send(:hashify, []).should == {}
|
42
|
+
# end
|
43
|
+
# it 'should turn the list into an unordered similarity' do
|
44
|
+
# @similarity.send(:hashify, [:meier, :maier]).should == { :M600 => [:meier, :maier] }
|
45
|
+
# end
|
46
|
+
# it 'should turn the list into a encoded hash' do
|
47
|
+
# @similarity.send(:hashify, [:meier, :maier, :peter]).should == { :M600 => [:meier, :maier], :P360 => [:peter] }
|
48
|
+
# end
|
49
|
+
# end
|
50
|
+
|
51
|
+
# context 'integration' do
|
52
|
+
# it 'should return the right ordered array' do
|
53
|
+
# index = @similarity.generate_from :meier => nil, :maier => nil, :mairai => nil, :mair => nil, :meira => nil
|
54
|
+
# code = @similarity.encoded :maier
|
55
|
+
#
|
56
|
+
# index[code].should == [:mair, :maier, :meier, :meira, :mairai]
|
57
|
+
# end
|
58
|
+
# end
|
59
59
|
|
60
60
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Picky::Generators::Weights::Constant do
|
4
|
+
|
5
|
+
context 'default weight' do
|
6
|
+
let(:constant) { described_class.new }
|
7
|
+
|
8
|
+
describe '[]' do
|
9
|
+
it 'is always 0.0' do
|
10
|
+
constant[:whatevs].should == 0.0
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'weight_for' do
|
15
|
+
it 'is 0.0' do
|
16
|
+
constant.weight_for(1234).should == 0.0
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'defined weight' do
|
22
|
+
let(:constant) { described_class.new 3.14 }
|
23
|
+
|
24
|
+
describe '[]' do
|
25
|
+
it 'is always the defined weight' do
|
26
|
+
constant[:whatevs].should == 3.14
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'weight_for' do
|
31
|
+
it 'is always the defined weight' do
|
32
|
+
constant.weight_for(1234).should == 3.14
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Picky::Generators::Weights::Dynamic do
|
4
|
+
|
5
|
+
context 'defined block' do
|
6
|
+
let(:constant) { described_class.new { |str_or_sym| str_or_sym.size } }
|
7
|
+
|
8
|
+
describe '[]' do
|
9
|
+
it 'is the length of the given string' do
|
10
|
+
constant[''].should == 0
|
11
|
+
end
|
12
|
+
it 'is the length of the given string' do
|
13
|
+
constant['whatevs'].should == 7
|
14
|
+
end
|
15
|
+
it 'is the length of the given symbol' do
|
16
|
+
constant[:whatever].should == 8
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'weight_for' do
|
21
|
+
it 'is nil' do
|
22
|
+
constant.weight_for(1234).should == nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -2,28 +2,23 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Picky::Generators::Weights::Logarithmic do
|
4
4
|
|
5
|
-
|
6
|
-
@cacher = described_class.new
|
7
|
-
end
|
5
|
+
let(:logarithmic) { described_class.new }
|
8
6
|
|
9
|
-
describe '
|
10
|
-
it '
|
11
|
-
|
12
|
-
end
|
13
|
-
it 'should round to 2' do
|
14
|
-
@cacher.generate_from({ :key => [1,2,3,4] }).should == { :key => 1.39 }
|
7
|
+
describe 'saved?' do
|
8
|
+
it 'is correct' do
|
9
|
+
logarithmic.saved?.should == true
|
15
10
|
end
|
16
11
|
end
|
17
12
|
|
18
13
|
describe 'weight_for' do
|
19
|
-
it '
|
20
|
-
|
14
|
+
it 'is 0 for 0' do
|
15
|
+
logarithmic.weight_for(0).should == 0
|
21
16
|
end
|
22
|
-
it '
|
23
|
-
|
17
|
+
it 'is 0 for 1' do
|
18
|
+
logarithmic.weight_for(1).should == 0
|
24
19
|
end
|
25
|
-
it '
|
26
|
-
|
20
|
+
it 'is log(x) for x' do
|
21
|
+
logarithmic.weight_for(1234).should == Math.log(1234)
|
27
22
|
end
|
28
23
|
end
|
29
24
|
|
@@ -6,7 +6,7 @@ describe Picky::Bundle do
|
|
6
6
|
@index = Picky::Index.new :some_index
|
7
7
|
@category = Picky::Category.new :some_category, @index
|
8
8
|
|
9
|
-
@weights = stub :weights
|
9
|
+
@weights = stub :weights, :saved? => true
|
10
10
|
@partial = stub :partial
|
11
11
|
@similarity = stub :similarity
|
12
12
|
@bundle = described_class.new :some_name, @category, Picky::Backends::Memory.new, @weights, @partial, @similarity
|
@@ -158,7 +158,8 @@ describe Picky::Bundle do
|
|
158
158
|
@index = Picky::Index.new :some_index
|
159
159
|
@category = Picky::Category.new :some_category, @index
|
160
160
|
|
161
|
-
@
|
161
|
+
@weights = stub :weights, :saved? => true
|
162
|
+
@bundle = described_class.new :some_name, @category, Picky::Backends::Memory.new, @weights, :partial, :similarity
|
162
163
|
end
|
163
164
|
it 'should initialize the index correctly' do
|
164
165
|
@bundle.backend_inverted.should be_kind_of(Picky::Backends::Memory::JSON)
|
@@ -9,27 +9,27 @@ describe Picky::Wrappers::Bundle::Calculation do
|
|
9
9
|
|
10
10
|
describe 'ids' do
|
11
11
|
it 'calls bundle#ids correctly' do
|
12
|
-
@bundle.should_receive(:ids).once.with
|
12
|
+
@bundle.should_receive(:ids).once.with '0.0'
|
13
13
|
|
14
|
-
@calculation.ids
|
14
|
+
@calculation.ids 'some_str'
|
15
15
|
end
|
16
16
|
it 'calls bundle#ids correctly' do
|
17
|
-
@bundle.should_receive(:ids).once.with
|
17
|
+
@bundle.should_receive(:ids).once.with '6.28'
|
18
18
|
|
19
|
-
@calculation.ids
|
19
|
+
@calculation.ids '6.28'
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
describe 'weight' do
|
24
24
|
it 'calls bundle#ids correctly' do
|
25
|
-
@bundle.should_receive(:weight).once.with
|
25
|
+
@bundle.should_receive(:weight).once.with '0.0'
|
26
26
|
|
27
|
-
@calculation.weight
|
27
|
+
@calculation.weight 'some_str'
|
28
28
|
end
|
29
29
|
it 'calls bundle#ids correctly' do
|
30
|
-
@bundle.should_receive(:weight).once.with
|
30
|
+
@bundle.should_receive(:weight).once.with '6.28'
|
31
31
|
|
32
|
-
@calculation.weight
|
32
|
+
@calculation.weight '6.28'
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -5,9 +5,10 @@ describe Picky::Bundle do
|
|
5
5
|
before(:each) do
|
6
6
|
@index = Picky::Index.new :some_index
|
7
7
|
@category = Picky::Category.new :some_category, @index
|
8
|
+
@weights = Picky::Weights::Logarithmic.new
|
8
9
|
@similarity = Picky::Similarity::DoubleMetaphone.new 3
|
9
10
|
end
|
10
|
-
let(:bundle) { described_class.new :some_name, @category, Picky::Backends::Memory.new,
|
11
|
+
let(:bundle) { described_class.new :some_name, @category, Picky::Backends::Memory.new, @weights, :some_partial, @similarity }
|
11
12
|
|
12
13
|
describe 'identifier' do
|
13
14
|
it 'is correct' do
|
@@ -17,13 +18,14 @@ describe Picky::Bundle do
|
|
17
18
|
|
18
19
|
describe 'similar' do
|
19
20
|
before(:each) do
|
20
|
-
bundle.
|
21
|
+
bundle.add_similarity :dragon
|
22
|
+
bundle.add_similarity :dargon
|
21
23
|
end
|
22
24
|
it 'returns the right similars (not itself)' do
|
23
25
|
bundle.similar(:dragon).should == [:dargon]
|
24
26
|
end
|
25
27
|
it 'returns the right similars' do
|
26
|
-
bundle.similar(:trkn).should == [:
|
28
|
+
bundle.similar(:trkn).should == [:dargon, :dragon]
|
27
29
|
end
|
28
30
|
it 'performs' do
|
29
31
|
performance_of { bundle.similar(:dragon) }.should < 0.000075
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe "Weights" do
|
6
|
+
|
7
|
+
# This tests the weights option.
|
8
|
+
#
|
9
|
+
context 'various cases' do
|
10
|
+
it 'stopwords destroy ids (final: id reference on attribute)' do
|
11
|
+
index = Picky::Index.new :dynamic_weights do
|
12
|
+
source { [] }
|
13
|
+
category :text1, weights: Picky::Weights::Constant.new
|
14
|
+
category :text2, weights: Picky::Weights::Constant.new(3.14)
|
15
|
+
category :text3, weights: Picky::Weights::Dynamic.new { |str_or_sym| str_or_sym.size }
|
16
|
+
category :text4 # Default
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'ostruct'
|
20
|
+
|
21
|
+
thing = OpenStruct.new id: 1, text1: "ohai", text2: "hello", text3: "world", text4: "kthxbye"
|
22
|
+
other = OpenStruct.new id: 2, text1: "", text2: "", text3: "", text4: "kthxbye"
|
23
|
+
|
24
|
+
index.add thing
|
25
|
+
index.add other
|
26
|
+
|
27
|
+
try = Picky::Search.new index
|
28
|
+
|
29
|
+
try.search("text1:ohai").allocations.first.score.should == 0.0
|
30
|
+
try.search("text2:hello").allocations.first.score.should == 3.14
|
31
|
+
try.search("text3:world").allocations.first.score.should == 5
|
32
|
+
try.search("text4:kthxbye").allocations.first.score.should == 0.6931471805599453
|
33
|
+
|
34
|
+
try_with_boosts = Picky::Search.new index do
|
35
|
+
boost [:text1] => +7.65,
|
36
|
+
[:text2] => +1.86
|
37
|
+
end
|
38
|
+
|
39
|
+
try_with_boosts.search("text1:ohai").allocations.first.score.should == 7.65
|
40
|
+
try_with_boosts.search("text2:hello").allocations.first.score.should == 5.00
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|