algoliasearch-rails 1.4.5 → 1.5.1
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.
- checksums.yaml +4 -4
- data/ChangeLog +4 -0
- data/README.md +12 -1
- data/VERSION +1 -1
- data/algoliasearch-rails.gemspec +2 -2
- data/lib/algoliasearch-rails.rb +20 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f261644d4f85253064f4683e6815c3fc4ef8a36
|
4
|
+
data.tar.gz: 47b1f0cfccd530d7fd5987fa82019abc4363e4da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f596456245ab08f64f23f7fb908d839489fb1bedfcf2b36752a67d7c561f52ab974e87a40c3a57614334b0ae56345d8e24779b54f3b561e639f7f741d767ed5f
|
7
|
+
data.tar.gz: 77cd27fb4231f8e6c4fc7076993557d23f17f89edec86aa299c03fe2807c37fce722b4aac9317446079cfa597a535e6dc1d081bdfa984125172eff8c997f888b
|
data/ChangeLog
CHANGED
data/README.md
CHANGED
@@ -89,7 +89,7 @@ p Contact.search("jon doe")
|
|
89
89
|
Options
|
90
90
|
----------
|
91
91
|
|
92
|
-
Each time a record is saved; it will be - asynchronously - indexed.
|
92
|
+
Each time a record is saved; it will be - asynchronously - indexed. On the other hand, each time a record is destroyed, it will be - asynchronously - removed from the index.
|
93
93
|
|
94
94
|
You can disable auto-indexing and auto-removing setting the following options:
|
95
95
|
|
@@ -164,6 +164,17 @@ class Contact < ActiveRecord::Base
|
|
164
164
|
end
|
165
165
|
```
|
166
166
|
|
167
|
+
By default, the `objectID` is based on your record's `id`. You can change this behavior specifying the `:id` option (be sure to use a uniq field).
|
168
|
+
|
169
|
+
```ruby
|
170
|
+
class UniqUser < ActiveRecord::Base
|
171
|
+
include AlgoliaSearch
|
172
|
+
|
173
|
+
algoliasearch id: :uniq_name do
|
174
|
+
end
|
175
|
+
end
|
176
|
+
```
|
177
|
+
|
167
178
|
Indexing
|
168
179
|
---------
|
169
180
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.5.1
|
data/algoliasearch-rails.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "algoliasearch-rails"
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.5.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Algolia"]
|
12
|
-
s.date = "2013-
|
12
|
+
s.date = "2013-12-03"
|
13
13
|
s.description = "AlgoliaSearch integration to your favorite ORM"
|
14
14
|
s.email = "contact@algolia.com"
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/algoliasearch-rails.rb
CHANGED
@@ -124,7 +124,7 @@ module AlgoliaSearch
|
|
124
124
|
ensure_init
|
125
125
|
last_task = nil
|
126
126
|
find_in_batches(batch_size: batch_size) do |group|
|
127
|
-
objects = group.map { |o| @index_settings.get_attributes(o).merge 'objectID' => o
|
127
|
+
objects = group.map { |o| @index_settings.get_attributes(o).merge 'objectID' => object_id_of(o) }
|
128
128
|
last_task = @index.save_objects(objects)
|
129
129
|
end
|
130
130
|
@index.wait_task(last_task["taskID"]) if last_task and synchronous == true
|
@@ -134,9 +134,9 @@ module AlgoliaSearch
|
|
134
134
|
return if @without_auto_index_scope
|
135
135
|
ensure_init
|
136
136
|
if synchronous
|
137
|
-
@index.add_object!(@index_settings.get_attributes(object), object
|
137
|
+
@index.add_object!(@index_settings.get_attributes(object), object_id_of(object))
|
138
138
|
else
|
139
|
-
@index.add_object(@index_settings.get_attributes(object), object
|
139
|
+
@index.add_object(@index_settings.get_attributes(object), object_id_of(object))
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
@@ -144,9 +144,9 @@ module AlgoliaSearch
|
|
144
144
|
return if @without_auto_index_scope
|
145
145
|
ensure_init
|
146
146
|
if synchronous
|
147
|
-
@index.delete_object!(object
|
147
|
+
@index.delete_object!(object_id_of(object))
|
148
148
|
else
|
149
|
-
@index.delete_object(object
|
149
|
+
@index.delete_object(object_id_of(object))
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
@@ -160,7 +160,7 @@ module AlgoliaSearch
|
|
160
160
|
ensure_init
|
161
161
|
json = @index.search(q, Hash[settings.map { |k,v| [k.to_s, v.to_s] }])
|
162
162
|
results = json['hits'].map do |hit|
|
163
|
-
o = full_const_get(@options[:type].to_s).
|
163
|
+
o = full_const_get(@options[:type].to_s).where(object_id_method => hit['objectID']).first
|
164
164
|
o.highlight_result = hit['_highlightResult']
|
165
165
|
o
|
166
166
|
end
|
@@ -175,7 +175,7 @@ module AlgoliaSearch
|
|
175
175
|
end
|
176
176
|
|
177
177
|
def must_reindex?(object)
|
178
|
-
return true if object
|
178
|
+
return true if object_id_changed?(object)
|
179
179
|
@index_settings.get_attributes(object).each do |k, v|
|
180
180
|
changed_method = "#{k}_changed?"
|
181
181
|
return true if object.respond_to?(changed_method) && object.send(changed_method)
|
@@ -191,6 +191,19 @@ module AlgoliaSearch
|
|
191
191
|
|
192
192
|
private
|
193
193
|
|
194
|
+
def object_id_method
|
195
|
+
@options[:id] || @options[:object_id] || :id
|
196
|
+
end
|
197
|
+
|
198
|
+
def object_id_of(o)
|
199
|
+
o.send(object_id_method).to_s
|
200
|
+
end
|
201
|
+
|
202
|
+
def object_id_changed?(o)
|
203
|
+
m = "#{object_id_method}_changed?"
|
204
|
+
o.respond_to?(m) ? o.send(m) : false
|
205
|
+
end
|
206
|
+
|
194
207
|
def index_settings_changed?(prev, current)
|
195
208
|
return true if prev.nil?
|
196
209
|
current.each do |k, v|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: algoliasearch-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Algolia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|