algoliasearch-rails 1.11.13 → 1.11.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/vendor/assets/javascripts/algolia/algoliasearch.js +295 -74
- data/vendor/assets/javascripts/algolia/algoliasearch.min.js +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7b3d9e0a8e4c99410af478ac78778874106386d
|
4
|
+
data.tar.gz: f683877fcee4845908424990bf29ae2f127bb2e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 739b503dc381838bc5a3da1b5c44063175fafcc024f71802050d97abe2b6bf814344ddf3abaecfb105425ef3c750bcfab1d8addf99c8897e52c222073910070d
|
7
|
+
data.tar.gz: f99ed457e8a65e38703862da6bd619f8a11e2213b3c25b767f537d41873d09f5161fc51de0bd0d258b5454e0af34449ad82a648e53442d67aae11b43ae27171c
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.11.
|
1
|
+
1.11.14
|
@@ -21,7 +21,7 @@
|
|
21
21
|
* THE SOFTWARE.
|
22
22
|
*/
|
23
23
|
|
24
|
-
var ALGOLIA_VERSION = '2.
|
24
|
+
var ALGOLIA_VERSION = '2.9.2';
|
25
25
|
|
26
26
|
/*
|
27
27
|
* Copyright (c) 2013 Algolia
|
@@ -68,6 +68,10 @@ var AlgoliaSearch = function(applicationID, apiKey, methodOrOptions, resolveDNS,
|
|
68
68
|
this.requestTimeoutInMs = 2000;
|
69
69
|
this.extraHeaders = [];
|
70
70
|
this.jsonp = null;
|
71
|
+
this.options = {};
|
72
|
+
|
73
|
+
// make sure every client instance has it's own cache
|
74
|
+
this.cache = {};
|
71
75
|
|
72
76
|
var method;
|
73
77
|
var tld = 'net';
|
@@ -76,6 +80,7 @@ var AlgoliaSearch = function(applicationID, apiKey, methodOrOptions, resolveDNS,
|
|
76
80
|
} else {
|
77
81
|
// Take all option from the hash
|
78
82
|
var options = methodOrOptions || {};
|
83
|
+
this.options = options;
|
79
84
|
if (!this._isUndefined(options.method)) {
|
80
85
|
method = options.method;
|
81
86
|
}
|
@@ -131,6 +136,13 @@ var AlgoliaSearch = function(applicationID, apiKey, methodOrOptions, resolveDNS,
|
|
131
136
|
this.hosts.unshift(this.host_protocol + this.applicationID + '-dsn.algolia.' + tld);
|
132
137
|
}
|
133
138
|
}
|
139
|
+
// angular dependencies injection
|
140
|
+
if (this.options.angular) {
|
141
|
+
this.options.angular.$injector.invoke(['$http', '$q', function ($http, $q) {
|
142
|
+
self.options.angular.$q = $q;
|
143
|
+
self.options.angular.$http = $http;
|
144
|
+
}]);
|
145
|
+
}
|
134
146
|
};
|
135
147
|
|
136
148
|
function AlgoliaExplainResults(hit, titleAttribute, otherAttributes) {
|
@@ -163,7 +175,7 @@ function AlgoliaExplainResults(hit, titleAttribute, otherAttributes) {
|
|
163
175
|
}
|
164
176
|
return res;
|
165
177
|
}
|
166
|
-
|
178
|
+
|
167
179
|
function _getHitExplanationForOneAttr(hit, foundWords, attr) {
|
168
180
|
var base = hit._highlightResult || hit;
|
169
181
|
if (attr.indexOf('.') === -1) {
|
@@ -219,7 +231,7 @@ AlgoliaSearch.prototype = {
|
|
219
231
|
* content: the server answer that contains the task ID
|
220
232
|
*/
|
221
233
|
deleteIndex: function(indexName, callback) {
|
222
|
-
this._jsonRequest({ method: 'DELETE',
|
234
|
+
return this._jsonRequest({ method: 'DELETE',
|
223
235
|
url: '/1/indexes/' + encodeURIComponent(indexName),
|
224
236
|
callback: callback });
|
225
237
|
},
|
@@ -233,7 +245,7 @@ AlgoliaSearch.prototype = {
|
|
233
245
|
*/
|
234
246
|
moveIndex: function(srcIndexName, dstIndexName, callback) {
|
235
247
|
var postObj = {operation: 'move', destination: dstIndexName};
|
236
|
-
this._jsonRequest({ method: 'POST',
|
248
|
+
return this._jsonRequest({ method: 'POST',
|
237
249
|
url: '/1/indexes/' + encodeURIComponent(srcIndexName) + '/operation',
|
238
250
|
body: postObj,
|
239
251
|
callback: callback });
|
@@ -249,7 +261,7 @@ AlgoliaSearch.prototype = {
|
|
249
261
|
*/
|
250
262
|
copyIndex: function(srcIndexName, dstIndexName, callback) {
|
251
263
|
var postObj = {operation: 'copy', destination: dstIndexName};
|
252
|
-
this._jsonRequest({ method: 'POST',
|
264
|
+
return this._jsonRequest({ method: 'POST',
|
253
265
|
url: '/1/indexes/' + encodeURIComponent(srcIndexName) + '/operation',
|
254
266
|
body: postObj,
|
255
267
|
callback: callback });
|
@@ -270,7 +282,7 @@ AlgoliaSearch.prototype = {
|
|
270
282
|
length = 10;
|
271
283
|
}
|
272
284
|
|
273
|
-
this._jsonRequest({ method: 'GET',
|
285
|
+
return this._jsonRequest({ method: 'GET',
|
274
286
|
url: '/1/logs?offset=' + offset + '&length=' + length,
|
275
287
|
callback: callback });
|
276
288
|
},
|
@@ -283,8 +295,8 @@ AlgoliaSearch.prototype = {
|
|
283
295
|
* @param page The page to retrieve, starting at 0.
|
284
296
|
*/
|
285
297
|
listIndexes: function(callback, page) {
|
286
|
-
var params = page ? '?page=' + page : '';
|
287
|
-
this._jsonRequest({ method: 'GET',
|
298
|
+
var params = typeof page !== 'undefined' ? '?page=' + page : '';
|
299
|
+
return this._jsonRequest({ method: 'GET',
|
288
300
|
url: '/1/indexes' + params,
|
289
301
|
callback: callback });
|
290
302
|
},
|
@@ -306,7 +318,7 @@ AlgoliaSearch.prototype = {
|
|
306
318
|
* content: the server answer with user keys list or error description if success is false.
|
307
319
|
*/
|
308
320
|
listUserKeys: function(callback) {
|
309
|
-
this._jsonRequest({ method: 'GET',
|
321
|
+
return this._jsonRequest({ method: 'GET',
|
310
322
|
url: '/1/keys',
|
311
323
|
callback: callback });
|
312
324
|
},
|
@@ -318,7 +330,7 @@ AlgoliaSearch.prototype = {
|
|
318
330
|
* content: the server answer with user keys list or error description if success is false.
|
319
331
|
*/
|
320
332
|
getUserKeyACL: function(key, callback) {
|
321
|
-
this._jsonRequest({ method: 'GET',
|
333
|
+
return this._jsonRequest({ method: 'GET',
|
322
334
|
url: '/1/keys/' + key,
|
323
335
|
callback: callback });
|
324
336
|
},
|
@@ -330,7 +342,7 @@ AlgoliaSearch.prototype = {
|
|
330
342
|
* content: the server answer with user keys list or error description if success is false.
|
331
343
|
*/
|
332
344
|
deleteUserKey: function(key, callback) {
|
333
|
-
this._jsonRequest({ method: 'DELETE',
|
345
|
+
return this._jsonRequest({ method: 'DELETE',
|
334
346
|
url: '/1/keys/' + key,
|
335
347
|
callback: callback });
|
336
348
|
},
|
@@ -352,7 +364,7 @@ AlgoliaSearch.prototype = {
|
|
352
364
|
addUserKey: function(acls, callback) {
|
353
365
|
var aclsObject = {};
|
354
366
|
aclsObject.acl = acls;
|
355
|
-
this._jsonRequest({ method: 'POST',
|
367
|
+
return this._jsonRequest({ method: 'POST',
|
356
368
|
url: '/1/keys',
|
357
369
|
body: aclsObject,
|
358
370
|
callback: callback });
|
@@ -382,7 +394,7 @@ AlgoliaSearch.prototype = {
|
|
382
394
|
aclsObject.validity = validity;
|
383
395
|
aclsObject.maxQueriesPerIPPerHour = maxQueriesPerIPPerHour;
|
384
396
|
aclsObject.maxHitsPerQuery = maxHitsPerQuery;
|
385
|
-
this._jsonRequest({ method: 'POST',
|
397
|
+
return this._jsonRequest({ method: 'POST',
|
386
398
|
url: '/1/indexes/' + indexObj.indexName + '/keys',
|
387
399
|
body: aclsObject,
|
388
400
|
callback: callback });
|
@@ -476,13 +488,13 @@ AlgoliaSearch.prototype = {
|
|
476
488
|
}, delay);
|
477
489
|
as.onDelayTrigger = onDelayTrigger;
|
478
490
|
} else {
|
479
|
-
this._sendQueriesBatch(params, callback);
|
491
|
+
return this._sendQueriesBatch(params, callback);
|
480
492
|
}
|
481
493
|
},
|
482
494
|
|
483
495
|
/**
|
484
496
|
* Set the number of milliseconds a request can take before automatically being terminated.
|
485
|
-
*
|
497
|
+
*
|
486
498
|
* @param {Number} milliseconds
|
487
499
|
*/
|
488
500
|
setRequestTimeout: function(milliseconds)
|
@@ -501,10 +513,13 @@ AlgoliaSearch.prototype = {
|
|
501
513
|
this.as = algoliasearch;
|
502
514
|
this.typeAheadArgs = null;
|
503
515
|
this.typeAheadValueOption = null;
|
516
|
+
|
517
|
+
// make sure every index instance has it's own cache
|
518
|
+
this.cache = {};
|
504
519
|
},
|
505
520
|
/**
|
506
521
|
* Add an extra field to the HTTP request
|
507
|
-
*
|
522
|
+
*
|
508
523
|
* @param key the header field name
|
509
524
|
* @param value the header field value
|
510
525
|
*/
|
@@ -516,7 +531,7 @@ AlgoliaSearch.prototype = {
|
|
516
531
|
|
517
532
|
if (this.jsonp === null) {
|
518
533
|
var self = this;
|
519
|
-
this._jsonRequest({ cache: this.cache,
|
534
|
+
return this._jsonRequest({ cache: this.cache,
|
520
535
|
method: 'POST',
|
521
536
|
url: '/1/indexes/*/queries',
|
522
537
|
body: params,
|
@@ -538,13 +553,13 @@ AlgoliaSearch.prototype = {
|
|
538
553
|
jsonpParams += i + '=' + encodeURIComponent(q) + '&';
|
539
554
|
}
|
540
555
|
var pObj = {params: jsonpParams};
|
541
|
-
this._jsonRequest({ cache: this.cache,
|
556
|
+
return this._jsonRequest({ cache: this.cache,
|
542
557
|
method: 'GET',
|
543
558
|
url: '/1/indexes/*',
|
544
|
-
|
559
|
+
body: pObj,
|
545
560
|
callback: callback });
|
546
561
|
} else {
|
547
|
-
this._jsonRequest({ cache: this.cache,
|
562
|
+
return this._jsonRequest({ cache: this.cache,
|
548
563
|
method: 'POST',
|
549
564
|
url: '/1/indexes/*/queries',
|
550
565
|
body: params,
|
@@ -559,32 +574,40 @@ AlgoliaSearch.prototype = {
|
|
559
574
|
var callback = opts.callback;
|
560
575
|
var cache = null;
|
561
576
|
var cacheID = opts.url;
|
577
|
+
var deferred = null;
|
578
|
+
if (this.options.jQuery) {
|
579
|
+
deferred = this.options.jQuery.$.Deferred();
|
580
|
+
deferred.promise = deferred.promise(); // promise is a property in angular
|
581
|
+
} else if (this.options.angular) {
|
582
|
+
deferred = this.options.angular.$q.defer();
|
583
|
+
}
|
584
|
+
|
562
585
|
if (!this._isUndefined(opts.body)) {
|
563
586
|
cacheID = opts.url + '_body_' + JSON.stringify(opts.body);
|
564
587
|
}
|
565
588
|
if (!this._isUndefined(opts.cache)) {
|
566
589
|
cache = opts.cache;
|
567
590
|
if (!this._isUndefined(cache[cacheID])) {
|
568
|
-
if (!this._isUndefined(callback)) {
|
591
|
+
if (!this._isUndefined(callback) && callback) {
|
569
592
|
setTimeout(function () { callback(true, cache[cacheID]); }, 1);
|
570
593
|
}
|
571
|
-
|
594
|
+
deferred && deferred.resolve(cache[cacheID]);
|
595
|
+
return deferred && deferred.promise;
|
572
596
|
}
|
573
597
|
}
|
574
598
|
|
575
599
|
opts.successiveRetryCount = 0;
|
576
600
|
var impl = function() {
|
577
601
|
if (opts.successiveRetryCount >= self.hosts.length) {
|
578
|
-
|
602
|
+
var error = { message: 'Cannot connect the Algolia\'s Search API. Please send an email to support@algolia.com to report the issue.' };
|
603
|
+
if (!self._isUndefined(callback) && callback) {
|
579
604
|
opts.successiveRetryCount = 0;
|
580
|
-
callback(false,
|
605
|
+
callback(false, error);
|
581
606
|
}
|
607
|
+
deferred && deferred.reject(error);
|
582
608
|
return;
|
583
609
|
}
|
584
|
-
opts.callback = function(retry, success,
|
585
|
-
if (!success && !self._isUndefined(body)) {
|
586
|
-
window.console && console.log('Error: ' + body.message);
|
587
|
-
}
|
610
|
+
opts.callback = function(retry, success, obj, body) {
|
588
611
|
if (success && !self._isUndefined(opts.cache)) {
|
589
612
|
cache[cacheID] = body;
|
590
613
|
}
|
@@ -594,7 +617,8 @@ AlgoliaSearch.prototype = {
|
|
594
617
|
impl();
|
595
618
|
} else {
|
596
619
|
opts.successiveRetryCount = 0;
|
597
|
-
|
620
|
+
deferred && (success ? deferred.resolve(body) : deferred.reject(body));
|
621
|
+
if (!self._isUndefined(callback) && callback) {
|
598
622
|
callback(success, body);
|
599
623
|
}
|
600
624
|
}
|
@@ -603,6 +627,8 @@ AlgoliaSearch.prototype = {
|
|
603
627
|
self._jsonRequestByHost(opts);
|
604
628
|
};
|
605
629
|
impl();
|
630
|
+
|
631
|
+
return deferred && deferred.promise;
|
606
632
|
},
|
607
633
|
|
608
634
|
_jsonRequestByHost: function(opts) {
|
@@ -611,11 +637,106 @@ AlgoliaSearch.prototype = {
|
|
611
637
|
|
612
638
|
if (this.jsonp) {
|
613
639
|
this._makeJsonpRequestByHost(url, opts);
|
640
|
+
} else if (this.options.jQuery) {
|
641
|
+
this._makejQueryRequestByHost(url, opts);
|
642
|
+
} else if (this.options.angular) {
|
643
|
+
this._makeAngularRequestByHost(url, opts);
|
614
644
|
} else {
|
615
645
|
this._makeXmlHttpRequestByHost(url, opts);
|
616
646
|
}
|
617
647
|
},
|
618
648
|
|
649
|
+
/**
|
650
|
+
* Make a $http
|
651
|
+
*
|
652
|
+
* @param url request url (includes endpoint and path)
|
653
|
+
* @param opts all request opts
|
654
|
+
*/
|
655
|
+
_makeAngularRequestByHost: function(url, opts) {
|
656
|
+
var self = this;
|
657
|
+
var body = null;
|
658
|
+
|
659
|
+
if (!this._isUndefined(opts.body)) {
|
660
|
+
body = JSON.stringify(opts.body);
|
661
|
+
}
|
662
|
+
|
663
|
+
url += ((url.indexOf('?') === -1) ? '?' : '&') + 'X-Algolia-API-Key=' + this.apiKey;
|
664
|
+
url += '&X-Algolia-Application-Id=' + this.applicationID;
|
665
|
+
if (this.userToken) {
|
666
|
+
url += '&X-Algolia-UserToken=' + encodeURIComponent(this.userToken);
|
667
|
+
}
|
668
|
+
if (this.tagFilters) {
|
669
|
+
url += '&X-Algolia-TagFilters=' + encodeURIComponent(this.tagFilters);
|
670
|
+
}
|
671
|
+
for (var i = 0; i < this.extraHeaders.length; ++i) {
|
672
|
+
url += '&' + this.extraHeaders[i].key + '=' + this.extraHeaders[i].value;
|
673
|
+
}
|
674
|
+
this.options.angular.$http({
|
675
|
+
url: url,
|
676
|
+
method: opts.method,
|
677
|
+
data: body,
|
678
|
+
cache: false,
|
679
|
+
timeout: (this.requestTimeoutInMs * (opts.successiveRetryCount + 1))
|
680
|
+
}).then(function(response) {
|
681
|
+
opts.callback(false, true, null, response.data);
|
682
|
+
}, function(response) {
|
683
|
+
if (response.status === 0) {
|
684
|
+
// xhr.timeout is not handled by Angular.js right now
|
685
|
+
// let's retry
|
686
|
+
opts.callback(true, false, null, response.data);
|
687
|
+
} else if (response.status == 400 || response.status === 403 || response.status === 404) {
|
688
|
+
opts.callback(false, false, null, response.data);
|
689
|
+
} else {
|
690
|
+
opts.callback(true, false, null, response.data);
|
691
|
+
}
|
692
|
+
});
|
693
|
+
},
|
694
|
+
|
695
|
+
/**
|
696
|
+
* Make a $.ajax
|
697
|
+
*
|
698
|
+
* @param url request url (includes endpoint and path)
|
699
|
+
* @param opts all request opts
|
700
|
+
*/
|
701
|
+
_makejQueryRequestByHost: function(url, opts) {
|
702
|
+
var self = this;
|
703
|
+
var body = null;
|
704
|
+
|
705
|
+
if (!this._isUndefined(opts.body)) {
|
706
|
+
body = JSON.stringify(opts.body);
|
707
|
+
}
|
708
|
+
|
709
|
+
url += ((url.indexOf('?') === -1) ? '?' : '&') + 'X-Algolia-API-Key=' + this.apiKey;
|
710
|
+
url += '&X-Algolia-Application-Id=' + this.applicationID;
|
711
|
+
if (this.userToken) {
|
712
|
+
url += '&X-Algolia-UserToken=' + encodeURIComponent(this.userToken);
|
713
|
+
}
|
714
|
+
if (this.tagFilters) {
|
715
|
+
url += '&X-Algolia-TagFilters=' + encodeURIComponent(this.tagFilters);
|
716
|
+
}
|
717
|
+
for (var i = 0; i < this.extraHeaders.length; ++i) {
|
718
|
+
url += '&' + this.extraHeaders[i].key + '=' + this.extraHeaders[i].value;
|
719
|
+
}
|
720
|
+
this.options.jQuery.$.ajax(url, {
|
721
|
+
type: opts.method,
|
722
|
+
timeout: (this.requestTimeoutInMs * (opts.successiveRetryCount + 1)),
|
723
|
+
dataType: 'json',
|
724
|
+
data: body,
|
725
|
+
error: function(xhr, textStatus, error) {
|
726
|
+
if (textStatus === 'timeout') {
|
727
|
+
opts.callback(true, false, null, { 'message': 'Timeout - Could not connect to endpoint ' + url } );
|
728
|
+
} else if (xhr.status === 400 || xhr.status === 403 || xhr.status === 404) {
|
729
|
+
opts.callback(false, false, null, xhr.responseJSON );
|
730
|
+
} else {
|
731
|
+
opts.callback(true, false, null, { 'message': error } );
|
732
|
+
}
|
733
|
+
},
|
734
|
+
success: function(data, textStatus, xhr) {
|
735
|
+
opts.callback(false, true, null, data);
|
736
|
+
}
|
737
|
+
});
|
738
|
+
},
|
739
|
+
|
619
740
|
/**
|
620
741
|
* Make a JSONP request
|
621
742
|
*
|
@@ -706,7 +827,7 @@ AlgoliaSearch.prototype = {
|
|
706
827
|
|
707
828
|
/**
|
708
829
|
* Make a XmlHttpRequest
|
709
|
-
*
|
830
|
+
*
|
710
831
|
* @param url request url (includes endpoint and path)
|
711
832
|
* @param opts all request opts
|
712
833
|
*/
|
@@ -768,7 +889,6 @@ AlgoliaSearch.prototype = {
|
|
768
889
|
ontimeout = null;
|
769
890
|
|
770
891
|
if (!self._isUndefined(event) && event.target !== null) {
|
771
|
-
var retry = (event.target.status === 0 || event.target.status === 503);
|
772
892
|
var success = false;
|
773
893
|
var response = null;
|
774
894
|
|
@@ -776,12 +896,12 @@ AlgoliaSearch.prototype = {
|
|
776
896
|
// Handle CORS requests IE8/IE9
|
777
897
|
response = event.target.responseText;
|
778
898
|
success = (response && response.length > 0);
|
779
|
-
}
|
780
|
-
else {
|
899
|
+
} else {
|
781
900
|
response = event.target.response;
|
782
901
|
success = (event.target.status === 200 || event.target.status === 201);
|
783
902
|
}
|
784
903
|
|
904
|
+
var retry = !success && event.target.status !== 400 && event.target.status !== 403 && event.target.status !== 404;
|
785
905
|
opts.callback(retry, success, event.target, response ? JSON.parse(response) : null);
|
786
906
|
} else {
|
787
907
|
opts.callback(false, true, event, JSON.parse(xmlHttp.responseText));
|
@@ -823,7 +943,6 @@ AlgoliaSearch.prototype = {
|
|
823
943
|
tagFilters: null,
|
824
944
|
userToken: null,
|
825
945
|
hosts: [],
|
826
|
-
cache: {},
|
827
946
|
extraHeaders: []
|
828
947
|
};
|
829
948
|
|
@@ -851,12 +970,12 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
851
970
|
addObject: function(content, callback, objectID) {
|
852
971
|
var indexObj = this;
|
853
972
|
if (this.as._isUndefined(objectID)) {
|
854
|
-
this.as._jsonRequest({ method: 'POST',
|
973
|
+
return this.as._jsonRequest({ method: 'POST',
|
855
974
|
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName),
|
856
975
|
body: content,
|
857
976
|
callback: callback });
|
858
977
|
} else {
|
859
|
-
this.as._jsonRequest({ method: 'PUT',
|
978
|
+
return this.as._jsonRequest({ method: 'PUT',
|
860
979
|
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/' + encodeURIComponent(objectID),
|
861
980
|
body: content,
|
862
981
|
callback: callback });
|
@@ -879,7 +998,7 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
879
998
|
body: objects[i] };
|
880
999
|
postObj.requests.push(request);
|
881
1000
|
}
|
882
|
-
this.as._jsonRequest({ method: 'POST',
|
1001
|
+
return this.as._jsonRequest({ method: 'POST',
|
883
1002
|
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/batch',
|
884
1003
|
body: postObj,
|
885
1004
|
callback: callback });
|
@@ -894,6 +1013,10 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
894
1013
|
* @param attributes (optional) if set, contains the array of attribute names to retrieve
|
895
1014
|
*/
|
896
1015
|
getObject: function(objectID, callback, attributes) {
|
1016
|
+
if (Object.prototype.toString.call(callback) === '[object Array]' && !attributes) {
|
1017
|
+
attributes = callback;
|
1018
|
+
callback = null;
|
1019
|
+
}
|
897
1020
|
var indexObj = this;
|
898
1021
|
var params = '';
|
899
1022
|
if (!this.as._isUndefined(attributes)) {
|
@@ -906,12 +1029,12 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
906
1029
|
}
|
907
1030
|
}
|
908
1031
|
if (this.as.jsonp === null) {
|
909
|
-
this.as._jsonRequest({ method: 'GET',
|
1032
|
+
return this.as._jsonRequest({ method: 'GET',
|
910
1033
|
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/' + encodeURIComponent(objectID) + params,
|
911
1034
|
callback: callback });
|
912
1035
|
} else {
|
913
1036
|
var pObj = {params: params};
|
914
|
-
this.as._jsonRequest({ method: 'GET',
|
1037
|
+
return this.as._jsonRequest({ method: 'GET',
|
915
1038
|
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/' + encodeURIComponent(objectID),
|
916
1039
|
callback: callback,
|
917
1040
|
body: pObj});
|
@@ -929,7 +1052,7 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
929
1052
|
*/
|
930
1053
|
partialUpdateObject: function(partialObject, callback) {
|
931
1054
|
var indexObj = this;
|
932
|
-
this.as._jsonRequest({ method: 'POST',
|
1055
|
+
return this.as._jsonRequest({ method: 'POST',
|
933
1056
|
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/' + encodeURIComponent(partialObject.objectID) + '/partial',
|
934
1057
|
body: partialObject,
|
935
1058
|
callback: callback });
|
@@ -951,7 +1074,7 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
951
1074
|
body: objects[i] };
|
952
1075
|
postObj.requests.push(request);
|
953
1076
|
}
|
954
|
-
this.as._jsonRequest({ method: 'POST',
|
1077
|
+
return this.as._jsonRequest({ method: 'POST',
|
955
1078
|
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/batch',
|
956
1079
|
body: postObj,
|
957
1080
|
callback: callback });
|
@@ -966,7 +1089,7 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
966
1089
|
*/
|
967
1090
|
saveObject: function(object, callback) {
|
968
1091
|
var indexObj = this;
|
969
|
-
this.as._jsonRequest({ method: 'PUT',
|
1092
|
+
return this.as._jsonRequest({ method: 'PUT',
|
970
1093
|
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/' + encodeURIComponent(object.objectID),
|
971
1094
|
body: object,
|
972
1095
|
callback: callback });
|
@@ -988,7 +1111,7 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
988
1111
|
body: objects[i] };
|
989
1112
|
postObj.requests.push(request);
|
990
1113
|
}
|
991
|
-
this.as._jsonRequest({ method: 'POST',
|
1114
|
+
return this.as._jsonRequest({ method: 'POST',
|
992
1115
|
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/batch',
|
993
1116
|
body: postObj,
|
994
1117
|
callback: callback });
|
@@ -1007,7 +1130,7 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1007
1130
|
return;
|
1008
1131
|
}
|
1009
1132
|
var indexObj = this;
|
1010
|
-
this.as._jsonRequest({ method: 'DELETE',
|
1133
|
+
return this.as._jsonRequest({ method: 'DELETE',
|
1011
1134
|
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/' + encodeURIComponent(objectID),
|
1012
1135
|
callback: callback });
|
1013
1136
|
},
|
@@ -1080,6 +1203,21 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1080
1203
|
* @param delay (optional) if set, wait for this delay (in ms) and only send the query if there was no other in the meantime.
|
1081
1204
|
*/
|
1082
1205
|
search: function(query, callback, args, delay) {
|
1206
|
+
if (query === undefined || query === null) {
|
1207
|
+
query = '';
|
1208
|
+
}
|
1209
|
+
|
1210
|
+
// no query = getAllObjects
|
1211
|
+
if (typeof query === 'function') {
|
1212
|
+
callback = query;
|
1213
|
+
query = '';
|
1214
|
+
}
|
1215
|
+
|
1216
|
+
if (typeof callback === 'object' && (this.as._isUndefined(args) || !args)) {
|
1217
|
+
args = callback;
|
1218
|
+
callback = null;
|
1219
|
+
}
|
1220
|
+
|
1083
1221
|
var indexObj = this;
|
1084
1222
|
var params = 'query=' + encodeURIComponent(query);
|
1085
1223
|
if (!this.as._isUndefined(args) && args !== null) {
|
@@ -1092,7 +1230,7 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1092
1230
|
}, delay);
|
1093
1231
|
indexObj.onDelayTrigger = onDelayTrigger;
|
1094
1232
|
} else {
|
1095
|
-
this._search(params, callback);
|
1233
|
+
return this._search(params, callback);
|
1096
1234
|
}
|
1097
1235
|
},
|
1098
1236
|
|
@@ -1104,12 +1242,16 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1104
1242
|
* @param hitsPerPage: Pagination parameter used to select the number of hits per page. Defaults to 1000.
|
1105
1243
|
*/
|
1106
1244
|
browse: function(page, callback, hitsPerPage) {
|
1245
|
+
if (+callback > 0 && (this.as._isUndefined(hitsPerPage) || !hitsPerPage)) {
|
1246
|
+
hitsPerPage = callback;
|
1247
|
+
callback = null;
|
1248
|
+
}
|
1107
1249
|
var indexObj = this;
|
1108
1250
|
var params = '?page=' + page;
|
1109
1251
|
if (!this.as._isUndefined(hitsPerPage)) {
|
1110
1252
|
params += '&hitsPerPage=' + hitsPerPage;
|
1111
1253
|
}
|
1112
|
-
this.as._jsonRequest({ method: 'GET',
|
1254
|
+
return this.as._jsonRequest({ method: 'GET',
|
1113
1255
|
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/browse' + params,
|
1114
1256
|
callback: callback });
|
1115
1257
|
},
|
@@ -1140,7 +1282,7 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1140
1282
|
*/
|
1141
1283
|
waitTask: function(taskID, callback) {
|
1142
1284
|
var indexObj = this;
|
1143
|
-
this.as._jsonRequest({ method: 'GET',
|
1285
|
+
return this.as._jsonRequest({ method: 'GET',
|
1144
1286
|
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/task/' + taskID,
|
1145
1287
|
callback: function(success, body) {
|
1146
1288
|
if (success) {
|
@@ -1164,7 +1306,7 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1164
1306
|
*/
|
1165
1307
|
clearIndex: function(callback) {
|
1166
1308
|
var indexObj = this;
|
1167
|
-
this.as._jsonRequest({ method: 'POST',
|
1309
|
+
return this.as._jsonRequest({ method: 'POST',
|
1168
1310
|
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/clear',
|
1169
1311
|
callback: callback });
|
1170
1312
|
},
|
@@ -1177,7 +1319,7 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1177
1319
|
*/
|
1178
1320
|
getSettings: function(callback) {
|
1179
1321
|
var indexObj = this;
|
1180
|
-
this.as._jsonRequest({ method: 'GET',
|
1322
|
+
return this.as._jsonRequest({ method: 'GET',
|
1181
1323
|
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/settings',
|
1182
1324
|
callback: callback });
|
1183
1325
|
},
|
@@ -1238,7 +1380,7 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1238
1380
|
*/
|
1239
1381
|
setSettings: function(settings, callback) {
|
1240
1382
|
var indexObj = this;
|
1241
|
-
this.as._jsonRequest({ method: 'PUT',
|
1383
|
+
return this.as._jsonRequest({ method: 'PUT',
|
1242
1384
|
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/settings',
|
1243
1385
|
body: settings,
|
1244
1386
|
callback: callback });
|
@@ -1252,7 +1394,7 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1252
1394
|
*/
|
1253
1395
|
listUserKeys: function(callback) {
|
1254
1396
|
var indexObj = this;
|
1255
|
-
this.as._jsonRequest({ method: 'GET',
|
1397
|
+
return this.as._jsonRequest({ method: 'GET',
|
1256
1398
|
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/keys',
|
1257
1399
|
callback: callback });
|
1258
1400
|
},
|
@@ -1265,7 +1407,7 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1265
1407
|
*/
|
1266
1408
|
getUserKeyACL: function(key, callback) {
|
1267
1409
|
var indexObj = this;
|
1268
|
-
this.as._jsonRequest({ method: 'GET',
|
1410
|
+
return this.as._jsonRequest({ method: 'GET',
|
1269
1411
|
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/keys/' + key,
|
1270
1412
|
callback: callback });
|
1271
1413
|
},
|
@@ -1278,7 +1420,7 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1278
1420
|
*/
|
1279
1421
|
deleteUserKey: function(key, callback) {
|
1280
1422
|
var indexObj = this;
|
1281
|
-
this.as._jsonRequest({ method: 'DELETE',
|
1423
|
+
return this.as._jsonRequest({ method: 'DELETE',
|
1282
1424
|
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/keys/' + key,
|
1283
1425
|
callback: callback });
|
1284
1426
|
},
|
@@ -1301,7 +1443,7 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1301
1443
|
var indexObj = this;
|
1302
1444
|
var aclsObject = {};
|
1303
1445
|
aclsObject.acl = acls;
|
1304
|
-
this.as._jsonRequest({ method: 'POST',
|
1446
|
+
return this.as._jsonRequest({ method: 'POST',
|
1305
1447
|
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/keys',
|
1306
1448
|
body: aclsObject,
|
1307
1449
|
callback: callback });
|
@@ -1331,7 +1473,7 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1331
1473
|
aclsObject.validity = validity;
|
1332
1474
|
aclsObject.maxQueriesPerIPPerHour = maxQueriesPerIPPerHour;
|
1333
1475
|
aclsObject.maxHitsPerQuery = maxHitsPerQuery;
|
1334
|
-
this.as._jsonRequest({ method: 'POST',
|
1476
|
+
return this.as._jsonRequest({ method: 'POST',
|
1335
1477
|
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/keys',
|
1336
1478
|
body: aclsObject,
|
1337
1479
|
callback: callback });
|
@@ -1343,7 +1485,7 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1343
1485
|
var pObj = {params: params};
|
1344
1486
|
if (this.as.jsonp === null) {
|
1345
1487
|
var self = this;
|
1346
|
-
this.as._jsonRequest({ cache: this.cache,
|
1488
|
+
return this.as._jsonRequest({ cache: this.cache,
|
1347
1489
|
method: 'POST',
|
1348
1490
|
url: '/1/indexes/' + encodeURIComponent(this.indexName) + '/query',
|
1349
1491
|
body: pObj,
|
@@ -1359,13 +1501,13 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1359
1501
|
}
|
1360
1502
|
});
|
1361
1503
|
} else if (this.as.jsonp) {
|
1362
|
-
this.as._jsonRequest({ cache: this.cache,
|
1504
|
+
return this.as._jsonRequest({ cache: this.cache,
|
1363
1505
|
method: 'GET',
|
1364
1506
|
url: '/1/indexes/' + encodeURIComponent(this.indexName),
|
1365
1507
|
body: pObj,
|
1366
1508
|
callback: callback });
|
1367
1509
|
} else {
|
1368
|
-
this.as._jsonRequest({ cache: this.cache,
|
1510
|
+
return this.as._jsonRequest({ cache: this.cache,
|
1369
1511
|
method: 'POST',
|
1370
1512
|
url: '/1/indexes/' + encodeURIComponent(this.indexName) + '/query',
|
1371
1513
|
body: pObj,
|
@@ -1376,10 +1518,8 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1376
1518
|
// internal attributes
|
1377
1519
|
as: null,
|
1378
1520
|
indexName: null,
|
1379
|
-
cache: {},
|
1380
1521
|
typeAheadArgs: null,
|
1381
|
-
typeAheadValueOption: null
|
1382
|
-
emptyConstructor: function() {}
|
1522
|
+
typeAheadValueOption: null
|
1383
1523
|
};
|
1384
1524
|
|
1385
1525
|
/*
|
@@ -1453,6 +1593,7 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1453
1593
|
this.options = options;
|
1454
1594
|
this.page = 0;
|
1455
1595
|
this.refinements = {};
|
1596
|
+
this.excludes = {};
|
1456
1597
|
this.disjunctiveRefinements = {};
|
1457
1598
|
this.extraQueries = [];
|
1458
1599
|
},
|
@@ -1530,6 +1671,47 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1530
1671
|
this.refinements[refinement] = false;
|
1531
1672
|
},
|
1532
1673
|
|
1674
|
+
/**
|
1675
|
+
* Ensure a facet exclude exists
|
1676
|
+
* @param {string} facet the facet to refine
|
1677
|
+
* @param {string} value the associated value
|
1678
|
+
*/
|
1679
|
+
addExclude: function(facet, value) {
|
1680
|
+
var refinement = facet + ':-' + value;
|
1681
|
+
this.excludes = this.excludes || {};
|
1682
|
+
this.excludes[refinement] = true;
|
1683
|
+
},
|
1684
|
+
|
1685
|
+
/**
|
1686
|
+
* Ensure a facet exclude does not exist
|
1687
|
+
* @param {string} facet the facet to refine
|
1688
|
+
* @param {string} value the associated value
|
1689
|
+
*/
|
1690
|
+
removeExclude: function(facet, value) {
|
1691
|
+
var refinement = facet + ':-' + value;
|
1692
|
+
this.excludes = this.excludes || {};
|
1693
|
+
this.excludes[refinement] = false;
|
1694
|
+
},
|
1695
|
+
|
1696
|
+
/**
|
1697
|
+
* Toggle refinement state of an exclude
|
1698
|
+
* @param {string} facet the facet to refine
|
1699
|
+
* @param {string} value the associated value
|
1700
|
+
* @return {boolean} true if the facet has been found
|
1701
|
+
*/
|
1702
|
+
toggleExclude: function(facet, value) {
|
1703
|
+
for (var i = 0; i < this.options.facets.length; ++i) {
|
1704
|
+
if (this.options.facets[i] == facet) {
|
1705
|
+
var refinement = facet + ':-' + value;
|
1706
|
+
this.excludes[refinement] = !this.excludes[refinement];
|
1707
|
+
this.page = 0;
|
1708
|
+
this._search();
|
1709
|
+
return true;
|
1710
|
+
}
|
1711
|
+
}
|
1712
|
+
return false;
|
1713
|
+
},
|
1714
|
+
|
1533
1715
|
/**
|
1534
1716
|
* Toggle refinement state of a facet
|
1535
1717
|
* @param {string} facet the facet to refine
|
@@ -1575,6 +1757,20 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1575
1757
|
return false;
|
1576
1758
|
},
|
1577
1759
|
|
1760
|
+
/**
|
1761
|
+
* Check the exclude state of a facet
|
1762
|
+
* @param {string} facet the facet
|
1763
|
+
* @param {string} value the associated value
|
1764
|
+
* @return {boolean} true if refined
|
1765
|
+
*/
|
1766
|
+
isExcluded: function(facet, value) {
|
1767
|
+
var refinement = facet + ':-' + value;
|
1768
|
+
if (this.excludes[refinement]) {
|
1769
|
+
return true;
|
1770
|
+
}
|
1771
|
+
return false;
|
1772
|
+
},
|
1773
|
+
|
1578
1774
|
/**
|
1579
1775
|
* Go to next page
|
1580
1776
|
*/
|
@@ -1657,7 +1853,8 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1657
1853
|
this.client.addQueryInBatch(this.index, this.q, this._getHitsSearchParams());
|
1658
1854
|
var disjunctiveFacets = [];
|
1659
1855
|
var unusedDisjunctiveFacets = {};
|
1660
|
-
|
1856
|
+
var i = 0;
|
1857
|
+
for (i = 0; i < this.options.disjunctiveFacets.length; ++i) {
|
1661
1858
|
var facet = this.options.disjunctiveFacets[i];
|
1662
1859
|
if (this._hasDisjunctiveRefinements(facet)) {
|
1663
1860
|
disjunctiveFacets.push(facet);
|
@@ -1665,10 +1862,10 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1665
1862
|
unusedDisjunctiveFacets[facet] = true;
|
1666
1863
|
}
|
1667
1864
|
}
|
1668
|
-
for (
|
1865
|
+
for (i = 0; i < disjunctiveFacets.length; ++i) {
|
1669
1866
|
this.client.addQueryInBatch(this.index, this.q, this._getDisjunctiveFacetSearchParams(disjunctiveFacets[i]));
|
1670
1867
|
}
|
1671
|
-
for (
|
1868
|
+
for (i = 0; i < this.extraQueries.length; ++i) {
|
1672
1869
|
this.client.addQueryInBatch(this.extraQueries[i].index, this.extraQueries[i].query, this.extraQueries[i].params);
|
1673
1870
|
}
|
1674
1871
|
var self = this;
|
@@ -1680,6 +1877,7 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1680
1877
|
var aggregatedAnswer = content.results[0];
|
1681
1878
|
aggregatedAnswer.disjunctiveFacets = aggregatedAnswer.disjunctiveFacets || {};
|
1682
1879
|
aggregatedAnswer.facetStats = aggregatedAnswer.facetStats || {};
|
1880
|
+
// create disjunctive facets from facets (disjunctive facets without refinements)
|
1683
1881
|
for (var facet in unusedDisjunctiveFacets) {
|
1684
1882
|
if (aggregatedAnswer.facets[facet] && !aggregatedAnswer.disjunctiveFacets[facet]) {
|
1685
1883
|
aggregatedAnswer.disjunctiveFacets[facet] = aggregatedAnswer.facets[facet];
|
@@ -1690,26 +1888,43 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1690
1888
|
}
|
1691
1889
|
}
|
1692
1890
|
}
|
1693
|
-
|
1694
|
-
|
1695
|
-
|
1696
|
-
|
1697
|
-
|
1698
|
-
|
1699
|
-
|
1891
|
+
// aggregate the disjunctive facets
|
1892
|
+
for (i = 0; i < disjunctiveFacets.length; ++i) {
|
1893
|
+
for (var dfacet in content.results[i + 1].facets) {
|
1894
|
+
aggregatedAnswer.disjunctiveFacets[dfacet] = content.results[i + 1].facets[dfacet];
|
1895
|
+
if (self.disjunctiveRefinements[dfacet]) {
|
1896
|
+
for (var value in self.disjunctiveRefinements[dfacet]) {
|
1897
|
+
// add the disjunctive reginements if it is no more retrieved
|
1898
|
+
if (!aggregatedAnswer.disjunctiveFacets[dfacet][value] && self.disjunctiveRefinements[dfacet][value]) {
|
1899
|
+
aggregatedAnswer.disjunctiveFacets[dfacet][value] = 0;
|
1700
1900
|
}
|
1701
1901
|
}
|
1702
1902
|
}
|
1703
1903
|
}
|
1904
|
+
// aggregate the disjunctive facets stats
|
1704
1905
|
for (var stats in content.results[i + 1].facets_stats) {
|
1705
1906
|
aggregatedAnswer.facetStats[stats] = content.results[i + 1].facets_stats[stats];
|
1706
1907
|
}
|
1707
1908
|
}
|
1909
|
+
// add the excludes
|
1910
|
+
for (var exclude in self.excludes) {
|
1911
|
+
if (self.excludes[exclude]) {
|
1912
|
+
var e = exclude.indexOf(':-');
|
1913
|
+
var facet = exclude.slice(0, e);
|
1914
|
+
var value = exclude.slice(e + 2);
|
1915
|
+
aggregatedAnswer.facets[facet] = aggregatedAnswer.facets[facet] || {};
|
1916
|
+
if (!aggregatedAnswer.facets[facet][value]) {
|
1917
|
+
aggregatedAnswer.facets[facet][value] = 0;
|
1918
|
+
}
|
1919
|
+
}
|
1920
|
+
}
|
1921
|
+
// call the actual callback
|
1708
1922
|
if (self.extraQueries.length === 0) {
|
1709
1923
|
self.searchCallback(true, aggregatedAnswer);
|
1710
1924
|
} else {
|
1925
|
+
// append the extra queries
|
1711
1926
|
var c = { results: [ aggregatedAnswer ] };
|
1712
|
-
for (
|
1927
|
+
for (i = 0; i < self.extraQueries.length; ++i) {
|
1713
1928
|
c.results.push(content.results[1 + disjunctiveFacets.length + i]);
|
1714
1929
|
}
|
1715
1930
|
self.searchCallback(true, c);
|
@@ -1723,10 +1938,11 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1723
1938
|
*/
|
1724
1939
|
_getHitsSearchParams: function() {
|
1725
1940
|
var facets = [];
|
1726
|
-
|
1941
|
+
var i = 0;
|
1942
|
+
for (i = 0; i < this.options.facets.length; ++i) {
|
1727
1943
|
facets.push(this.options.facets[i]);
|
1728
1944
|
}
|
1729
|
-
for (
|
1945
|
+
for (i = 0; i < this.options.disjunctiveFacets.length; ++i) {
|
1730
1946
|
var facet = this.options.disjunctiveFacets[i];
|
1731
1947
|
if (!this._hasDisjunctiveRefinements(facet)) {
|
1732
1948
|
facets.push(facet);
|
@@ -1786,6 +2002,11 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1786
2002
|
facetFilters.push(refinement);
|
1787
2003
|
}
|
1788
2004
|
}
|
2005
|
+
for (var refinement in this.excludes) {
|
2006
|
+
if (this.excludes[refinement]) {
|
2007
|
+
facetFilters.push(refinement);
|
2008
|
+
}
|
2009
|
+
}
|
1789
2010
|
for (var disjunctiveRefinement in this.disjunctiveRefinements) {
|
1790
2011
|
if (disjunctiveRefinement != facet) {
|
1791
2012
|
var refinements = [];
|
@@ -1,7 +1,7 @@
|
|
1
1
|
/*!
|
2
|
-
* algoliasearch 2.
|
2
|
+
* algoliasearch 2.9.2
|
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){var f=a._highlightResult||a;if(-1===c.indexOf("."))return c in f?d(f[c],b):[];for(var g=c.split("."),h=f,i=0;i<g.length;++i){if("[object Array]"===Object.prototype.toString.call(h)){for(var j=[],k=0;k<h.length;++k)j=j.concat(e(h[k],b,g.slice(i).join(".")));return j}if(!(g[i]in h))return[];h=h[g[i]]}return d(h,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.8.6",AlgoliaSearch=function(a,b,c,d,e){this.applicationID=a,this.apiKey=b,this.dsn=!0,this.dsnHost=null,this.hosts=[],this.currentHostIndex=0,this.requestTimeoutInMs=2e3,this.extraHeaders=[],this.jsonp=null;var f,g="net";if("string"==typeof c)f=c;else{var h=c||{};this._isUndefined(h.method)||(f=h.method),this._isUndefined(h.tld)||(g=h.tld),this._isUndefined(h.dsn)||(this.dsn=h.dsn),this._isUndefined(h.hosts)||(e=h.hosts),this._isUndefined(h.dsnHost)||(this.dsnHost=h.dsnHost),this._isUndefined(h.requestTimeoutInMs)||(this.requestTimeoutInMs=+h.requestTimeoutInMs),this._isUndefined(h.jsonp)||(this.jsonp=h.jsonp)}this._isUndefined(e)&&(e=[this.applicationID+"-1.algolia."+g,this.applicationID+"-2.algolia."+g,this.applicationID+"-3.algolia."+g]),this.host_protocol="http://",this._isUndefined(f)||null===f?this.host_protocol=("https:"==document.location.protocol?"https":"http")+"://":("https"===f||"HTTPS"===f)&&(this.host_protocol="https://");for(var i=0;i<e.length;++i)Math.random()>.5&&this.hosts.reverse(),this.hosts.push(this.host_protocol+e[i]);Math.random()>.5&&this.hosts.reverse(),(this.dsn||null!=this.dsnHost)&&this.hosts.unshift(this.dsnHost?this.host_protocol+this.dsnHost:this.host_protocol+this.applicationID+"-dsn.algolia."+g)};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,b){var c=b?"?page="+b:"";this._jsonRequest({method:"GET",url:"/1/indexes"+c,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.tagFilters=a},setUserToken:function(a){this.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:[]},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)},setRequestTimeout:function(a){a&&(this.requestTimeoutInMs=parseInt(a,10))},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){if(null===this.jsonp){var c=this;this._jsonRequest({cache:this.cache,method:"POST",url:"/1/indexes/*/queries",body:a,callback:function(d,e){d?(c.jsonp=!1,b&&b(d,e)):(c.jsonp=!0,c._sendQueriesBatch(a,b))}})}else if(this.jsonp){for(var d="",e=0;e<a.requests.length;++e){var f="/1/indexes/"+encodeURIComponent(a.requests[e].indexName)+"?"+a.requests[e].params;d+=e+"="+encodeURIComponent(f)+"&"}var g={params:d};this._jsonRequest({cache:this.cache,method:"GET",url:"/1/indexes/*",body:g,callback:b})}else 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 void(this._isUndefined(c)||setTimeout(function(){c(!0,d[e])},1));a.successiveRetryCount=0;var f=function(){return a.successiveRetryCount>=b.hosts.length?void(b._isUndefined(c)||(a.successiveRetryCount=0,c(!1,{message:"Cannot connect the Algolia's Search API. Please send an email to support@algolia.com to report the issue."}))):(a.callback=function(g,h,i,j){h||b._isUndefined(j)||window.console&&console.log("Error: "+j.message),h&&!b._isUndefined(a.cache)&&(d[e]=j),!h&&g?(b.currentHostIndex=++b.currentHostIndex%b.hosts.length,a.successiveRetryCount+=1,f()):(a.successiveRetryCount=0,b._isUndefined(c)||c(h,j))},a.hostname=b.hosts[b.currentHostIndex],void b._jsonRequestByHost(a))};f()},_jsonRequestByHost:function(a){var b=a.hostname+a.url;this.jsonp?this._makeJsonpRequestByHost(b,a):this._makeXmlHttpRequestByHost(b,a)},_makeJsonpRequestByHost:function(a,b){if("GET"!==b.method)return void b.callback(!0,!1,null,{message:"Method "+b.method+" "+a+" is not supported by JSONP."});this.jsonpCounter=this.jsonpCounter||0,this.jsonpCounter+=1;var c=document.getElementsByTagName("head")[0],d=document.createElement("script"),e="algoliaJSONP_"+this.jsonpCounter,f=!1,g=null;window[e]=function(a){b.callback(!1,!0,null,a);try{delete window[e]}catch(c){window[e]=void 0}},d.type="text/javascript",d.src=a+"?callback="+e+"&X-Algolia-Application-Id="+this.applicationID+"&X-Algolia-API-Key="+this.apiKey,this.tagFilters&&(d.src+="&X-Algolia-TagFilters="+encodeURIComponent(this.tagFilters)),this.userToken&&(d.src+="&X-Algolia-UserToken="+encodeURIComponent(this.userToken));for(var h=0;h<this.extraHeaders.length;++h)d.src+="&"+this.extraHeaders[h].key+"="+this.extraHeaders[h].value;b.body&&b.body.params&&(d.src+="&"+b.body.params),g=setTimeout(function(){d.onload=d.onreadystatechange=d.onerror=null,window[e]=function(){try{delete window[e]}catch(a){window[e]=void 0}},b.callback(!0,!1,null,{message:"Timeout - Failed to load JSONP script."}),c.removeChild(d),clearTimeout(g),g=null},this.requestTimeoutInMs),d.onload=d.onreadystatechange=function(){if(clearTimeout(g),g=null,!(f||this.readyState&&"loaded"!=this.readyState&&"complete"!=this.readyState)){if(f=!0,"undefined"==typeof window[e+"_loaded"]){b.callback(!0,!1,null,{message:"Failed to load JSONP script."});try{delete window[e]}catch(a){window[e]=void 0}}else try{delete window[e+"_loaded"]}catch(a){window[e+"_loaded"]=void 0}d.onload=d.onreadystatechange=null,c.removeChild(d)}},d.onerror=function(){clearTimeout(g),g=null,b.callback(!0,!1,null,{message:"Failed to load JSONP script."}),c.removeChild(d);try{delete window[e]}catch(a){window[e]=void 0}},c.appendChild(d)},_makeXmlHttpRequestByHost:function(a,b){var c=this,d=window.XMLHttpRequest?new XMLHttpRequest:{},e=null,f=null;this._isUndefined(b.body)||(e=JSON.stringify(b.body)),a+=(-1===a.indexOf("?")?"?":"&")+"X-Algolia-API-Key="+this.apiKey,a+="&X-Algolia-Application-Id="+this.applicationID,this.userToken&&(a+="&X-Algolia-UserToken="+encodeURIComponent(this.userToken)),this.tagFilters&&(a+="&X-Algolia-TagFilters="+encodeURIComponent(this.tagFilters));for(var g=0;g<this.extraHeaders.length;++g)a+="&"+this.extraHeaders[g].key+"="+this.extraHeaders[g].value;if("withCredentials"in d)d.open(b.method,a,!0),d.timeout=this.requestTimeoutInMs*(b.successiveRetryCount+1),null!==e&&d.setRequestHeader("Content-type","application/x-www-form-urlencoded");else{if("undefined"==typeof XDomainRequest)return void b.callback(!1,!1,null,{message:"CORS not supported"});d=new XDomainRequest,d.open(b.method,a)}f=setTimeout(function(){return d.abort(),d.aborted===!0?void stopLoadAnimation():(b.callback(!0,!1,null,{message:"Timeout - Could not connect to endpoint "+a}),clearTimeout(f),void(f=null))},this.requestTimeoutInMs*(b.successiveRetryCount+1)),d.onload=function(a){if(clearTimeout(f),f=null,c._isUndefined(a)||null===a.target)b.callback(!1,!0,a,JSON.parse(d.responseText));else{var e=0===a.target.status||503===a.target.status,g=!1,h=null;"undefined"!=typeof XDomainRequest?(h=a.target.responseText,g=h&&h.length>0):(h=a.target.response,g=200===a.target.status||201===a.target.status),b.callback(e,g,a.target,h?JSON.parse(h):null)}},d.ontimeout=function(){},d.onerror=function(a){clearTimeout(f),f=null,b.callback(!0,!1,null,{message:"Could not connect to host",error:a})},d.send(e)},_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,tagFilters:null,userToken:null,hosts:[],cache:{},extraHeaders:[]},AlgoliaSearch.prototype.Index.prototype={clearCache:function(){this.cache={}},addObject:function(a,b,c){var d=this;this.as._jsonRequest(this.as._isUndefined(c)?{method:"POST",url:"/1/indexes/"+encodeURIComponent(d.indexName),body:a,callback:b}:{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]}if(null===this.as.jsonp)this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(d.indexName)+"/"+encodeURIComponent(a)+e,callback:b});else{var g={params:e};this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(d.indexName)+"/"+encodeURIComponent(a),callback:b,body:g})}},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 void b(!1,{message:"empty objectID"});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;this.as._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){var c={params:a};if(null===this.as.jsonp){var d=this;this.as._jsonRequest({cache:this.cache,method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/query",body:c,callback:function(c,e){c?(d.as.jsonp=!1,b&&b(c,e)):(d.as.jsonp=!0,d._search(a,b))}})}else this.as._jsonRequest(this.as.jsonp?{cache:this.cache,method:"GET",url:"/1/indexes/"+encodeURIComponent(this.indexName),body:c,callback:b}:{cache:this.cache,method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/query",body:c,callback:b})},as:null,indexName:null,cache:{},typeAheadArgs:null,typeAheadValueOption:null,emptyConstructor:function(){}},function(){var a=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(b,c,d){var e={facets:[],disjunctiveFacets:[],hitsPerPage:20,defaultFacetFilters:[]};this.init(b,c,a({},e,d))},AlgoliaSearchHelper.prototype={init:function(a,b,c){this.client=a,this.index=b,this.options=c,this.page=0,this.refinements={},this.disjunctiveRefinements={},this.extraQueries=[]},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()},clearRefinements:function(){this.disjunctiveRefinements={},this.refinements={}},addDisjunctiveRefine:function(a,b){this.disjunctiveRefinements=this.disjunctiveRefinements||{},this.disjunctiveRefinements[a]=this.disjunctiveRefinements[a]||{},this.disjunctiveRefinements[a][b]=!0},removeDisjunctiveRefine:function(a,b){this.disjunctiveRefinements=this.disjunctiveRefinements||{},this.disjunctiveRefinements[a]=this.disjunctiveRefinements[a]||{};try{delete this.disjunctiveRefinements[a][b]}catch(c){this.disjunctiveRefinements[a][b]=void 0}},addRefine:function(a,b){var c=a+":"+b;this.refinements=this.refinements||{},this.refinements[c]=!0},removeRefine:function(a,b){var c=a+":"+b;this.refinements=this.refinements||{},this.refinements[c]=!1},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._gotoPage(a)},setPage:function(a){this.page=a},setIndex:function(a){this.index=a},getIndex:function(){return this.index},clearExtraQueries:function(){this.extraQueries=[]},addExtraQuery:function(a,b,c){this.extraQueries.push({index:a,query:b,params:c||{}})},_gotoPage:function(a){this.page=a,this._search()},_search:function(){this.client.startQueriesBatch(),this.client.addQueryInBatch(this.index,this.q,this._getHitsSearchParams());for(var a=[],b={},c=0;c<this.options.disjunctiveFacets.length;++c){var d=this.options.disjunctiveFacets[c];this._hasDisjunctiveRefinements(d)?a.push(d):b[d]=!0}for(var c=0;c<a.length;++c)this.client.addQueryInBatch(this.index,this.q,this._getDisjunctiveFacetSearchParams(a[c]));for(var c=0;c<this.extraQueries.length;++c)this.client.addQueryInBatch(this.extraQueries[c].index,this.extraQueries[c].query,this.extraQueries[c].params);var e=this;this.client.sendQueriesBatch(function(c,d){if(!c)return void e.searchCallback(!1,d);var f=d.results[0];f.disjunctiveFacets=f.disjunctiveFacets||{},f.facetStats=f.facetStats||{};for(var g in b)if(f.facets[g]&&!f.disjunctiveFacets[g]){f.disjunctiveFacets[g]=f.facets[g];try{delete f.facets[g]}catch(h){f.facets[g]=void 0}}for(var i=0;i<a.length;++i){for(var g in d.results[i+1].facets)if(f.disjunctiveFacets[g]=d.results[i+1].facets[g],e.disjunctiveRefinements[g])for(var j in e.disjunctiveRefinements[g])!f.disjunctiveFacets[g][j]&&e.disjunctiveRefinements[g][j]&&(f.disjunctiveFacets[g][j]=0);for(var k in d.results[i+1].facets_stats)f.facetStats[k]=d.results[i+1].facets_stats[k]}if(0===e.extraQueries.length)e.searchCallback(!0,f);else{for(var l={results:[f]},i=0;i<e.extraQueries.length;++i)l.results.push(d.results[1+a.length+i]);e.searchCallback(!0,l)}})},_getHitsSearchParams:function(){for(var b=[],c=0;c<this.options.facets.length;++c)b.push(this.options.facets[c]);for(var c=0;c<this.options.disjunctiveFacets.length;++c){var d=this.options.disjunctiveFacets[c];this._hasDisjunctiveRefinements(d)||b.push(d)}return a({},{hitsPerPage:this.options.hitsPerPage,page:this.page,facets:b,facetFilters:this._getFacetFilters()},this.searchParams)},_getDisjunctiveFacetSearchParams:function(b){return a({},this.searchParams,{hitsPerPage:1,page:0,attributesToRetrieve:[],attributesToHighlight:[],attributesToSnippet:[],facets:b,facetFilters:this._getFacetFilters(b)})},_hasDisjunctiveRefinements:function(a){for(var b in this.disjunctiveRefinements[a])if(this.disjunctiveRefinements[a][b])return!0;return!1},_getFacetFilters:function(a){var b=[];if(this.options.defaultFacetFilters)for(var c=0;c<this.options.defaultFacetFilters.length;++c)b.push(this.options.defaultFacetFilters[c]);for(var d in this.refinements)this.refinements[d]&&b.push(d);for(var e in this.disjunctiveRefinements)if(e!=a){var f=[];for(var g in this.disjunctiveRefinements[e])this.disjunctiveRefinements[e][g]&&f.push(e+":"+g);f.length>0&&b.push(f)}return b}}}(),function(){window.AlgoliaPlaces=function(a,b){this.init(a,b)},AlgoliaPlaces.prototype={init:function(a,b){this.client=new AlgoliaSearch(a,b,"http",!0,["places-1.algolia.io","places-2.algolia.io","places-3.algolia.io"]),this.cache={}},search:function(a,b,c){var d="query="+encodeURIComponent(a);this.client._isUndefined(c)||null==c||(d=this.client._getSearchParams(c,d));var e={params:d,apiKey:this.client.apiKey,appID:this.client.applicationID};this.client._jsonRequest({cache:this.cache,method:"POST",url:"/1/places/query",body:e,callback:b,removeCustomHTTPHeaders:!0})}}}(),"object"!=typeof JSON&&(JSON={}),function(){"use strict";function f(a){return 10>a?"0"+a:a}function quote(a){return escapable.lastIndex=0,escapable.test(a)?'"'+a.replace(escapable,function(a){var b=meta[a];return"string"==typeof b?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function str(a,b){var c,d,e,f,g,h=gap,i=b[a];switch(i&&"object"==typeof i&&"function"==typeof i.toJSON&&(i=i.toJSON(a)),"function"==typeof rep&&(i=rep.call(b,a,i)),typeof i){case"string":return quote(i);case"number":return isFinite(i)?String(i):"null";case"boolean":case"null":return String(i);case"object":if(!i)return"null";if(gap+=indent,g=[],"[object Array]"===Object.prototype.toString.apply(i)){for(f=i.length,c=0;f>c;c+=1)g[c]=str(c,i)||"null";return e=0===g.length?"[]":gap?"[\n"+gap+g.join(",\n"+gap)+"\n"+h+"]":"["+g.join(",")+"]",gap=h,e}if(rep&&"object"==typeof rep)for(f=rep.length,c=0;f>c;c+=1)"string"==typeof rep[c]&&(d=rep[c],e=str(d,i),e&&g.push(quote(d)+(gap?": ":":")+e));else for(d in i)Object.prototype.hasOwnProperty.call(i,d)&&(e=str(d,i),e&&g.push(quote(d)+(gap?": ":":")+e));return e=0===g.length?"{}":gap?"{\n"+gap+g.join(",\n"+gap)+"\n"+h+"}":"{"+g.join(",")+"}",gap=h,e}}"function"!=typeof Date.prototype.toJSON&&(Date.prototype.toJSON=function(){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null},String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(){return this.valueOf()});var cx,escapable,gap,indent,meta,rep;"function"!=typeof JSON.stringify&&(escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,meta={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},JSON.stringify=function(a,b,c){var d;if(gap="",indent="","number"==typeof c)for(d=0;c>d;d+=1)indent+=" ";else"string"==typeof c&&(indent=c);if(rep=b,b&&"function"!=typeof b&&("object"!=typeof b||"number"!=typeof b.length))throw new Error("JSON.stringify");return str("",{"":a})}),"function"!=typeof JSON.parse&&(cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,JSON.parse=function(text,reviver){function walk(a,b){var c,d,e=a[b];if(e&&"object"==typeof e)for(c in e)Object.prototype.hasOwnProperty.call(e,c)&&(d=walk(e,c),void 0!==d?e[c]=d:delete e[c]);return reviver.call(a,b,e)}var j;if(text=String(text),cx.lastIndex=0,cx.test(text)&&(text=text.replace(cx,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})),/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,"")))return j=eval("("+text+")"),"function"==typeof reviver?walk({"":j},""):j;throw new SyntaxError("JSON.parse")})}();
|
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){var f=a._highlightResult||a;if(-1===c.indexOf("."))return c in f?d(f[c],b):[];for(var g=c.split("."),h=f,i=0;i<g.length;++i){if("[object Array]"===Object.prototype.toString.call(h)){for(var j=[],k=0;k<h.length;++k)j=j.concat(e(h[k],b,g.slice(i).join(".")));return j}if(!(g[i]in h))return[];h=h[g[i]]}return d(h,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.9.2",AlgoliaSearch=function(a,b,c,d,e){var f=this;this.applicationID=a,this.apiKey=b,this.dsn=!0,this.dsnHost=null,this.hosts=[],this.currentHostIndex=0,this.requestTimeoutInMs=2e3,this.extraHeaders=[],this.jsonp=null,this.options={},this.cache={};var g,h="net";if("string"==typeof c)g=c;else{var i=c||{};this.options=i,this._isUndefined(i.method)||(g=i.method),this._isUndefined(i.tld)||(h=i.tld),this._isUndefined(i.dsn)||(this.dsn=i.dsn),this._isUndefined(i.hosts)||(e=i.hosts),this._isUndefined(i.dsnHost)||(this.dsnHost=i.dsnHost),this._isUndefined(i.requestTimeoutInMs)||(this.requestTimeoutInMs=+i.requestTimeoutInMs),this._isUndefined(i.jsonp)||(this.jsonp=i.jsonp)}this._isUndefined(e)&&(e=[this.applicationID+"-1.algolia."+h,this.applicationID+"-2.algolia."+h,this.applicationID+"-3.algolia."+h]),this.host_protocol="http://",this._isUndefined(g)||null===g?this.host_protocol=("https:"==document.location.protocol?"https":"http")+"://":("https"===g||"HTTPS"===g)&&(this.host_protocol="https://");for(var j=0;j<e.length;++j)Math.random()>.5&&this.hosts.reverse(),this.hosts.push(this.host_protocol+e[j]);Math.random()>.5&&this.hosts.reverse(),(this.dsn||null!=this.dsnHost)&&this.hosts.unshift(this.dsnHost?this.host_protocol+this.dsnHost:this.host_protocol+this.applicationID+"-dsn.algolia."+h),this.options.angular&&this.options.angular.$injector.invoke(["$http","$q",function(a,b){f.options.angular.$q=b,f.options.angular.$http=a}])};AlgoliaSearch.prototype={deleteIndex:function(a,b){return this._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(a),callback:b})},moveIndex:function(a,b,c){var d={operation:"move",destination:b};return 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};return this._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(a)+"/operation",body:d,callback:c})},getLogs:function(a,b,c){return 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,b){var c="undefined"!=typeof b?"?page="+b:"";return this._jsonRequest({method:"GET",url:"/1/indexes"+c,callback:a})},initIndex:function(a){return new this.Index(this,a)},listUserKeys:function(a){return this._jsonRequest({method:"GET",url:"/1/keys",callback:a})},getUserKeyACL:function(a,b){return this._jsonRequest({method:"GET",url:"/1/keys/"+a,callback:b})},deleteUserKey:function(a,b){return this._jsonRequest({method:"DELETE",url:"/1/keys/"+a,callback:b})},addUserKey:function(a,b){var c={};return 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={};return 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.tagFilters=a},setUserToken:function(a){this.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:[]},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))return this._sendQueriesBatch(d,a);var f=window.setTimeout(function(){c._sendQueriesBatch(d,a)},b);c.onDelayTrigger=f},setRequestTimeout:function(a){a&&(this.requestTimeoutInMs=parseInt(a,10))},Index:function(a,b){this.indexName=b,this.as=a,this.typeAheadArgs=null,this.typeAheadValueOption=null,this.cache={}},setExtraHeader:function(a,b){this.extraHeaders.push({key:a,value:b})},_sendQueriesBatch:function(a,b){if(null===this.jsonp){var c=this;return this._jsonRequest({cache:this.cache,method:"POST",url:"/1/indexes/*/queries",body:a,callback:function(d,e){d?(c.jsonp=!1,b&&b(d,e)):(c.jsonp=!0,c._sendQueriesBatch(a,b))}})}if(this.jsonp){for(var d="",e=0;e<a.requests.length;++e){var f="/1/indexes/"+encodeURIComponent(a.requests[e].indexName)+"?"+a.requests[e].params;d+=e+"="+encodeURIComponent(f)+"&"}var g={params:d};return this._jsonRequest({cache:this.cache,method:"GET",url:"/1/indexes/*",body:g,callback:b})}return 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,f=null;if(this.options.jQuery?(f=this.options.jQuery.$.Deferred(),f.promise=f.promise()):this.options.angular&&(f=this.options.angular.$q.defer()),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&&setTimeout(function(){c(!0,d[e])},1),f&&f.resolve(d[e]),f&&f.promise;a.successiveRetryCount=0;var g=function(){if(a.successiveRetryCount>=b.hosts.length){var h={message:"Cannot connect the Algolia's Search API. Please send an email to support@algolia.com to report the issue."};return!b._isUndefined(c)&&c&&(a.successiveRetryCount=0,c(!1,h)),void(f&&f.reject(h))}a.callback=function(h,i,j,k){i&&!b._isUndefined(a.cache)&&(d[e]=k),!i&&h?(b.currentHostIndex=++b.currentHostIndex%b.hosts.length,a.successiveRetryCount+=1,g()):(a.successiveRetryCount=0,f&&(i?f.resolve(k):f.reject(k)),!b._isUndefined(c)&&c&&c(i,k))},a.hostname=b.hosts[b.currentHostIndex],b._jsonRequestByHost(a)};return g(),f&&f.promise},_jsonRequestByHost:function(a){var b=a.hostname+a.url;this.jsonp?this._makeJsonpRequestByHost(b,a):this.options.jQuery?this._makejQueryRequestByHost(b,a):this.options.angular?this._makeAngularRequestByHost(b,a):this._makeXmlHttpRequestByHost(b,a)},_makeAngularRequestByHost:function(a,b){var c=null;this._isUndefined(b.body)||(c=JSON.stringify(b.body)),a+=(-1===a.indexOf("?")?"?":"&")+"X-Algolia-API-Key="+this.apiKey,a+="&X-Algolia-Application-Id="+this.applicationID,this.userToken&&(a+="&X-Algolia-UserToken="+encodeURIComponent(this.userToken)),this.tagFilters&&(a+="&X-Algolia-TagFilters="+encodeURIComponent(this.tagFilters));for(var d=0;d<this.extraHeaders.length;++d)a+="&"+this.extraHeaders[d].key+"="+this.extraHeaders[d].value;this.options.angular.$http({url:a,method:b.method,data:c,cache:!1,timeout:this.requestTimeoutInMs*(b.successiveRetryCount+1)}).then(function(a){b.callback(!1,!0,null,a.data)},function(a){0===a.status?b.callback(!0,!1,null,a.data):400==a.status||403===a.status||404===a.status?b.callback(!1,!1,null,a.data):b.callback(!0,!1,null,a.data)})},_makejQueryRequestByHost:function(a,b){var c=null;this._isUndefined(b.body)||(c=JSON.stringify(b.body)),a+=(-1===a.indexOf("?")?"?":"&")+"X-Algolia-API-Key="+this.apiKey,a+="&X-Algolia-Application-Id="+this.applicationID,this.userToken&&(a+="&X-Algolia-UserToken="+encodeURIComponent(this.userToken)),this.tagFilters&&(a+="&X-Algolia-TagFilters="+encodeURIComponent(this.tagFilters));for(var d=0;d<this.extraHeaders.length;++d)a+="&"+this.extraHeaders[d].key+"="+this.extraHeaders[d].value;this.options.jQuery.$.ajax(a,{type:b.method,timeout:this.requestTimeoutInMs*(b.successiveRetryCount+1),dataType:"json",data:c,error:function(c,d,e){"timeout"===d?b.callback(!0,!1,null,{message:"Timeout - Could not connect to endpoint "+a}):400===c.status||403===c.status||404===c.status?b.callback(!1,!1,null,c.responseJSON):b.callback(!0,!1,null,{message:e})},success:function(a){b.callback(!1,!0,null,a)}})},_makeJsonpRequestByHost:function(a,b){if("GET"!==b.method)return void b.callback(!0,!1,null,{message:"Method "+b.method+" "+a+" is not supported by JSONP."});this.jsonpCounter=this.jsonpCounter||0,this.jsonpCounter+=1;var c=document.getElementsByTagName("head")[0],d=document.createElement("script"),e="algoliaJSONP_"+this.jsonpCounter,f=!1,g=null;window[e]=function(a){b.callback(!1,!0,null,a);try{delete window[e]}catch(c){window[e]=void 0}},d.type="text/javascript",d.src=a+"?callback="+e+"&X-Algolia-Application-Id="+this.applicationID+"&X-Algolia-API-Key="+this.apiKey,this.tagFilters&&(d.src+="&X-Algolia-TagFilters="+encodeURIComponent(this.tagFilters)),this.userToken&&(d.src+="&X-Algolia-UserToken="+encodeURIComponent(this.userToken));for(var h=0;h<this.extraHeaders.length;++h)d.src+="&"+this.extraHeaders[h].key+"="+this.extraHeaders[h].value;b.body&&b.body.params&&(d.src+="&"+b.body.params),g=setTimeout(function(){d.onload=d.onreadystatechange=d.onerror=null,window[e]=function(){try{delete window[e]}catch(a){window[e]=void 0}},b.callback(!0,!1,null,{message:"Timeout - Failed to load JSONP script."}),c.removeChild(d),clearTimeout(g),g=null},this.requestTimeoutInMs),d.onload=d.onreadystatechange=function(){if(clearTimeout(g),g=null,!(f||this.readyState&&"loaded"!=this.readyState&&"complete"!=this.readyState)){if(f=!0,"undefined"==typeof window[e+"_loaded"]){b.callback(!0,!1,null,{message:"Failed to load JSONP script."});try{delete window[e]}catch(a){window[e]=void 0}}else try{delete window[e+"_loaded"]}catch(a){window[e+"_loaded"]=void 0}d.onload=d.onreadystatechange=null,c.removeChild(d)}},d.onerror=function(){clearTimeout(g),g=null,b.callback(!0,!1,null,{message:"Failed to load JSONP script."}),c.removeChild(d);try{delete window[e]}catch(a){window[e]=void 0}},c.appendChild(d)},_makeXmlHttpRequestByHost:function(a,b){var c=this,d=window.XMLHttpRequest?new XMLHttpRequest:{},e=null,f=null;this._isUndefined(b.body)||(e=JSON.stringify(b.body)),a+=(-1===a.indexOf("?")?"?":"&")+"X-Algolia-API-Key="+this.apiKey,a+="&X-Algolia-Application-Id="+this.applicationID,this.userToken&&(a+="&X-Algolia-UserToken="+encodeURIComponent(this.userToken)),this.tagFilters&&(a+="&X-Algolia-TagFilters="+encodeURIComponent(this.tagFilters));for(var g=0;g<this.extraHeaders.length;++g)a+="&"+this.extraHeaders[g].key+"="+this.extraHeaders[g].value;if("withCredentials"in d)d.open(b.method,a,!0),d.timeout=this.requestTimeoutInMs*(b.successiveRetryCount+1),null!==e&&d.setRequestHeader("Content-type","application/x-www-form-urlencoded");else{if("undefined"==typeof XDomainRequest)return void b.callback(!1,!1,null,{message:"CORS not supported"});d=new XDomainRequest,d.open(b.method,a)}f=setTimeout(function(){return d.abort(),d.aborted===!0?void stopLoadAnimation():(b.callback(!0,!1,null,{message:"Timeout - Could not connect to endpoint "+a}),clearTimeout(f),void(f=null))},this.requestTimeoutInMs*(b.successiveRetryCount+1)),d.onload=function(a){if(clearTimeout(f),f=null,c._isUndefined(a)||null===a.target)b.callback(!1,!0,a,JSON.parse(d.responseText));else{var e=!1,g=null;"undefined"!=typeof XDomainRequest?(g=a.target.responseText,e=g&&g.length>0):(g=a.target.response,e=200===a.target.status||201===a.target.status);var h=!e&&400!==a.target.status&&403!==a.target.status&&404!==a.target.status;b.callback(h,e,a.target,g?JSON.parse(g):null)}},d.ontimeout=function(){},d.onerror=function(a){clearTimeout(f),f=null,b.callback(!0,!1,null,{message:"Could not connect to host",error:a})},d.send(e)},_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,tagFilters:null,userToken:null,hosts:[],extraHeaders:[]},AlgoliaSearch.prototype.Index.prototype={clearCache:function(){this.cache={}},addObject:function(a,b,c){var d=this;return this.as._jsonRequest(this.as._isUndefined(c)?{method:"POST",url:"/1/indexes/"+encodeURIComponent(d.indexName),body:a,callback:b}:{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)}return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/batch",body:d,callback:b})},getObject:function(a,b,c){"[object Array]"!==Object.prototype.toString.call(b)||c||(c=b,b=null);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]}if(null===this.as.jsonp)return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(d.indexName)+"/"+encodeURIComponent(a)+e,callback:b});var g={params:e};return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(d.indexName)+"/"+encodeURIComponent(a),callback:b,body:g})},partialUpdateObject:function(a,b){var c=this;return 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)}return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/batch",body:d,callback:b})},saveObject:function(a,b){var c=this;return 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)}return 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 void b(!1,{message:"empty objectID"});var c=this;return this.as._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/"+encodeURIComponent(a),callback:b})},search:function(a,b,c,d){(void 0===a||null===a)&&(a=""),"function"==typeof a&&(b=a,a=""),"object"!=typeof b||!this.as._isUndefined(c)&&c||(c=b,b=null);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))return this._search(f,b);var g=window.setTimeout(function(){e._search(f,b)},d);e.onDelayTrigger=g},browse:function(a,b,c){+b>0&&(this.as._isUndefined(c)||!c)&&(c=b,b=null);var d=this,e="?page="+a;return this.as._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;return 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;return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(b.indexName)+"/clear",callback:a})},getSettings:function(a){var b=this;return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(b.indexName)+"/settings",callback:a})},setSettings:function(a,b){var c=this;return this.as._jsonRequest({method:"PUT",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/settings",body:a,callback:b})},listUserKeys:function(a){var b=this;return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(b.indexName)+"/keys",callback:a})},getUserKeyACL:function(a,b){var c=this;return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/keys/"+a,callback:b})},deleteUserKey:function(a,b){var c=this;return this.as._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/keys/"+a,callback:b})},addUserKey:function(a,b){var c=this,d={};return 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={};return 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){var c={params:a};if(null===this.as.jsonp){var d=this;return this.as._jsonRequest({cache:this.cache,method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/query",body:c,callback:function(c,e){c?(d.as.jsonp=!1,b&&b(c,e)):(d.as.jsonp=!0,d._search(a,b))}})}return this.as._jsonRequest(this.as.jsonp?{cache:this.cache,method:"GET",url:"/1/indexes/"+encodeURIComponent(this.indexName),body:c,callback:b}:{cache:this.cache,method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/query",body:c,callback:b})},as:null,indexName:null,typeAheadArgs:null,typeAheadValueOption:null},function(){var a=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(b,c,d){var e={facets:[],disjunctiveFacets:[],hitsPerPage:20,defaultFacetFilters:[]};this.init(b,c,a({},e,d))},AlgoliaSearchHelper.prototype={init:function(a,b,c){this.client=a,this.index=b,this.options=c,this.page=0,this.refinements={},this.excludes={},this.disjunctiveRefinements={},this.extraQueries=[]},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()},clearRefinements:function(){this.disjunctiveRefinements={},this.refinements={}},addDisjunctiveRefine:function(a,b){this.disjunctiveRefinements=this.disjunctiveRefinements||{},this.disjunctiveRefinements[a]=this.disjunctiveRefinements[a]||{},this.disjunctiveRefinements[a][b]=!0},removeDisjunctiveRefine:function(a,b){this.disjunctiveRefinements=this.disjunctiveRefinements||{},this.disjunctiveRefinements[a]=this.disjunctiveRefinements[a]||{};try{delete this.disjunctiveRefinements[a][b]}catch(c){this.disjunctiveRefinements[a][b]=void 0}},addRefine:function(a,b){var c=a+":"+b;this.refinements=this.refinements||{},this.refinements[c]=!0},removeRefine:function(a,b){var c=a+":"+b;this.refinements=this.refinements||{},this.refinements[c]=!1},addExclude:function(a,b){var c=a+":-"+b;this.excludes=this.excludes||{},this.excludes[c]=!0},removeExclude:function(a,b){var c=a+":-"+b;this.excludes=this.excludes||{},this.excludes[c]=!1},toggleExclude: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.excludes[d]=!this.excludes[d],this.page=0,this._search(),!0}return!1},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},isExcluded:function(a,b){var c=a+":-"+b;return this.excludes[c]?!0:!1},nextPage:function(){this._gotoPage(this.page+1)},previousPage:function(){this.page>0&&this._gotoPage(this.page-1)},gotoPage:function(a){this._gotoPage(a)},setPage:function(a){this.page=a},setIndex:function(a){this.index=a},getIndex:function(){return this.index},clearExtraQueries:function(){this.extraQueries=[]},addExtraQuery:function(a,b,c){this.extraQueries.push({index:a,query:b,params:c||{}})},_gotoPage:function(a){this.page=a,this._search()},_search:function(){this.client.startQueriesBatch(),this.client.addQueryInBatch(this.index,this.q,this._getHitsSearchParams());var a=[],b={},c=0;for(c=0;c<this.options.disjunctiveFacets.length;++c){var d=this.options.disjunctiveFacets[c];this._hasDisjunctiveRefinements(d)?a.push(d):b[d]=!0}for(c=0;c<a.length;++c)this.client.addQueryInBatch(this.index,this.q,this._getDisjunctiveFacetSearchParams(a[c]));for(c=0;c<this.extraQueries.length;++c)this.client.addQueryInBatch(this.extraQueries[c].index,this.extraQueries[c].query,this.extraQueries[c].params);var e=this;this.client.sendQueriesBatch(function(d,f){if(!d)return void e.searchCallback(!1,f);var g=f.results[0];g.disjunctiveFacets=g.disjunctiveFacets||{},g.facetStats=g.facetStats||{};for(var h in b)if(g.facets[h]&&!g.disjunctiveFacets[h]){g.disjunctiveFacets[h]=g.facets[h];try{delete g.facets[h]}catch(i){g.facets[h]=void 0}}for(c=0;c<a.length;++c){for(var j in f.results[c+1].facets)if(g.disjunctiveFacets[j]=f.results[c+1].facets[j],e.disjunctiveRefinements[j])for(var k in e.disjunctiveRefinements[j])!g.disjunctiveFacets[j][k]&&e.disjunctiveRefinements[j][k]&&(g.disjunctiveFacets[j][k]=0);for(var l in f.results[c+1].facets_stats)g.facetStats[l]=f.results[c+1].facets_stats[l]}for(var m in e.excludes)if(e.excludes[m]){var i=m.indexOf(":-"),h=m.slice(0,i),k=m.slice(i+2);g.facets[h]=g.facets[h]||{},g.facets[h][k]||(g.facets[h][k]=0)}if(0===e.extraQueries.length)e.searchCallback(!0,g);else{var n={results:[g]};for(c=0;c<e.extraQueries.length;++c)n.results.push(f.results[1+a.length+c]);e.searchCallback(!0,n)}})},_getHitsSearchParams:function(){var b=[],c=0;for(c=0;c<this.options.facets.length;++c)b.push(this.options.facets[c]);for(c=0;c<this.options.disjunctiveFacets.length;++c){var d=this.options.disjunctiveFacets[c];this._hasDisjunctiveRefinements(d)||b.push(d)}return a({},{hitsPerPage:this.options.hitsPerPage,page:this.page,facets:b,facetFilters:this._getFacetFilters()},this.searchParams)},_getDisjunctiveFacetSearchParams:function(b){return a({},this.searchParams,{hitsPerPage:1,page:0,attributesToRetrieve:[],attributesToHighlight:[],attributesToSnippet:[],facets:b,facetFilters:this._getFacetFilters(b)})},_hasDisjunctiveRefinements:function(a){for(var b in this.disjunctiveRefinements[a])if(this.disjunctiveRefinements[a][b])return!0;return!1},_getFacetFilters:function(a){var b=[];if(this.options.defaultFacetFilters)for(var c=0;c<this.options.defaultFacetFilters.length;++c)b.push(this.options.defaultFacetFilters[c]);for(var d in this.refinements)this.refinements[d]&&b.push(d);for(var d in this.excludes)this.excludes[d]&&b.push(d);for(var e in this.disjunctiveRefinements)if(e!=a){var f=[];for(var g in this.disjunctiveRefinements[e])this.disjunctiveRefinements[e][g]&&f.push(e+":"+g);f.length>0&&b.push(f)}return b}}}(),function(){window.AlgoliaPlaces=function(a,b){this.init(a,b)},AlgoliaPlaces.prototype={init:function(a,b){this.client=new AlgoliaSearch(a,b,"http",!0,["places-1.algolia.io","places-2.algolia.io","places-3.algolia.io"]),this.cache={}},search:function(a,b,c){var d="query="+encodeURIComponent(a);this.client._isUndefined(c)||null==c||(d=this.client._getSearchParams(c,d));var e={params:d,apiKey:this.client.apiKey,appID:this.client.applicationID};this.client._jsonRequest({cache:this.cache,method:"POST",url:"/1/places/query",body:e,callback:b,removeCustomHTTPHeaders:!0})}}}(),"object"!=typeof JSON&&(JSON={}),function(){"use strict";function f(a){return 10>a?"0"+a:a}function quote(a){return escapable.lastIndex=0,escapable.test(a)?'"'+a.replace(escapable,function(a){var b=meta[a];return"string"==typeof b?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function str(a,b){var c,d,e,f,g,h=gap,i=b[a];switch(i&&"object"==typeof i&&"function"==typeof i.toJSON&&(i=i.toJSON(a)),"function"==typeof rep&&(i=rep.call(b,a,i)),typeof i){case"string":return quote(i);case"number":return isFinite(i)?String(i):"null";case"boolean":case"null":return String(i);case"object":if(!i)return"null";if(gap+=indent,g=[],"[object Array]"===Object.prototype.toString.apply(i)){for(f=i.length,c=0;f>c;c+=1)g[c]=str(c,i)||"null";return e=0===g.length?"[]":gap?"[\n"+gap+g.join(",\n"+gap)+"\n"+h+"]":"["+g.join(",")+"]",gap=h,e}if(rep&&"object"==typeof rep)for(f=rep.length,c=0;f>c;c+=1)"string"==typeof rep[c]&&(d=rep[c],e=str(d,i),e&&g.push(quote(d)+(gap?": ":":")+e));else for(d in i)Object.prototype.hasOwnProperty.call(i,d)&&(e=str(d,i),e&&g.push(quote(d)+(gap?": ":":")+e));return e=0===g.length?"{}":gap?"{\n"+gap+g.join(",\n"+gap)+"\n"+h+"}":"{"+g.join(",")+"}",gap=h,e}}"function"!=typeof Date.prototype.toJSON&&(Date.prototype.toJSON=function(){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null},String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(){return this.valueOf()});var cx,escapable,gap,indent,meta,rep;"function"!=typeof JSON.stringify&&(escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,meta={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},JSON.stringify=function(a,b,c){var d;if(gap="",indent="","number"==typeof c)for(d=0;c>d;d+=1)indent+=" ";else"string"==typeof c&&(indent=c);if(rep=b,b&&"function"!=typeof b&&("object"!=typeof b||"number"!=typeof b.length))throw new Error("JSON.stringify");return str("",{"":a})}),"function"!=typeof JSON.parse&&(cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,JSON.parse=function(text,reviver){function walk(a,b){var c,d,e=a[b];if(e&&"object"==typeof e)for(c in e)Object.prototype.hasOwnProperty.call(e,c)&&(d=walk(e,c),void 0!==d?e[c]=d:delete e[c]);return reviver.call(a,b,e)}var j;if(text=String(text),cx.lastIndex=0,cx.test(text)&&(text=text.replace(cx,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})),/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,"")))return j=eval("("+text+")"),"function"==typeof reviver?walk({"":j},""):j;throw new SyntaxError("JSON.parse")})}();
|
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.11.
|
4
|
+
version: 1.11.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Algolia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -164,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
164
|
version: '0'
|
165
165
|
requirements: []
|
166
166
|
rubyforge_project:
|
167
|
-
rubygems_version: 2.
|
167
|
+
rubygems_version: 2.4.5
|
168
168
|
signing_key:
|
169
169
|
specification_version: 4
|
170
170
|
summary: AlgoliaSearch integration to your favorite ORM
|