picky 4.31.1 → 4.31.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2b3c54b9a8b3db32d2cfb2ddbc7acd92889ae4bf
4
- data.tar.gz: dc1355c15b92450a9b4d5ac2d05cdd1754938e94
3
+ metadata.gz: 54dcfc7c9200c82d700cbc217d92b95dfdeb7560
4
+ data.tar.gz: e6bb65cb70e0e35b682461354fc7141196d8250a
5
5
  SHA512:
6
- metadata.gz: 5c8267d3a6d40cb9170d9f068d296dca257c83651db5848c2e8d43c1e8547bb07a57a5a58bf20b8e9d3c3e1e0c5b64564daefa5a0e7cc434df0b2a7fbded6154
7
- data.tar.gz: 4a5e283823b8558e5e030cb583b491f5be88669ca6e6b70904a78a5d92e1aeae10183b96e27deea2c816af677bd4038a8fa7251982c684ea0606fe1b9d55d68d
6
+ metadata.gz: 0785f11056dc78dbfd52414ab3ff14be8ec1bb429ddcbdb90b6a5d77d9c5250308b64e52ba91e5313a7991b84cb50b9f5f94ccfc8fda05c3716479e3f36a9f4e
7
+ data.tar.gz: a7a92264369467374a3d7490b7d5f32170d07a923a40e5fe5466888dc0086b339066d153503cd846ab01a535ddf48ef0c300f3e6185573eaef903728fc5e8af1
@@ -7,7 +7,9 @@ module Picky
7
7
  # Adds and indexes this category of the
8
8
  # given object.
9
9
  #
10
- # TODO Don't do this super-dynamically?
10
+ # @param object [Object] The thing to index.
11
+ # @param method [Symbol] The method name to use on the id array.
12
+ # @param force_update [Boolean] Whether to force update.
11
13
  #
12
14
  def add object, method: :unshift, force_update: false
13
15
  data = if from.respond_to? :call
@@ -21,22 +23,40 @@ module Picky
21
23
  # Removes an indexed object with the
22
24
  # given id.
23
25
  #
26
+ # @param id [Object] The id of the object.
27
+ #
24
28
  def remove id
25
29
  id = id.send key_format if key_format?
26
30
  exact.remove id
27
31
  partial.remove id
28
32
  end
29
33
 
30
- # Removes the object's id, and then
31
- # adds it again.
34
+ # Replaces an object. Will first check if each category of the object is in
35
+ # the index it would insert, and if it is, will not insert.
36
+ # Otherwise will delete and add.
32
37
  #
33
- # TODO Is this the actual forced update?
38
+ # @param object [Object] The object to replace.
39
+ # @param method [Symbol] The method name to use on the id array.
34
40
  #
35
41
  def replace object, method: :unshift
36
42
  remove object.send id
37
43
  add object, method: method
38
44
  end
39
45
 
46
+ # Always removes the object's id, and then
47
+ # adds the object again.
48
+ #
49
+ # Note: This puts a bit of a strain on Ruby's
50
+ # memory management.
51
+ #
52
+ # @param object [Object] The object to replace.
53
+ # @param method [Symbol] The method name to use on the id array.
54
+ #
55
+ def replace! object, method: :unshift
56
+ remove object.send id
57
+ add object, method: method
58
+ end
59
+
40
60
  # Replaces just part of the indexed data.
41
61
  #
42
62
  # Note: Takes a hash as opposed to the add/replace method.
@@ -18,7 +18,7 @@ module Picky
18
18
  def dump; end
19
19
  def empty; end
20
20
  def index; end
21
- def load; end
21
+ def load(*); end
22
22
 
23
23
  def to_tree_s indent = 0
24
24
  bundle.to_tree_s(indent) { "(reference)" }
@@ -107,6 +107,15 @@ describe "Realtime Indexing" do
107
107
 
108
108
  books.search('Titl').ids.should == [2,1]
109
109
  end
110
+ it 'will not have duplicate result from adding something twice' do
111
+ books.search('Titl').ids.should == [1]
112
+
113
+ index.add Book.new(2, "Title New", "Author New")
114
+ index.add Book.new(2, "New Title", "New Author")
115
+ index.add Book.new(2, "Title New", "Author New")
116
+
117
+ books.search('Titl').ids.should == [2,1]
118
+ end
110
119
 
111
120
  it 'allows replacing something' do
112
121
  index.replace Book.new(1, "Title New", "Author New")
@@ -134,6 +143,17 @@ describe "Realtime Indexing" do
134
143
 
135
144
  books.search('title:Ne').ids.should == [1]
136
145
  end
146
+ it 'does not unnecessarily change the position if a category already contains it' do
147
+ books.search('title:Title').ids.should == [1]
148
+
149
+ index.add Book.new(2, "Title New", "Author New")
150
+
151
+ books.search('title:Title').ids.should == [2,1]
152
+
153
+ index.replace Book.new(1, "Title", "Author")
154
+
155
+ books.search('title:Title').ids.should == [2,1]
156
+ end
137
157
  end
138
158
 
139
159
  context 'non-partial' do
@@ -258,11 +278,11 @@ describe "Realtime Indexing" do
258
278
  end
259
279
  end
260
280
 
261
- context 'special index' do
281
+ context 'index with key_format :to_sym' do
262
282
  let(:index) do
263
283
  Picky::Index.new(:books) do
264
284
  key_format :to_sym
265
- source []
285
+
266
286
  category :title
267
287
  category :author, similarity: Picky::Generators::Similarity::DoubleMetaphone.new(3)
268
288
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: picky
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.31.1
4
+ version: 4.31.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Hanke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-30 00:00:00.000000000 Z
11
+ date: 2015-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -397,7 +397,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
397
397
  version: '0'
398
398
  requirements: []
399
399
  rubyforge_project: http://rubyforge.org/projects/picky
400
- rubygems_version: 2.4.5
400
+ rubygems_version: 2.4.6
401
401
  signing_key:
402
402
  specification_version: 4
403
403
  summary: 'Picky: Semantic Search Engine. Clever Interface. Good Tools.'