picky 3.1.10 → 3.1.11
Sign up to get free protection for your applications and to get access to all the features.
@@ -16,9 +16,12 @@ module Picky
|
|
16
16
|
ids = @inverted[sym]
|
17
17
|
ids.delete id
|
18
18
|
|
19
|
+
encoded = self.similarity_strategy.encoded sym
|
20
|
+
|
19
21
|
if ids.empty?
|
20
|
-
@inverted.delete
|
21
|
-
@weights.delete
|
22
|
+
@inverted.delete sym
|
23
|
+
@weights.delete sym
|
24
|
+
@similarity.delete encoded # Since no element uses this sym anymore, we can delete the similarity for it.
|
22
25
|
else
|
23
26
|
@weights[sym] = self.weights_strategy.weight_for ids.size
|
24
27
|
end
|
@@ -35,6 +38,8 @@ module Picky
|
|
35
38
|
syms = @realtime_mapping[id]
|
36
39
|
syms = (@realtime_mapping[id] = []) unless syms # TODO Nicefy.
|
37
40
|
|
41
|
+
# Inverted.
|
42
|
+
#
|
38
43
|
ids = if syms.include? sym
|
39
44
|
ids = @inverted[sym]
|
40
45
|
ids.delete id # Move id
|
@@ -45,7 +50,21 @@ module Picky
|
|
45
50
|
inverted.unshift id
|
46
51
|
end
|
47
52
|
|
53
|
+
# Weights.
|
54
|
+
#
|
48
55
|
@weights[sym] = self.weights_strategy.weight_for ids.size
|
56
|
+
|
57
|
+
# Similarity.
|
58
|
+
#
|
59
|
+
if encoded = self.similarity_strategy.encoded(sym)
|
60
|
+
similarity = @similarity[encoded] ||= []
|
61
|
+
if similarity.include? sym
|
62
|
+
similarity.delete sym # Not completely correct, as others will also be affected, but meh.
|
63
|
+
similarity.unshift sym #
|
64
|
+
else
|
65
|
+
similarity.unshift sym
|
66
|
+
end
|
67
|
+
end
|
49
68
|
end
|
50
69
|
|
51
70
|
end
|
@@ -8,7 +8,7 @@ describe Picky::Indexed::Bundle do
|
|
8
8
|
|
9
9
|
@weights = Picky::Generators::Weights::Default
|
10
10
|
@partial = Picky::Generators::Partial::Default
|
11
|
-
@similarity =
|
11
|
+
@similarity = Picky::Generators::Similarity::DoubleMetaphone.new 3
|
12
12
|
@bundle = described_class.new :some_name, @category, Picky::Backends::Memory.new, @weights, @partial, @similarity
|
13
13
|
end
|
14
14
|
|
@@ -21,6 +21,9 @@ describe Picky::Indexed::Bundle do
|
|
21
21
|
it 'is by default empty' do
|
22
22
|
@bundle.inverted.should == {}
|
23
23
|
end
|
24
|
+
it 'is by default empty' do
|
25
|
+
@bundle.similarity.should == {}
|
26
|
+
end
|
24
27
|
|
25
28
|
describe 'combined' do
|
26
29
|
it 'works correctly' do
|
@@ -29,7 +32,8 @@ describe Picky::Indexed::Bundle do
|
|
29
32
|
|
30
33
|
@bundle.realtime_mapping.should == { 1 => [:title], 2 => [:title] }
|
31
34
|
@bundle.inverted.should == { :title => [2,1] }
|
32
|
-
@bundle.weights.should
|
35
|
+
@bundle.weights.should == { :title => 0.6931471805599453 }
|
36
|
+
@bundle.similarity.should == { :TTL => [:title] }
|
33
37
|
end
|
34
38
|
it 'works correctly' do
|
35
39
|
@bundle.add 1, :title
|
@@ -38,8 +42,9 @@ describe Picky::Indexed::Bundle do
|
|
38
42
|
@bundle.remove 2
|
39
43
|
|
40
44
|
@bundle.realtime_mapping.should == {}
|
41
|
-
@bundle.weights.should
|
45
|
+
@bundle.weights.should == {}
|
42
46
|
@bundle.inverted.should == {}
|
47
|
+
@bundle.similarity.should == {}
|
43
48
|
end
|
44
49
|
it 'works correctly' do
|
45
50
|
@bundle.add 1, :title
|
@@ -48,8 +53,9 @@ describe Picky::Indexed::Bundle do
|
|
48
53
|
@bundle.remove 1
|
49
54
|
|
50
55
|
@bundle.realtime_mapping.should == {}
|
51
|
-
@bundle.weights.should
|
56
|
+
@bundle.weights.should == {}
|
52
57
|
@bundle.inverted.should == {}
|
58
|
+
@bundle.similarity.should == {}
|
53
59
|
end
|
54
60
|
it 'works correctly' do
|
55
61
|
@bundle.add 1, :title
|
@@ -58,8 +64,9 @@ describe Picky::Indexed::Bundle do
|
|
58
64
|
@bundle.remove 1
|
59
65
|
|
60
66
|
@bundle.realtime_mapping.should == { 2 => [:thing] }
|
61
|
-
@bundle.weights.should
|
67
|
+
@bundle.weights.should == { :thing => 0.0 }
|
62
68
|
@bundle.inverted.should == { :thing => [2] }
|
69
|
+
@bundle.similarity.should == { :"0NK" => [:thing] }
|
63
70
|
end
|
64
71
|
it 'works correctly' do
|
65
72
|
@bundle.add 1, :title
|
@@ -68,6 +75,7 @@ describe Picky::Indexed::Bundle do
|
|
68
75
|
@bundle.realtime_mapping.should == { 1 => [:title] }
|
69
76
|
@bundle.weights.should == { :title => 0.0 }
|
70
77
|
@bundle.inverted.should == { :title => [1] }
|
78
|
+
@bundle.similarity.should == { :TTL => [:title] }
|
71
79
|
end
|
72
80
|
it 'works correctly' do
|
73
81
|
@bundle.add 1, :title
|
@@ -77,6 +85,7 @@ describe Picky::Indexed::Bundle do
|
|
77
85
|
@bundle.realtime_mapping.should == {}
|
78
86
|
@bundle.weights.should == {}
|
79
87
|
@bundle.inverted.should == {}
|
88
|
+
@bundle.similarity.should == {}
|
80
89
|
end
|
81
90
|
end
|
82
91
|
|
@@ -97,8 +106,9 @@ describe Picky::Indexed::Bundle do
|
|
97
106
|
it 'works correctly' do
|
98
107
|
@bundle.add 1, :title
|
99
108
|
|
100
|
-
@bundle.weights.should
|
109
|
+
@bundle.weights.should == { :title => 0.0 }
|
101
110
|
@bundle.inverted.should == { :title => [1] }
|
111
|
+
@bundle.similarity.should == { :TTL => [:title] }
|
102
112
|
end
|
103
113
|
end
|
104
114
|
|
@@ -11,7 +11,13 @@ describe "Realtime Indexing" do
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
let(:index)
|
14
|
+
let(:index) do
|
15
|
+
Picky::Index.new(:test) do
|
16
|
+
source []
|
17
|
+
category :title
|
18
|
+
category :author, similarity: Picky::Generators::Similarity::DoubleMetaphone.new(3)
|
19
|
+
end
|
20
|
+
end
|
15
21
|
let(:books) { Picky::Search.new index }
|
16
22
|
|
17
23
|
before(:each) do
|
@@ -120,11 +126,74 @@ describe "Realtime Indexing" do
|
|
120
126
|
it 'handles more complex cases' do
|
121
127
|
index.remove 1
|
122
128
|
|
123
|
-
books.search('
|
129
|
+
books.search('Titl').ids.should == []
|
124
130
|
|
125
131
|
index.replace Book.new(1, "Title New", "Author New")
|
126
132
|
|
127
|
-
books.search('title:
|
133
|
+
books.search('title:Ne').ids.should == [1]
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
context 'similarity' do
|
138
|
+
it 'finds the first entry' do
|
139
|
+
books.search('Authr~').ids.should == [1]
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'allows removing something' do
|
143
|
+
index.remove 1
|
144
|
+
end
|
145
|
+
it 'is not findable anymore after removing' do
|
146
|
+
books.search('Authr~').ids.should == [1]
|
147
|
+
|
148
|
+
index.remove 1
|
149
|
+
|
150
|
+
books.search('Authr~').ids.should == []
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'allows adding something' do
|
154
|
+
index.add Book.new(2, "Title2", "Author2")
|
155
|
+
end
|
156
|
+
it 'is findable after adding' do
|
157
|
+
books.search('Authr~').ids.should == [1]
|
158
|
+
|
159
|
+
index.add Book.new(2, "Title New", "Author New")
|
160
|
+
|
161
|
+
books.search('Authr~').ids.should == [2,1]
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'allows replacing something' do
|
165
|
+
index.replace Book.new(1, "Title New", "Author New")
|
166
|
+
end
|
167
|
+
it 'is findable after replacing' do
|
168
|
+
books.search('Nuw~').ids.should == []
|
169
|
+
|
170
|
+
index.replace Book.new(1, "Title New", "Author New")
|
171
|
+
|
172
|
+
books.search('Nuw~').ids.should == [1, 1] # TODO FIXME Not really what I'd expect.
|
173
|
+
end
|
174
|
+
it 'handles more complex cases' do
|
175
|
+
books.search('Now~').ids.should == []
|
176
|
+
|
177
|
+
index.replace Book.new(1, "Title New", "Author New")
|
178
|
+
|
179
|
+
books.search('author:Now~').ids.should == [1]
|
180
|
+
end
|
181
|
+
it 'handles more complex cases' do
|
182
|
+
index.remove 1
|
183
|
+
|
184
|
+
books.search('Athr~').ids.should == []
|
185
|
+
|
186
|
+
index.replace Book.new(1, "Title New", "Author New")
|
187
|
+
|
188
|
+
books.search('author:Athr~').ids.should == [1]
|
189
|
+
end
|
190
|
+
it 'handles more complex cases' do
|
191
|
+
books.search('Athr~').ids.should == [1]
|
192
|
+
|
193
|
+
index.replace Book.new(2, "Title New", "Author New")
|
194
|
+
index.add Book.new(3, "TTL", "AUTHR")
|
195
|
+
|
196
|
+
books.search('author:Athr~').ids.should == [2, 1, 3] # TODO Is that what I'd expect?
|
128
197
|
end
|
129
198
|
end
|
130
199
|
|
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.1.
|
4
|
+
version: 3.1.11
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ default_executable: picky
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
17
|
-
requirement: &
|
17
|
+
requirement: &70264818405600 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,18 +22,18 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70264818405600
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: picky-client
|
28
|
-
requirement: &
|
28
|
+
requirement: &70264818404920 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - =
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 3.1.
|
33
|
+
version: 3.1.11
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70264818404920
|
37
37
|
description: Fast Ruby semantic text search engine with comfortable single field interface.
|
38
38
|
email: florian.hanke+picky@gmail.com
|
39
39
|
executables:
|