algoliasearch-rails 1.3.10 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +4 -0
- data/README.md +15 -0
- data/VERSION +1 -1
- data/algoliasearch-rails.gemspec +2 -2
- data/lib/algoliasearch-rails.rb +26 -27
- 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: c7c04861a87809fcc0e5b1f6a3195b38e62e5634
|
4
|
+
data.tar.gz: 1f354ed3067a4c438deef7d1355eaeb98c75edd1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4329b3f1440d9dbb810da2225dbf04de248cbb771cdddfd508a44bf038b643ee6ca76fafd3a3282086dda476073dca63478522ed9141478579aaae6154f70618
|
7
|
+
data.tar.gz: 56b9c819f5e5d7b7cd79c664adecc2f8b770b19c45113682a0193d666090712c755e3ee60350f22841ec8c38da331e3b05af102fe5835ba923d3471d28ac8785
|
data/ChangeLog
CHANGED
data/README.md
CHANGED
@@ -149,6 +149,21 @@ class Contact < ActiveRecord::Base
|
|
149
149
|
end
|
150
150
|
```
|
151
151
|
|
152
|
+
You can use a block to specify a complex attribute value
|
153
|
+
|
154
|
+
```ruby
|
155
|
+
class Contact < ActiveRecord::Base
|
156
|
+
include AlgoliaSearch
|
157
|
+
|
158
|
+
algoliasearch do
|
159
|
+
attribute :email
|
160
|
+
attribute :full_name do
|
161
|
+
"#{first_name} #{last_name}"
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
```
|
166
|
+
|
152
167
|
Indexing
|
153
168
|
---------
|
154
169
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.4.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.4.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-11-
|
12
|
+
s.date = "2013-11-25"
|
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
@@ -42,7 +42,7 @@ module AlgoliaSearch
|
|
42
42
|
|
43
43
|
end
|
44
44
|
|
45
|
-
class
|
45
|
+
class IndexSettings
|
46
46
|
|
47
47
|
# AlgoliaSearch settings
|
48
48
|
OPTIONS = [:attributesToIndex, :minWordSizefor1Typo,
|
@@ -56,26 +56,31 @@ module AlgoliaSearch
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
# attributes to consider
|
60
|
-
attr_accessor :attributes
|
61
|
-
|
62
59
|
def initialize(block)
|
63
60
|
instance_exec(&block) if block
|
64
61
|
end
|
65
62
|
|
66
|
-
def attribute(*names)
|
67
|
-
|
68
|
-
|
63
|
+
def attribute(*names, &block)
|
64
|
+
raise ArgumentError.new('Cannot pass multiple attribute names if block given') if block_given? and names.length > 1
|
65
|
+
@attributes ||= {}
|
66
|
+
names.each do |name|
|
67
|
+
@attributes[name] = block_given? ? Proc.new { |o| o.instance_eval(&block) } : Proc.new { |o| o.send(name) }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def get_attributes(object)
|
72
|
+
return object.attributes if @attributes.nil? or @attributes.length == 0
|
73
|
+
Hash[@attributes.map { |name, value| [name.to_s, value.call(object) ] }]
|
69
74
|
end
|
70
75
|
|
71
|
-
def
|
72
|
-
instance_variable_get("@#{
|
76
|
+
def get_setting(name)
|
77
|
+
instance_variable_get("@#{name}")
|
73
78
|
end
|
74
79
|
|
75
80
|
def to_settings
|
76
81
|
settings = {}
|
77
82
|
OPTIONS.each do |k|
|
78
|
-
v =
|
83
|
+
v = get_setting(k)
|
79
84
|
settings[k] = v if !v.nil?
|
80
85
|
end
|
81
86
|
settings
|
@@ -86,7 +91,10 @@ module AlgoliaSearch
|
|
86
91
|
module ClassMethods
|
87
92
|
|
88
93
|
def algoliasearch(options = {}, &block)
|
89
|
-
@
|
94
|
+
@index_settings = IndexSettings.new(block_given? ? Proc.new : nil)
|
95
|
+
@settings = @index_settings.to_settings
|
96
|
+
@options = { type: model_name, per_page: @index_settings.get_setting(:hitsPerPage) || 10, page: 1 }.merge(options)
|
97
|
+
|
90
98
|
attr_accessor :highlight_result
|
91
99
|
|
92
100
|
if options[:synchronous] == true
|
@@ -100,8 +108,6 @@ module AlgoliaSearch
|
|
100
108
|
unless options[:auto_remove] == false
|
101
109
|
after_destroy { |searchable| searchable.remove_from_index! } if respond_to?(:after_destroy)
|
102
110
|
end
|
103
|
-
|
104
|
-
@options = { type: model_name, per_page: @index_options.get(:hitsPerPage) || 10, page: 1 }.merge(options)
|
105
111
|
end
|
106
112
|
|
107
113
|
def without_auto_index(&block)
|
@@ -118,7 +124,7 @@ module AlgoliaSearch
|
|
118
124
|
ensure_init
|
119
125
|
last_task = nil
|
120
126
|
find_in_batches(batch_size: batch_size) do |group|
|
121
|
-
objects = group.map { |o|
|
127
|
+
objects = group.map { |o| @index_settings.get_attributes(o).merge 'objectID' => o.id.to_s }
|
122
128
|
last_task = @index.save_objects(objects)
|
123
129
|
end
|
124
130
|
@index.wait_task(last_task["taskID"]) if last_task and synchronous == true
|
@@ -128,9 +134,9 @@ module AlgoliaSearch
|
|
128
134
|
return if @without_auto_index_scope
|
129
135
|
ensure_init
|
130
136
|
if synchronous
|
131
|
-
@index.add_object!(
|
137
|
+
@index.add_object!(@index_settings.get_attributes(object), object.id.to_s)
|
132
138
|
else
|
133
|
-
@index.add_object(
|
139
|
+
@index.add_object(@index_settings.get_attributes(object), object.id.to_s)
|
134
140
|
end
|
135
141
|
end
|
136
142
|
|
@@ -162,17 +168,15 @@ module AlgoliaSearch
|
|
162
168
|
end
|
163
169
|
|
164
170
|
def ensure_init
|
165
|
-
|
166
|
-
return if @index and !index_settings_changed?(@settings, new_settings)
|
171
|
+
return if @index
|
167
172
|
@index = Algolia::Index.new(index_name)
|
168
173
|
current_settings = @index.get_settings rescue nil # if the index doesn't exist
|
169
|
-
@index.set_settings(
|
170
|
-
@settings = new_settings
|
174
|
+
@index.set_settings(@settings) if index_settings_changed?(current_settings, @settings)
|
171
175
|
end
|
172
176
|
|
173
177
|
def must_reindex?(object)
|
174
178
|
return true if object.id_changed?
|
175
|
-
|
179
|
+
@index_settings.get_attributes(object).each do |k, v|
|
176
180
|
changed_method = "#{k}_changed?"
|
177
181
|
return true if object.respond_to?(changed_method) && object.send(changed_method)
|
178
182
|
end
|
@@ -187,11 +191,6 @@ module AlgoliaSearch
|
|
187
191
|
|
188
192
|
private
|
189
193
|
|
190
|
-
def attributes(object)
|
191
|
-
return object.attributes if @index_options.attributes.nil? or @index_options.attributes.length == 0
|
192
|
-
Hash[@index_options.attributes.map { |attr| [attr.to_s, object.send(attr)] }]
|
193
|
-
end
|
194
|
-
|
195
194
|
def index_settings_changed?(prev, current)
|
196
195
|
return true if prev.nil?
|
197
196
|
current.each do |k, v|
|
@@ -233,7 +232,7 @@ module AlgoliaSearch
|
|
233
232
|
end
|
234
233
|
|
235
234
|
def mark_must_reindex
|
236
|
-
@must_reindex = self.class.must_reindex?(self)
|
235
|
+
@must_reindex = new_record? || self.class.must_reindex?(self)
|
237
236
|
true
|
238
237
|
end
|
239
238
|
|
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.4.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-
|
11
|
+
date: 2013-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|