algoliasearch-rails 1.9.2 → 1.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -2
- data/ChangeLog +5 -0
- data/Gemfile +7 -7
- data/Gemfile.lock +68 -70
- data/VERSION +1 -1
- data/algoliasearch-rails.gemspec +2 -2
- data/lib/algoliasearch-rails.rb +6 -6
- data/lib/algoliasearch/configuration.rb +1 -1
- data/lib/algoliasearch/pagination/kaminari.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/utilities_spec.rb +1 -1
- data/vendor/assets/javascripts/algolia/algoliasearch.js +18 -15
- data/vendor/assets/javascripts/algolia/algoliasearch.min.js +2 -2
- 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: 4c717e0d5fe37fae7e75570ceba23c498cecaa4f
|
4
|
+
data.tar.gz: c16f748ce4eda2d00cdd79ca26615993c4b8a421
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50b34c87258d9849cedf846bc335b17f1e18bff4227ba539c6eed9db86e1c7eb6194694287107e0930df2a61e3a6cf8a26fe8437ce16da4de5c1ae3eee76ec4d
|
7
|
+
data.tar.gz: 3046f5be4d6c3f169e2904274ef22a5ae0559b662ab06b59c5d8e7985d0feac59995a709e1c1a512a2a4120bbc3042e86e408ba80d9886affdde2ad1a8abf86c
|
data/.travis.yml
CHANGED
data/ChangeLog
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
|
3
|
+
2014-03-26 1.9.3
|
4
|
+
|
5
|
+
* Ruby 1.8 compatibility
|
6
|
+
* Fixed a bug ignoring hitsPerPage parameter while using backend pagination (will_paginate/kaminari)
|
7
|
+
|
3
8
|
2014-03-17 1.9.2
|
4
9
|
|
5
10
|
* Raise an exception while attempting to index a non-saved object (blank objectID)
|
data/Gemfile
CHANGED
@@ -2,15 +2,15 @@ source "http://rubygems.org"
|
|
2
2
|
|
3
3
|
gem 'json', '>= 1.5.1'
|
4
4
|
gem 'algoliasearch', '~> 1.2'
|
5
|
-
gem 'rubysl', '~> 2.0', platform
|
5
|
+
gem 'rubysl', '~> 2.0', :platform => :rbx
|
6
6
|
|
7
7
|
group :test do
|
8
8
|
gem 'rspec', '>= 2.5.0'
|
9
|
-
gem 'rails', '>= 3.0.
|
10
|
-
gem 'sqlite3', platform
|
11
|
-
gem 'jdbc-sqlite3', platform
|
12
|
-
gem 'activerecord-jdbc-adapter', platform
|
13
|
-
gem 'activerecord-jdbcsqlite3-adapter', platform
|
9
|
+
gem 'rails', '>= 3.2.0', '< 4.0'
|
10
|
+
gem 'sqlite3', :platform => [:rbx, :ruby]
|
11
|
+
gem 'jdbc-sqlite3', :platform => :jruby
|
12
|
+
gem 'activerecord-jdbc-adapter', :platform => :jruby
|
13
|
+
gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby
|
14
14
|
gem 'autotest'
|
15
15
|
gem 'autotest-fsevent'
|
16
16
|
gem 'redgreen'
|
@@ -19,7 +19,7 @@ end
|
|
19
19
|
|
20
20
|
group :development do
|
21
21
|
gem 'travis'
|
22
|
-
gem 'rake'
|
22
|
+
gem 'rake', '~> 10.1.0'
|
23
23
|
gem 'rdoc'
|
24
24
|
end
|
25
25
|
|
data/Gemfile.lock
CHANGED
@@ -2,55 +2,55 @@ GEM
|
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
4
|
ZenTest (4.9.5)
|
5
|
-
actionmailer (
|
6
|
-
actionpack (=
|
5
|
+
actionmailer (3.2.17)
|
6
|
+
actionpack (= 3.2.17)
|
7
7
|
mail (~> 2.5.4)
|
8
|
-
actionpack (
|
9
|
-
|
10
|
-
|
8
|
+
actionpack (3.2.17)
|
9
|
+
activemodel (= 3.2.17)
|
10
|
+
activesupport (= 3.2.17)
|
11
|
+
builder (~> 3.0.0)
|
11
12
|
erubis (~> 2.7.0)
|
12
|
-
|
13
|
-
rack
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
13
|
+
journey (~> 1.0.4)
|
14
|
+
rack (~> 1.4.5)
|
15
|
+
rack-cache (~> 1.2)
|
16
|
+
rack-test (~> 0.6.1)
|
17
|
+
sprockets (~> 2.2.1)
|
18
|
+
activemodel (3.2.17)
|
19
|
+
activesupport (= 3.2.17)
|
20
|
+
builder (~> 3.0.0)
|
21
|
+
activerecord (3.2.17)
|
22
|
+
activemodel (= 3.2.17)
|
23
|
+
activesupport (= 3.2.17)
|
24
|
+
arel (~> 3.0.2)
|
25
|
+
tzinfo (~> 0.3.29)
|
23
26
|
activerecord-jdbc-adapter (1.3.6)
|
24
27
|
activerecord (>= 2.2)
|
25
28
|
activerecord-jdbcsqlite3-adapter (1.3.6)
|
26
29
|
activerecord-jdbc-adapter (~> 1.3.6)
|
27
30
|
jdbc-sqlite3 (~> 3.7.2)
|
28
|
-
|
31
|
+
activeresource (3.2.17)
|
32
|
+
activemodel (= 3.2.17)
|
33
|
+
activesupport (= 3.2.17)
|
34
|
+
activesupport (3.2.17)
|
29
35
|
i18n (~> 0.6, >= 0.6.4)
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
tzinfo (~> 0.3.37)
|
34
|
-
addressable (2.3.5)
|
35
|
-
algoliasearch (1.2.5)
|
36
|
+
multi_json (~> 1.0)
|
37
|
+
addressable (2.3.6)
|
38
|
+
algoliasearch (1.2.7)
|
36
39
|
httpclient (~> 2.3)
|
37
40
|
json (>= 1.5.1)
|
38
|
-
arel (
|
39
|
-
atomic (1.1.15)
|
40
|
-
atomic (1.1.15-java)
|
41
|
+
arel (3.0.3)
|
41
42
|
autotest (4.4.6)
|
42
43
|
ZenTest (>= 4.4.1)
|
43
44
|
autotest-fsevent (0.2.9)
|
44
45
|
sys-uname
|
45
46
|
autotest-growl (0.2.16)
|
46
|
-
backports (3.
|
47
|
-
builder (3.
|
47
|
+
backports (3.6.0)
|
48
|
+
builder (3.0.4)
|
48
49
|
coderay (1.1.0)
|
49
50
|
diff-lcs (1.2.5)
|
50
51
|
erubis (2.7.0)
|
51
|
-
ethon (0.
|
52
|
+
ethon (0.7.0)
|
52
53
|
ffi (>= 1.3.0)
|
53
|
-
mime-types (~> 1.18)
|
54
54
|
faraday (0.8.9)
|
55
55
|
multipart-post (~> 1.2.0)
|
56
56
|
faraday_middleware (0.9.0)
|
@@ -65,11 +65,12 @@ GEM
|
|
65
65
|
multi_json (~> 1.0)
|
66
66
|
net-http-persistent (>= 2.7)
|
67
67
|
net-http-pipeline
|
68
|
-
highline (1.6.
|
68
|
+
highline (1.6.21)
|
69
69
|
hike (1.2.3)
|
70
70
|
httpclient (2.3.4.1)
|
71
71
|
i18n (0.6.9)
|
72
72
|
jdbc-sqlite3 (3.7.2.1)
|
73
|
+
journey (1.0.4)
|
73
74
|
json (1.8.1)
|
74
75
|
json (1.8.1-java)
|
75
76
|
kaminari (0.15.1)
|
@@ -85,10 +86,9 @@ GEM
|
|
85
86
|
treetop (~> 1.4.8)
|
86
87
|
method_source (0.8.2)
|
87
88
|
mime-types (1.25.1)
|
88
|
-
|
89
|
-
multi_json (1.9.0)
|
89
|
+
multi_json (1.9.2)
|
90
90
|
multipart-post (1.2.0)
|
91
|
-
net-http-persistent (2.9.
|
91
|
+
net-http-persistent (2.9.4)
|
92
92
|
net-http-pipeline (1.0.1)
|
93
93
|
polyglot (0.3.4)
|
94
94
|
pry (0.9.12.6)
|
@@ -102,34 +102,40 @@ GEM
|
|
102
102
|
spoon (~> 0.0)
|
103
103
|
pusher-client (0.4.0)
|
104
104
|
websocket (~> 1.0.0)
|
105
|
-
rack (1.5
|
105
|
+
rack (1.4.5)
|
106
|
+
rack-cache (1.2)
|
107
|
+
rack (>= 0.4)
|
108
|
+
rack-ssl (1.3.4)
|
109
|
+
rack
|
106
110
|
rack-test (0.6.2)
|
107
111
|
rack (>= 1.0)
|
108
|
-
rails (
|
109
|
-
actionmailer (=
|
110
|
-
actionpack (=
|
111
|
-
activerecord (=
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
railties (
|
117
|
-
actionpack (=
|
118
|
-
activesupport (=
|
112
|
+
rails (3.2.17)
|
113
|
+
actionmailer (= 3.2.17)
|
114
|
+
actionpack (= 3.2.17)
|
115
|
+
activerecord (= 3.2.17)
|
116
|
+
activeresource (= 3.2.17)
|
117
|
+
activesupport (= 3.2.17)
|
118
|
+
bundler (~> 1.0)
|
119
|
+
railties (= 3.2.17)
|
120
|
+
railties (3.2.17)
|
121
|
+
actionpack (= 3.2.17)
|
122
|
+
activesupport (= 3.2.17)
|
123
|
+
rack-ssl (~> 1.3.2)
|
119
124
|
rake (>= 0.8.7)
|
120
|
-
|
125
|
+
rdoc (~> 3.4)
|
126
|
+
thor (>= 0.14.6, < 2.0)
|
121
127
|
rake (10.1.1)
|
122
|
-
rdoc (
|
128
|
+
rdoc (3.12.2)
|
123
129
|
json (~> 1.4)
|
124
130
|
redgreen (1.2.2)
|
125
131
|
rspec (2.14.1)
|
126
132
|
rspec-core (~> 2.14.0)
|
127
133
|
rspec-expectations (~> 2.14.0)
|
128
134
|
rspec-mocks (~> 2.14.0)
|
129
|
-
rspec-core (2.14.
|
135
|
+
rspec-core (2.14.8)
|
130
136
|
rspec-expectations (2.14.5)
|
131
137
|
diff-lcs (>= 1.1.3, < 2.0)
|
132
|
-
rspec-mocks (2.14.
|
138
|
+
rspec-mocks (2.14.6)
|
133
139
|
rubysl (2.0.15)
|
134
140
|
rubysl-abbrev (~> 2.0)
|
135
141
|
rubysl-base64 (~> 2.0)
|
@@ -293,7 +299,7 @@ GEM
|
|
293
299
|
rubysl-shellwords (~> 2.0)
|
294
300
|
rubysl-ostruct (2.0.4)
|
295
301
|
rubysl-pathname (2.0.0)
|
296
|
-
rubysl-prettyprint (2.0.
|
302
|
+
rubysl-prettyprint (2.0.3)
|
297
303
|
rubysl-prime (2.0.1)
|
298
304
|
rubysl-profile (2.0.0)
|
299
305
|
rubysl-profiler (2.0.1)
|
@@ -301,7 +307,7 @@ GEM
|
|
301
307
|
rubysl-pty (2.0.2)
|
302
308
|
rubysl-rational (2.0.1)
|
303
309
|
rubysl-readline (2.0.2)
|
304
|
-
rubysl-resolv (2.
|
310
|
+
rubysl-resolv (2.1.0)
|
305
311
|
rubysl-rexml (2.0.2)
|
306
312
|
rubysl-rinda (2.0.1)
|
307
313
|
rubysl-rss (2.0.0)
|
@@ -321,7 +327,7 @@ GEM
|
|
321
327
|
rubysl-thwait (2.0.0)
|
322
328
|
rubysl-time (2.0.3)
|
323
329
|
rubysl-timeout (2.0.0)
|
324
|
-
rubysl-tmpdir (2.0.
|
330
|
+
rubysl-tmpdir (2.0.1)
|
325
331
|
rubysl-tsort (2.0.1)
|
326
332
|
rubysl-un (2.0.0)
|
327
333
|
rubysl-fileutils (~> 2.0)
|
@@ -332,28 +338,20 @@ GEM
|
|
332
338
|
rubysl-xmlrpc (2.0.0)
|
333
339
|
rubysl-yaml (2.0.4)
|
334
340
|
rubysl-zlib (2.0.1)
|
335
|
-
slop (3.
|
341
|
+
slop (3.5.0)
|
336
342
|
spoon (0.0.4)
|
337
343
|
ffi
|
338
|
-
sprockets (2.
|
344
|
+
sprockets (2.2.2)
|
339
345
|
hike (~> 1.2)
|
340
346
|
multi_json (~> 1.0)
|
341
347
|
rack (~> 1.0)
|
342
348
|
tilt (~> 1.1, != 1.3.0)
|
343
|
-
|
344
|
-
actionpack (>= 3.0)
|
345
|
-
activesupport (>= 3.0)
|
346
|
-
sprockets (~> 2.8)
|
347
|
-
sqlite3 (1.3.8)
|
349
|
+
sqlite3 (1.3.9)
|
348
350
|
sys-uname (0.9.2)
|
349
351
|
ffi (>= 1.0.0)
|
350
|
-
thor (0.
|
351
|
-
thread_safe (0.2.0)
|
352
|
-
atomic (>= 1.1.7, < 2)
|
353
|
-
thread_safe (0.2.0-java)
|
354
|
-
atomic (>= 1.1.7, < 2)
|
352
|
+
thor (0.19.1)
|
355
353
|
tilt (1.4.1)
|
356
|
-
travis (1.6.
|
354
|
+
travis (1.6.8)
|
357
355
|
addressable (~> 2.3)
|
358
356
|
backports
|
359
357
|
faraday (~> 0.8.7)
|
@@ -367,8 +365,8 @@ GEM
|
|
367
365
|
treetop (1.4.15)
|
368
366
|
polyglot
|
369
367
|
polyglot (>= 0.3.1)
|
370
|
-
typhoeus (0.6.
|
371
|
-
ethon (
|
368
|
+
typhoeus (0.6.8)
|
369
|
+
ethon (>= 0.7.0)
|
372
370
|
tzinfo (0.3.39)
|
373
371
|
websocket (1.0.7)
|
374
372
|
will_paginate (3.0.5)
|
@@ -387,8 +385,8 @@ DEPENDENCIES
|
|
387
385
|
jdbc-sqlite3
|
388
386
|
json (>= 1.5.1)
|
389
387
|
kaminari
|
390
|
-
rails (>= 3.0.
|
391
|
-
rake
|
388
|
+
rails (>= 3.2.0, < 4.0)
|
389
|
+
rake (~> 10.1.0)
|
392
390
|
rdoc
|
393
391
|
redgreen
|
394
392
|
rspec (>= 2.5.0)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.9.
|
1
|
+
1.9.3
|
data/algoliasearch-rails.gemspec
CHANGED
@@ -6,11 +6,11 @@
|
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "algoliasearch-rails"
|
9
|
-
s.version = "1.9.
|
9
|
+
s.version = "1.9.3"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.authors = ["Algolia"]
|
13
|
-
s.date = "2014-03-
|
13
|
+
s.date = "2014-03-26"
|
14
14
|
s.description = "AlgoliaSearch integration to your favorite ORM"
|
15
15
|
s.email = "contact@algolia.com"
|
16
16
|
s.extra_rdoc_files = [
|
data/lib/algoliasearch-rails.rb
CHANGED
@@ -92,7 +92,7 @@ module AlgoliaSearch
|
|
92
92
|
|
93
93
|
def geoloc(lat_attr, lng_attr)
|
94
94
|
add_attribute :_geoloc do |o|
|
95
|
-
{ lat
|
95
|
+
{ :lat => o.send(lat_attr).to_f, :lng => o.send(lng_attr).to_f }
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
@@ -140,7 +140,7 @@ module AlgoliaSearch
|
|
140
140
|
def algoliasearch(options = {}, &block)
|
141
141
|
self.algolia_index_settings = IndexSettings.new(block_given? ? Proc.new : nil)
|
142
142
|
self.algolia_settings = algolia_index_settings.to_settings
|
143
|
-
self.algolia_options = { type
|
143
|
+
self.algolia_options = { :type => algolia_full_const_get(model_name.to_s), :per_page => algolia_index_settings.get_setting(:hitsPerPage) || 10, :page => 1 }.merge(options)
|
144
144
|
|
145
145
|
attr_accessor :highlight_result
|
146
146
|
|
@@ -177,7 +177,7 @@ module AlgoliaSearch
|
|
177
177
|
objects = group.select { |o| !algolia_indexable?(o) }.map { |o| algolia_object_id_of(o) }
|
178
178
|
@algolia_index.delete_objects(objects)
|
179
179
|
# select only indexable objects
|
180
|
-
group.select
|
180
|
+
group = group.select { |o| algolia_indexable?(o) }
|
181
181
|
end
|
182
182
|
objects = group.map { |o| algolia_index_settings.get_attributes(o).merge 'objectID' => algolia_object_id_of(o) }
|
183
183
|
last_task = @algolia_index.save_objects(objects)
|
@@ -265,7 +265,7 @@ module AlgoliaSearch
|
|
265
265
|
o
|
266
266
|
end
|
267
267
|
end.compact
|
268
|
-
res = AlgoliaSearch::Pagination.create(results, json['nbHits'].to_i, algolia_options.merge({ page
|
268
|
+
res = AlgoliaSearch::Pagination.create(results, json['nbHits'].to_i, algolia_options.merge({ :page => json['page'] + 1, :per_page => json['hitsPerPage'] }))
|
269
269
|
res.extend(AdditionalMethods)
|
270
270
|
res.send(:algolia_init_raw_answer, json)
|
271
271
|
res
|
@@ -332,7 +332,7 @@ module AlgoliaSearch
|
|
332
332
|
def algolia_full_const_get(name)
|
333
333
|
list = name.split('::')
|
334
334
|
list.shift if list.first.blank?
|
335
|
-
obj = self
|
335
|
+
obj = Object.const_defined?(:RUBY_VERSION) && RUBY_VERSION.to_f < 1.9 ? Object : self
|
336
336
|
list.each do |x|
|
337
337
|
# This is required because const_get tries to look for constants in the
|
338
338
|
# ancestor chain, but we only want constants that are HERE
|
@@ -371,7 +371,7 @@ module AlgoliaSearch
|
|
371
371
|
|
372
372
|
def algolia_find_in_batches(batch_size, &block)
|
373
373
|
if (defined?(::ActiveRecord) && ancestors.include?(::ActiveRecord::Base)) || respond_to?(:find_in_batches)
|
374
|
-
find_in_batches(batch_size
|
374
|
+
find_in_batches(:batch_size => batch_size, &block)
|
375
375
|
else
|
376
376
|
# don't worry, mongoid has its own underlying cursor/streaming mechanism
|
377
377
|
items = []
|
@@ -6,7 +6,7 @@ module AlgoliaSearch
|
|
6
6
|
|
7
7
|
def configuration=(configuration)
|
8
8
|
@@configuration = configuration
|
9
|
-
Algolia.init application_id
|
9
|
+
Algolia.init :application_id => @@configuration[:application_id], :api_key => @@configuration[:api_key]
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -24,7 +24,7 @@ module AlgoliaSearch
|
|
24
24
|
|
25
25
|
class << self
|
26
26
|
def create(results, total_hits, options = {})
|
27
|
-
new results, offset
|
27
|
+
new results, :offset => ((options[:page] - 1) * options[:per_page]), :limit => options[:per_page], :total_count => total_hits
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/utilities_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
2
2
|
|
3
|
-
AlgoliaSearch.configuration = { application_id
|
3
|
+
AlgoliaSearch.configuration = { :application_id => ENV['ALGOLIA_APPLICATION_ID'], :api_key => ENV['ALGOLIA_API_KEY'] }
|
4
4
|
|
5
5
|
describe AlgoliaSearch::Utilities do
|
6
6
|
|
@@ -21,7 +21,7 @@
|
|
21
21
|
* THE SOFTWARE.
|
22
22
|
*/
|
23
23
|
|
24
|
-
var ALGOLIA_VERSION = '2.4.
|
24
|
+
var ALGOLIA_VERSION = '2.4.4';
|
25
25
|
|
26
26
|
/*
|
27
27
|
* Copyright (c) 2013 Algolia
|
@@ -72,7 +72,7 @@ var AlgoliaSearch = function(applicationID, apiKey, method, resolveDNS, hostsArr
|
|
72
72
|
}
|
73
73
|
if (this._isUndefined(method) || method == null) {
|
74
74
|
this.hosts.push(('https:' == document.location.protocol ? 'https' : 'http') + '://' + hostsArray[i]);
|
75
|
-
} else if (method === 'https' ||
|
75
|
+
} else if (method === 'https' || method === 'HTTPS') {
|
76
76
|
this.hosts.push('https://' + hostsArray[i]);
|
77
77
|
} else {
|
78
78
|
this.hosts.push('http://' + hostsArray[i]);
|
@@ -700,7 +700,7 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
700
700
|
* success: boolean set to true if the request was successfull
|
701
701
|
* content: the server answer that updateAt and taskID
|
702
702
|
*/
|
703
|
-
saveObject: function(object, callback)
|
703
|
+
saveObject: function(object, callback) {
|
704
704
|
var indexObj = this;
|
705
705
|
this.as._jsonRequest({ method: 'PUT',
|
706
706
|
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/' + encodeURIComponent(object.objectID),
|
@@ -879,10 +879,12 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
879
879
|
this.as._jsonRequest({ method: 'GET',
|
880
880
|
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/task/' + taskID,
|
881
881
|
callback: function(success, body) {
|
882
|
-
if (success
|
883
|
-
|
884
|
-
|
885
|
-
|
882
|
+
if (success) {
|
883
|
+
if (body.status === 'published') {
|
884
|
+
callback(true, body);
|
885
|
+
} else {
|
886
|
+
setTimeout(function() { indexObj.waitTask(taskID, callback); }, 100);
|
887
|
+
}
|
886
888
|
} else {
|
887
889
|
callback(false, body);
|
888
890
|
}
|
@@ -1173,12 +1175,13 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1173
1175
|
* success: boolean set to true if the request was successfull
|
1174
1176
|
* content: the query answer with an extra 'disjunctiveFacets' attribute
|
1175
1177
|
*/
|
1176
|
-
search: function(q, searchCallback) {
|
1178
|
+
search: function(q, searchCallback, searchParams) {
|
1177
1179
|
this.q = q;
|
1178
1180
|
this.searchCallback = searchCallback;
|
1179
|
-
this.
|
1180
|
-
this.
|
1181
|
-
this.
|
1181
|
+
this.searchParams = searchParams || {};
|
1182
|
+
this.page = this.page || 0;
|
1183
|
+
this.refinements = this.refinements || {};
|
1184
|
+
this.disjunctiveRefinements = this.disjunctiveRefinements || {};
|
1182
1185
|
this._search();
|
1183
1186
|
},
|
1184
1187
|
|
@@ -1291,12 +1294,12 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1291
1294
|
* @return {hash}
|
1292
1295
|
*/
|
1293
1296
|
_getHitsSearchParams: function() {
|
1294
|
-
return {
|
1297
|
+
return extend({}, this.searchParams, {
|
1295
1298
|
hitsPerPage: this.options.hitsPerPage,
|
1296
1299
|
page: this.page,
|
1297
1300
|
facets: this.options.facets,
|
1298
1301
|
facetFilters: this._getFacetFilters()
|
1299
|
-
};
|
1302
|
+
});
|
1300
1303
|
},
|
1301
1304
|
|
1302
1305
|
/**
|
@@ -1305,12 +1308,12 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1305
1308
|
* @return {hash}
|
1306
1309
|
*/
|
1307
1310
|
_getDisjunctiveFacetSearchParams: function(facet) {
|
1308
|
-
return {
|
1311
|
+
return extend({}, this.searchParams, {
|
1309
1312
|
hitsPerPage: 1,
|
1310
1313
|
page: 0,
|
1311
1314
|
facets: facet,
|
1312
1315
|
facetFilters: this._getFacetFilters(facet)
|
1313
|
-
};
|
1316
|
+
});
|
1314
1317
|
},
|
1315
1318
|
|
1316
1319
|
/**
|
@@ -1,7 +1,7 @@
|
|
1
1
|
/*!
|
2
|
-
* algoliasearch 2.4.
|
2
|
+
* algoliasearch 2.4.4
|
3
3
|
* https://github.com/algolia/algoliasearch-client-js
|
4
4
|
* Copyright 2014 Algolia SAS; Licensed MIT
|
5
5
|
*/
|
6
6
|
|
7
|
-
function AlgoliaExplainResults(a,b,c){function d(a,b){var c=[];if("object"==typeof a&&"matchedWords"in a&&"value"in a){for(var e=!1,f=0;f<a.matchedWords.length;++f){var g=a.matchedWords[f];g in b||(b[g]=1,e=!0)}e&&c.push(a.value)}else if("[object Array]"===Object.prototype.toString.call(a))for(var h=0;h<a.length;++h){var i=d(a[h],b);c=c.concat(i)}else if("object"==typeof a)for(var j in a)a.hasOwnProperty(j)&&(c=c.concat(d(a[j],b)));return c}function e(a,b,c){if(-1===c.indexOf("."))return c in a._highlightResult?d(a._highlightResult[c],b):[];for(var e=c.split("."),f=a._highlightResult,g=0;g<e.length;++g){if(!(e[g]in f))return[];f=f[e[g]]}return d(f,b)}var f={},g={},h=e(a,g,b);if(f.title=h.length>0?h[0]:"",f.subtitles=[],"undefined"!=typeof c)for(var i=0;i<c.length;++i)for(var j=e(a,g,c[i]),k=0;k<j.length;++k)f.subtitles.push({attr:c[i],value:j[k]});return f}var ALGOLIA_VERSION="2.4.2",AlgoliaSearch=function(a,b,c,d,e){this.applicationID=a,this.apiKey=b,this._isUndefined(e)&&(e=[a+"-1.algolia.io",a+"-2.algolia.io",a+"-3.algolia.io"]),this.hosts=[];for(var f=0;f<e.length;++f)Math.random()>.5&&this.hosts.reverse(),this._isUndefined(c)||null==c?this.hosts.push(("https:"==document.location.protocol?"https":"http")+"://"+e[f]):"https"===c||"HTTPS"===c?this.hosts.push("https://"+e[f]):this.hosts.push("http://"+e[f]);Math.random()>.5&&this.hosts.reverse(),(this._isUndefined(d)||d)&&this._jsonRequest({method:"GET",url:"/1/isalive"}),this.extraHeaders=[]};AlgoliaSearch.prototype={deleteIndex:function(a,b){this._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(a),callback:b})},moveIndex:function(a,b,c){var d={operation:"move",destination:b};this._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(a)+"/operation",body:d,callback:c})},copyIndex:function(a,b,c){var d={operation:"copy",destination:b};this._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(a)+"/operation",body:d,callback:c})},getLogs:function(a,b,c){this._isUndefined(b)&&(b=0),this._isUndefined(c)&&(c=10),this._jsonRequest({method:"GET",url:"/1/logs?offset="+b+"&length="+c,callback:a})},listIndexes:function(a){this._jsonRequest({method:"GET",url:"/1/indexes/",callback:a})},initIndex:function(a){return new this.Index(this,a)},listUserKeys:function(a){this._jsonRequest({method:"GET",url:"/1/keys",callback:a})},getUserKeyACL:function(a,b){this._jsonRequest({method:"GET",url:"/1/keys/"+a,callback:b})},deleteUserKey:function(a,b){this._jsonRequest({method:"DELETE",url:"/1/keys/"+a,callback:b})},addUserKey:function(a,b){var c={};c.acl=a,this._jsonRequest({method:"POST",url:"/1/keys",body:c,callback:b})},addUserKeyWithValidity:function(a,b,c,d,e){var f=this,g={};g.acl=a,g.validity=b,g.maxQueriesPerIPPerHour=c,g.maxHitsPerQuery=d,this._jsonRequest({method:"POST",url:"/1/indexes/"+f.indexName+"/keys",body:g,callback:e})},setSecurityTags:function(a){if("[object Array]"===Object.prototype.toString.call(a)){for(var b=[],c=0;c<a.length;++c)if("[object Array]"===Object.prototype.toString.call(a[c])){for(var d=[],e=0;e<a[c].length;++e)d.push(a[c][e]);b.push("("+d.join(",")+")")}else b.push(a[c]);a=b.join(",")}this.setExtraHeader("X-Algolia-TagFilters",a)},setUserToken:function(a){this.setExtraHeader("X-Algolia-UserToken",a)},startQueriesBatch:function(){this.batch=[]},addQueryInBatch:function(a,b,c){var d="query="+encodeURIComponent(b);this._isUndefined(c)||null==c||(d=this._getSearchParams(c,d)),this.batch.push({indexName:a,params:d})},clearCache:function(){this.cache={}},sendQueriesBatch:function(a,b){for(var c=this,d={requests:[],apiKey:this.apiKey,appID:this.applicationID},e=0;e<c.batch.length;++e)d.requests.push(c.batch[e]);if(window.clearTimeout(c.onDelayTrigger),!this._isUndefined(b)&&null!=b&&b>0){var f=window.setTimeout(function(){c._sendQueriesBatch(d,a)},b);c.onDelayTrigger=f}else this._sendQueriesBatch(d,a)},Index:function(a,b){this.indexName=b,this.as=a,this.typeAheadArgs=null,this.typeAheadValueOption=null},setExtraHeader:function(a,b){this.extraHeaders.push({key:a,value:b})},_sendQueriesBatch:function(a,b){this._jsonRequest({cache:this.cache,method:"POST",url:"/1/indexes/*/queries",body:a,callback:b})},_jsonRequest:function(a){var b=this,c=a.callback,d=null,e=a.url;if(this._isUndefined(a.body)||(e=a.url+"_body_"+JSON.stringify(a.body)),!this._isUndefined(a.cache)&&(d=a.cache,!this._isUndefined(d[e])))return this._isUndefined(c)||c(!0,d[e]),void 0;var f=function(g){var h=0;return b._isUndefined(g)||(h=g),b.hosts.length<=h?(b._isUndefined(c)||c(!1,{message:"Cannot contact server"}),void 0):(a.callback=function(g,i,j,k){i||b._isUndefined(k)||console.log("Error: "+k.message),i&&!b._isUndefined(a.cache)&&(d[e]=k),!i&&g&&h+1<b.hosts.length?f(h+1):b._isUndefined(c)||c(i,k)},a.hostname=b.hosts[h],b._jsonRequestByHost(a),void 0)};f()},_jsonRequestByHost:function(a){var b=null,c=this;this._isUndefined(a.body)||(b=JSON.stringify(a.body));var d=a.hostname+a.url,e=null;if(e=new XMLHttpRequest,"withCredentials"in e){e.open(a.method,d,!0),e.setRequestHeader("X-Algolia-API-Key",this.apiKey),e.setRequestHeader("X-Algolia-Application-Id",this.applicationID);for(var f=0;f<this.extraHeaders.length;++f)e.setRequestHeader(this.extraHeaders[f].key,this.extraHeaders[f].value);null!=b&&e.setRequestHeader("Content-type","application/json")}else"undefined"!=typeof XDomainRequest?(e=new XDomainRequest,e.open(a.method,d)):console.log("your browser is too old to support CORS requests");e.send(b),e.onload=function(b){if(c._isUndefined(b)||null==b.target)a.callback(!1,!0,b,JSON.parse(e.responseText));else{var d=0===b.target.status||503===b.target.status,f=200===b.target.status||201===b.target.status;a.callback(d,f,b.target,null!=b.target.response?JSON.parse(b.target.response):null)}},e.onerror=function(){a.callback(!0,!1,null,{message:"Could not connect to Host"})}},_getSearchParams:function(a,b){if(this._isUndefined(a)||null==a)return b;for(var c in a)null!=c&&a.hasOwnProperty(c)&&(b+=0===b.length?"?":"&",b+=c+"="+encodeURIComponent("[object Array]"===Object.prototype.toString.call(a[c])?JSON.stringify(a[c]):a[c]));return b},_isUndefined:function(a){return void 0===a},applicationID:null,apiKey:null,hosts:[],cache:{},extraHeaders:[]},AlgoliaSearch.prototype.Index.prototype={clearCache:function(){this.cache={}},addObject:function(a,b,c){var d=this;this.as._isUndefined(c)?this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(d.indexName),body:a,callback:b}):this.as._jsonRequest({method:"PUT",url:"/1/indexes/"+encodeURIComponent(d.indexName)+"/"+encodeURIComponent(c),body:a,callback:b})},addObjects:function(a,b){for(var c=this,d={requests:[]},e=0;e<a.length;++e){var f={action:"addObject",body:a[e]};d.requests.push(f)}this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/batch",body:d,callback:b})},getObject:function(a,b,c){var d=this,e="";if(!this.as._isUndefined(c)){e="?attributes=";for(var f=0;f<c.length;++f)0!==f&&(e+=","),e+=c[f]}this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(d.indexName)+"/"+encodeURIComponent(a)+e,callback:b})},partialUpdateObject:function(a,b){var c=this;this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/"+encodeURIComponent(a.objectID)+"/partial",body:a,callback:b})},partialUpdateObjects:function(a,b){for(var c=this,d={requests:[]},e=0;e<a.length;++e){var f={action:"partialUpdateObject",objectID:a[e].objectID,body:a[e]};d.requests.push(f)}this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/batch",body:d,callback:b})},saveObject:function(a,b){var c=this;this.as._jsonRequest({method:"PUT",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/"+encodeURIComponent(a.objectID),body:a,callback:b})},saveObjects:function(a,b){for(var c=this,d={requests:[]},e=0;e<a.length;++e){var f={action:"updateObject",objectID:a[e].objectID,body:a[e]};d.requests.push(f)}this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/batch",body:d,callback:b})},deleteObject:function(a,b){if(null==a||0===a.length)return b(!1,{message:"empty objectID"}),void 0;var c=this;this.as._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/"+encodeURIComponent(a),callback:b})},search:function(a,b,c,d){var e=this,f="query="+encodeURIComponent(a);if(this.as._isUndefined(c)||null==c||(f=this.as._getSearchParams(c,f)),window.clearTimeout(e.onDelayTrigger),!this.as._isUndefined(d)&&null!=d&&d>0){var g=window.setTimeout(function(){e._search(f,b)},d);e.onDelayTrigger=g}else this._search(f,b)},browse:function(a,b,c){var d=this,e="?page="+a;_.isUndefined(c)||(e+="&hitsPerPage="+c),this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(d.indexName)+"/browse"+e,callback:b})},ttAdapter:function(a){var b=this;return function(c,d){b.search(c,function(a,b){a&&d(b.hits)},a)}},waitTask:function(a,b){var c=this;this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/task/"+a,callback:function(d,e){if(d&&"published"===e.status)b(!0,e);else{if(d&&e.pendingTask)return c.waitTask(a,b);b(!1,e)}}})},clearIndex:function(a){var b=this;this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(b.indexName)+"/clear",callback:a})},getSettings:function(a){var b=this;this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(b.indexName)+"/settings",callback:a})},setSettings:function(a,b){var c=this;this.as._jsonRequest({method:"PUT",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/settings",body:a,callback:b})},listUserKeys:function(a){var b=this;this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(b.indexName)+"/keys",callback:a})},getUserKeyACL:function(a,b){var c=this;this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/keys/"+a,callback:b})},deleteUserKey:function(a,b){var c=this;this.as._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/keys/"+a,callback:b})},addUserKey:function(a,b){var c=this,d={};d.acl=a,this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/keys",body:d,callback:b})},addUserKeyWithValidity:function(a,b,c,d,e){var f=this,g={};g.acl=a,g.validity=b,g.maxQueriesPerIPPerHour=c,g.maxHitsPerQuery=d,this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(f.indexName)+"/keys",body:g,callback:e})},_search:function(a,b){this.as._jsonRequest({cache:this.cache,method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/query",body:{params:a,apiKey:this.as.apiKey,appID:this.as.applicationID},callback:b})},as:null,indexName:null,cache:{},typeAheadArgs:null,typeAheadValueOption:null,emptyConstructor:function(){}},function(){var a,b=function(a){a=a||{};for(var b=1;b<arguments.length;b++)if(arguments[b])for(var c in arguments[b])arguments[b].hasOwnProperty(c)&&(a[c]=arguments[b][c]);return a};window.AlgoliaSearchHelper=function(c,d,e){var f={facets:[],disjunctiveFacets:[],hitsPerPage:20};this.init(c,d,b({},f,e)),a=this},AlgoliaSearchHelper.prototype={init:function(a,b,c){this.client=a,this.index=b,this.options=c,this.page=0,this.refinements={},this.disjunctiveRefinements={}},search:function(a,b){this.q=a,this.searchCallback=b,this.page=0,this.refinements={},this.disjunctiveRefinements={},this._search()},toggleRefine:function(a,b){for(var c=0;c<this.options.facets.length;++c)if(this.options.facets[c]==a){var d=a+":"+b;return this.refinements[d]=!this.refinements[d],this.page=0,this._search(),!0}this.disjunctiveRefinements[a]=this.disjunctiveRefinements[a]||{};for(var e=0;e<this.options.disjunctiveFacets.length;++e)if(this.options.disjunctiveFacets[e]==a)return this.disjunctiveRefinements[a][b]=!this.disjunctiveRefinements[a][b],this.page=0,this._search(),!0;return!1},isRefined:function(a,b){var c=a+":"+b;return this.refinements[c]?!0:this.disjunctiveRefinements[a]&&this.disjunctiveRefinements[a][b]?!0:!1},nextPage:function(){this._gotoPage(this.page+1)},previousPage:function(){this.page>0&&this._gotoPage(this.page-1)},_gotoPage:function(a){this.page=a,this._search()},_search:function(){this.client.startQueriesBatch(),this.client.addQueryInBatch(this.index,this.q,this._getHitsSearchParams());for(var b=0;b<this.options.disjunctiveFacets.length;++b)this.client.addQueryInBatch(this.index,this.q,this._getDisjunctiveFacetSearchParams(this.options.disjunctiveFacets[b]));this.client.sendQueriesBatch(function(b,c){if(!b)return a.searchCallback(!1,c),void 0;var d=c.results[0];d.disjunctiveFacets={};for(var e=1;e<c.results.length;++e)for(var f in c.results[e].facets)if(d.disjunctiveFacets[f]=c.results[e].facets[f],a.disjunctiveRefinements[f])for(var g in a.disjunctiveRefinements[f])!d.disjunctiveFacets[f][g]&&a.disjunctiveRefinements[f][g]&&(d.disjunctiveFacets[f][g]=0);a.searchCallback(!0,d)})},_getHitsSearchParams:function(){return{hitsPerPage:this.options.hitsPerPage,page:this.page,facets:this.options.facets,facetFilters:this._getFacetFilters()}},_getDisjunctiveFacetSearchParams:function(a){return{hitsPerPage:1,page:0,facets:a,facetFilters:this._getFacetFilters(a)}},_getFacetFilters:function(a){var b=[];for(var c in this.refinements)this.refinements[c]&&b.push(c);for(var d in this.disjunctiveRefinements)if(d!=a){var e=[];for(var f in this.disjunctiveRefinements[d])this.disjunctiveRefinements[d][f]&&e.push(d+":"+f);e.length>0&&b.push(e)}return b}}}();
|
7
|
+
function AlgoliaExplainResults(a,b,c){function d(a,b){var c=[];if("object"==typeof a&&"matchedWords"in a&&"value"in a){for(var e=!1,f=0;f<a.matchedWords.length;++f){var g=a.matchedWords[f];g in b||(b[g]=1,e=!0)}e&&c.push(a.value)}else if("[object Array]"===Object.prototype.toString.call(a))for(var h=0;h<a.length;++h){var i=d(a[h],b);c=c.concat(i)}else if("object"==typeof a)for(var j in a)a.hasOwnProperty(j)&&(c=c.concat(d(a[j],b)));return c}function e(a,b,c){if(-1===c.indexOf("."))return c in a._highlightResult?d(a._highlightResult[c],b):[];for(var e=c.split("."),f=a._highlightResult,g=0;g<e.length;++g){if(!(e[g]in f))return[];f=f[e[g]]}return d(f,b)}var f={},g={},h=e(a,g,b);if(f.title=h.length>0?h[0]:"",f.subtitles=[],"undefined"!=typeof c)for(var i=0;i<c.length;++i)for(var j=e(a,g,c[i]),k=0;k<j.length;++k)f.subtitles.push({attr:c[i],value:j[k]});return f}var ALGOLIA_VERSION="2.4.4",AlgoliaSearch=function(a,b,c,d,e){this.applicationID=a,this.apiKey=b,this._isUndefined(e)&&(e=[a+"-1.algolia.io",a+"-2.algolia.io",a+"-3.algolia.io"]),this.hosts=[];for(var f=0;f<e.length;++f)Math.random()>.5&&this.hosts.reverse(),this._isUndefined(c)||null==c?this.hosts.push(("https:"==document.location.protocol?"https":"http")+"://"+e[f]):"https"===c||"HTTPS"===c?this.hosts.push("https://"+e[f]):this.hosts.push("http://"+e[f]);Math.random()>.5&&this.hosts.reverse(),(this._isUndefined(d)||d)&&this._jsonRequest({method:"GET",url:"/1/isalive"}),this.extraHeaders=[]};AlgoliaSearch.prototype={deleteIndex:function(a,b){this._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(a),callback:b})},moveIndex:function(a,b,c){var d={operation:"move",destination:b};this._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(a)+"/operation",body:d,callback:c})},copyIndex:function(a,b,c){var d={operation:"copy",destination:b};this._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(a)+"/operation",body:d,callback:c})},getLogs:function(a,b,c){this._isUndefined(b)&&(b=0),this._isUndefined(c)&&(c=10),this._jsonRequest({method:"GET",url:"/1/logs?offset="+b+"&length="+c,callback:a})},listIndexes:function(a){this._jsonRequest({method:"GET",url:"/1/indexes/",callback:a})},initIndex:function(a){return new this.Index(this,a)},listUserKeys:function(a){this._jsonRequest({method:"GET",url:"/1/keys",callback:a})},getUserKeyACL:function(a,b){this._jsonRequest({method:"GET",url:"/1/keys/"+a,callback:b})},deleteUserKey:function(a,b){this._jsonRequest({method:"DELETE",url:"/1/keys/"+a,callback:b})},addUserKey:function(a,b){var c={};c.acl=a,this._jsonRequest({method:"POST",url:"/1/keys",body:c,callback:b})},addUserKeyWithValidity:function(a,b,c,d,e){var f=this,g={};g.acl=a,g.validity=b,g.maxQueriesPerIPPerHour=c,g.maxHitsPerQuery=d,this._jsonRequest({method:"POST",url:"/1/indexes/"+f.indexName+"/keys",body:g,callback:e})},setSecurityTags:function(a){if("[object Array]"===Object.prototype.toString.call(a)){for(var b=[],c=0;c<a.length;++c)if("[object Array]"===Object.prototype.toString.call(a[c])){for(var d=[],e=0;e<a[c].length;++e)d.push(a[c][e]);b.push("("+d.join(",")+")")}else b.push(a[c]);a=b.join(",")}this.setExtraHeader("X-Algolia-TagFilters",a)},setUserToken:function(a){this.setExtraHeader("X-Algolia-UserToken",a)},startQueriesBatch:function(){this.batch=[]},addQueryInBatch:function(a,b,c){var d="query="+encodeURIComponent(b);this._isUndefined(c)||null==c||(d=this._getSearchParams(c,d)),this.batch.push({indexName:a,params:d})},clearCache:function(){this.cache={}},sendQueriesBatch:function(a,b){for(var c=this,d={requests:[],apiKey:this.apiKey,appID:this.applicationID},e=0;e<c.batch.length;++e)d.requests.push(c.batch[e]);if(window.clearTimeout(c.onDelayTrigger),!this._isUndefined(b)&&null!=b&&b>0){var f=window.setTimeout(function(){c._sendQueriesBatch(d,a)},b);c.onDelayTrigger=f}else this._sendQueriesBatch(d,a)},Index:function(a,b){this.indexName=b,this.as=a,this.typeAheadArgs=null,this.typeAheadValueOption=null},setExtraHeader:function(a,b){this.extraHeaders.push({key:a,value:b})},_sendQueriesBatch:function(a,b){this._jsonRequest({cache:this.cache,method:"POST",url:"/1/indexes/*/queries",body:a,callback:b})},_jsonRequest:function(a){var b=this,c=a.callback,d=null,e=a.url;if(this._isUndefined(a.body)||(e=a.url+"_body_"+JSON.stringify(a.body)),!this._isUndefined(a.cache)&&(d=a.cache,!this._isUndefined(d[e])))return this._isUndefined(c)||c(!0,d[e]),void 0;var f=function(g){var h=0;return b._isUndefined(g)||(h=g),b.hosts.length<=h?(b._isUndefined(c)||c(!1,{message:"Cannot contact server"}),void 0):(a.callback=function(g,i,j,k){i||b._isUndefined(k)||console.log("Error: "+k.message),i&&!b._isUndefined(a.cache)&&(d[e]=k),!i&&g&&h+1<b.hosts.length?f(h+1):b._isUndefined(c)||c(i,k)},a.hostname=b.hosts[h],b._jsonRequestByHost(a),void 0)};f()},_jsonRequestByHost:function(a){var b=null,c=this;this._isUndefined(a.body)||(b=JSON.stringify(a.body));var d=a.hostname+a.url,e=null;if(e=new XMLHttpRequest,"withCredentials"in e){e.open(a.method,d,!0),e.setRequestHeader("X-Algolia-API-Key",this.apiKey),e.setRequestHeader("X-Algolia-Application-Id",this.applicationID);for(var f=0;f<this.extraHeaders.length;++f)e.setRequestHeader(this.extraHeaders[f].key,this.extraHeaders[f].value);null!=b&&e.setRequestHeader("Content-type","application/json")}else"undefined"!=typeof XDomainRequest?(e=new XDomainRequest,e.open(a.method,d)):console.log("your browser is too old to support CORS requests");e.send(b),e.onload=function(b){if(c._isUndefined(b)||null==b.target)a.callback(!1,!0,b,JSON.parse(e.responseText));else{var d=0===b.target.status||503===b.target.status,f=200===b.target.status||201===b.target.status;a.callback(d,f,b.target,null!=b.target.response?JSON.parse(b.target.response):null)}},e.onerror=function(){a.callback(!0,!1,null,{message:"Could not connect to Host"})}},_getSearchParams:function(a,b){if(this._isUndefined(a)||null==a)return b;for(var c in a)null!=c&&a.hasOwnProperty(c)&&(b+=0===b.length?"?":"&",b+=c+"="+encodeURIComponent("[object Array]"===Object.prototype.toString.call(a[c])?JSON.stringify(a[c]):a[c]));return b},_isUndefined:function(a){return void 0===a},applicationID:null,apiKey:null,hosts:[],cache:{},extraHeaders:[]},AlgoliaSearch.prototype.Index.prototype={clearCache:function(){this.cache={}},addObject:function(a,b,c){var d=this;this.as._isUndefined(c)?this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(d.indexName),body:a,callback:b}):this.as._jsonRequest({method:"PUT",url:"/1/indexes/"+encodeURIComponent(d.indexName)+"/"+encodeURIComponent(c),body:a,callback:b})},addObjects:function(a,b){for(var c=this,d={requests:[]},e=0;e<a.length;++e){var f={action:"addObject",body:a[e]};d.requests.push(f)}this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/batch",body:d,callback:b})},getObject:function(a,b,c){var d=this,e="";if(!this.as._isUndefined(c)){e="?attributes=";for(var f=0;f<c.length;++f)0!==f&&(e+=","),e+=c[f]}this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(d.indexName)+"/"+encodeURIComponent(a)+e,callback:b})},partialUpdateObject:function(a,b){var c=this;this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/"+encodeURIComponent(a.objectID)+"/partial",body:a,callback:b})},partialUpdateObjects:function(a,b){for(var c=this,d={requests:[]},e=0;e<a.length;++e){var f={action:"partialUpdateObject",objectID:a[e].objectID,body:a[e]};d.requests.push(f)}this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/batch",body:d,callback:b})},saveObject:function(a,b){var c=this;this.as._jsonRequest({method:"PUT",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/"+encodeURIComponent(a.objectID),body:a,callback:b})},saveObjects:function(a,b){for(var c=this,d={requests:[]},e=0;e<a.length;++e){var f={action:"updateObject",objectID:a[e].objectID,body:a[e]};d.requests.push(f)}this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/batch",body:d,callback:b})},deleteObject:function(a,b){if(null==a||0===a.length)return b(!1,{message:"empty objectID"}),void 0;var c=this;this.as._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/"+encodeURIComponent(a),callback:b})},search:function(a,b,c,d){var e=this,f="query="+encodeURIComponent(a);if(this.as._isUndefined(c)||null==c||(f=this.as._getSearchParams(c,f)),window.clearTimeout(e.onDelayTrigger),!this.as._isUndefined(d)&&null!=d&&d>0){var g=window.setTimeout(function(){e._search(f,b)},d);e.onDelayTrigger=g}else this._search(f,b)},browse:function(a,b,c){var d=this,e="?page="+a;_.isUndefined(c)||(e+="&hitsPerPage="+c),this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(d.indexName)+"/browse"+e,callback:b})},ttAdapter:function(a){var b=this;return function(c,d){b.search(c,function(a,b){a&&d(b.hits)},a)}},waitTask:function(a,b){var c=this;this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/task/"+a,callback:function(d,e){d?"published"===e.status?b(!0,e):setTimeout(function(){c.waitTask(a,b)},100):b(!1,e)}})},clearIndex:function(a){var b=this;this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(b.indexName)+"/clear",callback:a})},getSettings:function(a){var b=this;this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(b.indexName)+"/settings",callback:a})},setSettings:function(a,b){var c=this;this.as._jsonRequest({method:"PUT",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/settings",body:a,callback:b})},listUserKeys:function(a){var b=this;this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(b.indexName)+"/keys",callback:a})},getUserKeyACL:function(a,b){var c=this;this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/keys/"+a,callback:b})},deleteUserKey:function(a,b){var c=this;this.as._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/keys/"+a,callback:b})},addUserKey:function(a,b){var c=this,d={};d.acl=a,this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/keys",body:d,callback:b})},addUserKeyWithValidity:function(a,b,c,d,e){var f=this,g={};g.acl=a,g.validity=b,g.maxQueriesPerIPPerHour=c,g.maxHitsPerQuery=d,this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(f.indexName)+"/keys",body:g,callback:e})},_search:function(a,b){this.as._jsonRequest({cache:this.cache,method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/query",body:{params:a,apiKey:this.as.apiKey,appID:this.as.applicationID},callback:b})},as:null,indexName:null,cache:{},typeAheadArgs:null,typeAheadValueOption:null,emptyConstructor:function(){}},function(){var a,b=function(a){a=a||{};for(var b=1;b<arguments.length;b++)if(arguments[b])for(var c in arguments[b])arguments[b].hasOwnProperty(c)&&(a[c]=arguments[b][c]);return a};window.AlgoliaSearchHelper=function(c,d,e){var f={facets:[],disjunctiveFacets:[],hitsPerPage:20};this.init(c,d,b({},f,e)),a=this},AlgoliaSearchHelper.prototype={init:function(a,b,c){this.client=a,this.index=b,this.options=c,this.page=0,this.refinements={},this.disjunctiveRefinements={}},search:function(a,b,c){this.q=a,this.searchCallback=b,this.searchParams=c||{},this.page=this.page||0,this.refinements=this.refinements||{},this.disjunctiveRefinements=this.disjunctiveRefinements||{},this._search()},toggleRefine:function(a,b){for(var c=0;c<this.options.facets.length;++c)if(this.options.facets[c]==a){var d=a+":"+b;return this.refinements[d]=!this.refinements[d],this.page=0,this._search(),!0}this.disjunctiveRefinements[a]=this.disjunctiveRefinements[a]||{};for(var e=0;e<this.options.disjunctiveFacets.length;++e)if(this.options.disjunctiveFacets[e]==a)return this.disjunctiveRefinements[a][b]=!this.disjunctiveRefinements[a][b],this.page=0,this._search(),!0;return!1},isRefined:function(a,b){var c=a+":"+b;return this.refinements[c]?!0:this.disjunctiveRefinements[a]&&this.disjunctiveRefinements[a][b]?!0:!1},nextPage:function(){this._gotoPage(this.page+1)},previousPage:function(){this.page>0&&this._gotoPage(this.page-1)},_gotoPage:function(a){this.page=a,this._search()},_search:function(){this.client.startQueriesBatch(),this.client.addQueryInBatch(this.index,this.q,this._getHitsSearchParams());for(var b=0;b<this.options.disjunctiveFacets.length;++b)this.client.addQueryInBatch(this.index,this.q,this._getDisjunctiveFacetSearchParams(this.options.disjunctiveFacets[b]));this.client.sendQueriesBatch(function(b,c){if(!b)return a.searchCallback(!1,c),void 0;var d=c.results[0];d.disjunctiveFacets={};for(var e=1;e<c.results.length;++e)for(var f in c.results[e].facets)if(d.disjunctiveFacets[f]=c.results[e].facets[f],a.disjunctiveRefinements[f])for(var g in a.disjunctiveRefinements[f])!d.disjunctiveFacets[f][g]&&a.disjunctiveRefinements[f][g]&&(d.disjunctiveFacets[f][g]=0);a.searchCallback(!0,d)})},_getHitsSearchParams:function(){return b({},this.searchParams,{hitsPerPage:this.options.hitsPerPage,page:this.page,facets:this.options.facets,facetFilters:this._getFacetFilters()})},_getDisjunctiveFacetSearchParams:function(a){return b({},this.searchParams,{hitsPerPage:1,page:0,facets:a,facetFilters:this._getFacetFilters(a)})},_getFacetFilters:function(a){var b=[];for(var c in this.refinements)this.refinements[c]&&b.push(c);for(var d in this.disjunctiveRefinements)if(d!=a){var e=[];for(var f in this.disjunctiveRefinements[d])this.disjunctiveRefinements[d][f]&&e.push(d+":"+f);e.length>0&&b.push(e)}return b}}}();
|
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.9.
|
4
|
+
version: 1.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Algolia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|