algoliasearch-rails 1.11.4 → 1.11.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32b3cc39ddb51e1ed05f6d42b0884ec31e45035b
4
- data.tar.gz: d805300078c543d140d4ceaa9f88bd0159b7bf32
3
+ metadata.gz: 6245c8a49433f26ba9c8547fc92d47e3284a642a
4
+ data.tar.gz: 11434652966ca83862e092c7afce9054f7fea1d9
5
5
  SHA512:
6
- metadata.gz: a7a62a8f7c79036c0a51ed2bb2416262331abac6245496bb6b7585c849be486976e10a8e69a80c23ddbeaa9481031cf56111b59d43fac4c06046ef023084e2b0
7
- data.tar.gz: 6703e4e84e65b8400476a0326a53df42d2744f811f495b9a49d01c81c2f54a78d263c74d3d7868ae56a6307dc85c809652c1d78c29ca52e4dc797fc3cd8d6592
6
+ metadata.gz: d2c3c09294f74f171f15b9685eb0f944c166a12c3d53c7f7f7de81982c45f39d97b78037ed9cea989285e6403c6afb3a7315aab67bb09cd06ae0a498e92fa157
7
+ data.tar.gz: 53297000b075c8a3d5e49b3f5fb4916c1cecfaec4abc7b600000bbe99f2d755f9c11519b754dbd171cd53cd59589014b51db948b8e8c2060fc358ded13d33e0e
data/ChangeLog CHANGED
@@ -1,5 +1,9 @@
1
1
  CHANGELOG
2
2
 
3
+ 2014-10-15 1.11.5
4
+
5
+ * Upgraded algoliasearch JavaScript client from 2.5.3 to 2.7.0
6
+
3
7
  2014-10-05 1.11.4
4
8
 
5
9
  * Do not compute the 'slaves' index settings on slaves (breaking the diff between current & configured version)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.11.4
1
+ 1.11.5
@@ -6,11 +6,11 @@
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "algoliasearch-rails"
9
- s.version = "1.11.4"
9
+ s.version = "1.11.5"
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-10-05"
13
+ s.date = "2014-10-15"
14
14
  s.description = "AlgoliaSearch integration to your favorite ORM"
15
15
  s.email = "contact@algolia.com"
16
16
  s.extra_rdoc_files = [
@@ -21,7 +21,7 @@
21
21
  * THE SOFTWARE.
22
22
  */
23
23
 
24
- var ALGOLIA_VERSION = '2.5.3';
24
+ var ALGOLIA_VERSION = '2.7.0';
25
25
 
26
26
  /*
27
27
  * Copyright (c) 2013 Algolia
@@ -50,40 +50,77 @@ var ALGOLIA_VERSION = '2.5.3';
50
50
  * Algolia Search library initialization
51
51
  * @param applicationID the application ID you have in your admin interface
52
52
  * @param apiKey a valid API key for the service
53
- * @param method specify if the protocol used is http or https (http by default to make the first search query faster).
54
- * You need to use https is you are doing something else than just search queries.
55
- * @param resolveDNS let you disable first empty query that is launch to warmup the service
56
- * @param hostsArray (optionnal) the list of hosts that you have received for the service
53
+ * @param methodOrOptions the hash of parameters for initialization. It can contains:
54
+ * - method (optional) specify if the protocol used is http or https (http by default to make the first search query faster).
55
+ * You need to use https is you are doing something else than just search queries.
56
+ * - hosts (optional) the list of hosts that you have received for the service
57
+ * - dsn (optional) set to true if your account has the Distributed Search Option
58
+ * - dsnHost (optional) override the automatic computation of dsn hostname
57
59
  */
58
- var AlgoliaSearch = function(applicationID, apiKey, method, resolveDNS, hostsArray) {
60
+ var AlgoliaSearch = function(applicationID, apiKey, methodOrOptions, resolveDNS, hosts) {
59
61
  var self = this;
60
62
  this.applicationID = applicationID;
61
63
  this.apiKey = apiKey;
64
+ this.dsn = false;
65
+ this.dsnHost = null;
66
+ this.hosts = [];
62
67
 
63
- if (this._isUndefined(hostsArray)) {
64
- hostsArray = [applicationID + '-1.algolia.io',
65
- applicationID + '-2.algolia.io',
66
- applicationID + '-3.algolia.io'];
68
+ var method;
69
+ if (typeof methodOrOptions === 'string') { // Old initialization
70
+ method = methodOrOptions;
71
+ } else {
72
+ // Take all option from the hash
73
+ var options = methodOrOptions;
74
+ if (!this._isUndefined(options.method)) {
75
+ method = options.method;
76
+ }
77
+ if (!this._isUndefined(options.dsn)) {
78
+ this.dsn = options.dsn;
79
+ }
80
+ if (!this._isUndefined(options.hosts)) {
81
+ hosts = options.hosts;
82
+ }
83
+ if (!this._isUndefined(options.dsnHost)) {
84
+ this.dsnHost = options.dsnHost;
85
+ }
86
+ }
87
+ // If hosts is undefined, initialize it with applicationID
88
+ if (this._isUndefined(hosts)) {
89
+ hosts = [
90
+ this.applicationID + '-1.algolia.io',
91
+ this.applicationID + '-2.algolia.io',
92
+ this.applicationID + '-3.algolia.io'
93
+ ];
94
+ }
95
+ // detect is we use http or https
96
+ this.host_protocol = 'http://';
97
+ if (this._isUndefined(method) || method === null) {
98
+ this.host_protocol = ('https:' == document.location.protocol ? 'https' : 'http') + '://';
99
+ } else if (method === 'https' || method === 'HTTPS') {
100
+ this.host_protocol = 'https://';
67
101
  }
68
- this.hosts = [];
69
102
  // Add hosts in random order
70
- for (var i = 0; i < hostsArray.length; ++i) {
103
+ for (var i = 0; i < hosts.length; ++i) {
71
104
  if (Math.random() > 0.5) {
72
105
  this.hosts.reverse();
73
106
  }
74
- if (this._isUndefined(method) || method == null) {
75
- this.hosts.push(('https:' == document.location.protocol ? 'https' : 'http') + '://' + hostsArray[i]);
76
- } else if (method === 'https' || method === 'HTTPS') {
77
- this.hosts.push('https://' + hostsArray[i]);
78
- } else {
79
- this.hosts.push('http://' + hostsArray[i]);
80
- }
107
+ this.hosts.push(this.host_protocol + hosts[i]);
81
108
  }
82
109
  if (Math.random() > 0.5) {
83
110
  this.hosts.reverse();
84
111
  }
112
+ // then add Distributed Search Network host if there is one
113
+ if (this.dsn || this.dsnHost != null) {
114
+ if (this.dsnHost) {
115
+ this.hosts.unshift(this.host_protocol + this.dsnHost);
116
+ } else {
117
+ this.hosts.unshift(this.host_protocol + this.applicationID + '-dsn.algolia.io');
118
+ }
119
+ }
85
120
 
86
121
  // resolve DNS + check CORS support (JSONP fallback)
122
+ this.requestTimeoutInMs = 2000;
123
+ this.currentHostIndex = 0;
87
124
  this.jsonp = null;
88
125
  this.jsonpWait = 0;
89
126
  this._jsonRequest({
@@ -91,7 +128,8 @@ var AlgoliaSearch = function(applicationID, apiKey, method, resolveDNS, hostsArr
91
128
  url: '/1/isalive',
92
129
  callback: function(success, content) {
93
130
  self.jsonp = !success;
94
- }
131
+ },
132
+ removeCustomHTTPHeaders: true
95
133
  });
96
134
  this.extraHeaders = [];
97
135
  };
@@ -408,7 +446,7 @@ AlgoliaSearch.prototype = {
408
446
  */
409
447
  addQueryInBatch: function(indexName, query, args) {
410
448
  var params = 'query=' + encodeURIComponent(query);
411
- if (!this._isUndefined(args) && args != null) {
449
+ if (!this._isUndefined(args) && args !== null) {
412
450
  params = this._getSearchParams(args, params);
413
451
  }
414
452
  this.batch.push({ indexName: indexName, params: params });
@@ -439,7 +477,7 @@ AlgoliaSearch.prototype = {
439
477
  params.requests.push(as.batch[i]);
440
478
  }
441
479
  window.clearTimeout(as.onDelayTrigger);
442
- if (!this._isUndefined(delay) && delay != null && delay > 0) {
480
+ if (!this._isUndefined(delay) && delay !== null && delay > 0) {
443
481
  var onDelayTrigger = window.setTimeout( function() {
444
482
  as._sendQueriesBatch(params, callback);
445
483
  }, delay);
@@ -448,6 +486,19 @@ AlgoliaSearch.prototype = {
448
486
  this._sendQueriesBatch(params, callback);
449
487
  }
450
488
  },
489
+
490
+ /**
491
+ * Set the number of milliseconds a request can take before automatically being terminated.
492
+ *
493
+ * @param {Number} milliseconds
494
+ */
495
+ setRequestTimeout: function(milliseconds)
496
+ {
497
+ if (milliseconds) {
498
+ this.requestTimeoutInMs = parseInt(milliseconds, 10);
499
+ }
500
+ },
501
+
451
502
  /*
452
503
  * Index class constructor.
453
504
  * You should not use this method directly but use initIndex() function
@@ -458,13 +509,18 @@ AlgoliaSearch.prototype = {
458
509
  this.typeAheadArgs = null;
459
510
  this.typeAheadValueOption = null;
460
511
  },
461
-
512
+ /**
513
+ * Add an extra field to the HTTP request
514
+ *
515
+ * @param key the header field name
516
+ * @param value the header field value
517
+ */
462
518
  setExtraHeader: function(key, value) {
463
519
  this.extraHeaders.push({ key: key, value: value});
464
520
  },
465
521
 
466
522
  _sendQueriesBatch: function(params, callback) {
467
- if (this.jsonp == null) {
523
+ if (this.jsonp === null) {
468
524
  var self = this;
469
525
  this._waitReady(function() { self._sendQueriesBatch(params, callback); });
470
526
  return;
@@ -485,13 +541,15 @@ AlgoliaSearch.prototype = {
485
541
  method: 'POST',
486
542
  url: '/1/indexes/*/queries',
487
543
  body: params,
488
- callback: callback });
544
+ callback: callback,
545
+ removeCustomHTTPHeaders: true});
489
546
  }
490
547
  },
491
548
  /*
492
549
  * Wrapper that try all hosts to maximize the quality of service
493
550
  */
494
551
  _jsonRequest: function(opts) {
552
+ var successiveRetryCount = 0;
495
553
  var self = this;
496
554
  var callback = opts.callback;
497
555
  var cache = null;
@@ -509,33 +567,33 @@ AlgoliaSearch.prototype = {
509
567
  }
510
568
  }
511
569
 
512
- var impl = function(position) {
513
- var idx = 0;
514
- if (!self._isUndefined(position)) {
515
- idx = position;
516
- }
517
- if (self.hosts.length <= idx) {
570
+ var impl = function() {
571
+ if (successiveRetryCount >= self.hosts.length) {
518
572
  if (!self._isUndefined(callback)) {
519
- callback(false, { message: 'Cannot contact server'});
573
+ successiveRetryCount = 0;
574
+ callback(false, { message: 'Cannot connect the Algolia\'s Search API. Please send an email to support@algolia.com to report the issue.' });
520
575
  }
521
576
  return;
522
577
  }
523
578
  opts.callback = function(retry, success, res, body) {
524
579
  if (!success && !self._isUndefined(body)) {
525
- if (window.console) { console.log('Error: ' + body.message); }
580
+ console && console.log('Error: ' + body.message);
526
581
  }
527
582
  if (success && !self._isUndefined(opts.cache)) {
528
583
  cache[cacheID] = body;
529
584
  }
530
- if (!success && retry && (idx + 1) < self.hosts.length) {
531
- impl(idx + 1);
585
+ if (!success && retry) {
586
+ self.currentHostIndex = ++self.currentHostIndex % self.hosts.length;
587
+ successiveRetryCount += 1;
588
+ impl();
532
589
  } else {
590
+ successiveRetryCount = 0;
533
591
  if (!self._isUndefined(callback)) {
534
592
  callback(success, body);
535
593
  }
536
594
  }
537
595
  };
538
- opts.hostname = self.hosts[idx];
596
+ opts.hostname = self.hosts[self.currentHostIndex];
539
597
  self._jsonRequestByHost(opts);
540
598
  };
541
599
  impl();
@@ -546,98 +604,191 @@ AlgoliaSearch.prototype = {
546
604
  var url = opts.hostname + opts.url;
547
605
 
548
606
  if (this.jsonp) {
549
- if (!opts.jsonp) {
550
- opts.callback(true, false, null, { 'message': 'Method ' + opts.method + ' ' + url + ' is not supported by JSONP.' });
551
- return;
552
- }
553
- this.jsonpCounter = this.jsonpCounter || 0;
554
- this.jsonpCounter += 1;
555
- var cb = 'algoliaJSONP_' + this.jsonpCounter;
607
+ this._makeJsonpRequestByHost(url, opts);
608
+ } else {
609
+ this._makeXmlHttpRequestByHost(url, opts);
610
+ }
611
+ },
612
+
613
+ /**
614
+ * Make a JSONP request
615
+ *
616
+ * @param url request url (includes endpoint and path)
617
+ * @param opts all request options
618
+ */
619
+ _makeJsonpRequestByHost: function(url, opts) {
620
+ if (!opts.jsonp) {
621
+ opts.callback(true, false, null, { 'message': 'Method ' + opts.method + ' ' + url + ' is not supported by JSONP.' });
622
+ return;
623
+ }
624
+
625
+ this.jsonpCounter = this.jsonpCounter || 0;
626
+ this.jsonpCounter += 1;
627
+ var head = document.getElementsByTagName('head')[0];
628
+ var script = document.createElement('script');
629
+ var cb = 'algoliaJSONP_' + this.jsonpCounter;
630
+ var done = false;
631
+ var ontimeout = null;
632
+
633
+ window[cb] = function(data) {
634
+ opts.callback(false, true, null, data);
635
+ try { delete window[cb]; } catch (e) { window[cb] = undefined; }
636
+ };
637
+
638
+ script.type = 'text/javascript';
639
+ script.src = url + '?callback=' + cb + ',' + this.applicationID + ',' + this.apiKey;
640
+
641
+ if (opts.body['X-Algolia-TagFilters']) {
642
+ script.src += '&X-Algolia-TagFilters=' + encodeURIComponent(opts.body['X-Algolia-TagFilters']);
643
+ }
644
+
645
+ if (opts.body['X-Algolia-UserToken']) {
646
+ script.src += '&X-Algolia-UserToken=' + encodeURIComponent(opts.body['X-Algolia-UserToken']);
647
+ }
648
+
649
+ if (opts.body && opts.body.params) {
650
+ script.src += '&' + opts.body.params;
651
+ }
652
+
653
+ ontimeout = setTimeout(function() {
654
+ script.onload = script.onreadystatechange = script.onerror = null;
556
655
  window[cb] = function(data) {
557
- opts.callback(false, true, null, data);
558
656
  try { delete window[cb]; } catch (e) { window[cb] = undefined; }
559
657
  };
560
- var script = document.createElement('script');
561
- script.type = 'text/javascript';
562
- script.src = url + '?callback=' + cb + ',' + this.applicationID + ',' + this.apiKey;
563
- if (opts['X-Algolia-TagFilters']) {
564
- script.src += '&X-Algolia-TagFilters=' + opts['X-Algolia-TagFilters'];
658
+
659
+ opts.callback(true, false, null, { 'message': 'Timeout - Failed to load JSONP script.' });
660
+ head.removeChild(script);
661
+
662
+ clearTimeout(ontimeout);
663
+ ontimeout = null;
664
+
665
+ }, this.requestTimeoutInMs);
666
+
667
+ script.onload = script.onreadystatechange = function() {
668
+ clearTimeout(ontimeout);
669
+ ontimeout = null;
670
+
671
+ if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
672
+ done = true;
673
+
674
+ if (typeof window[cb + '_loaded'] === 'undefined') {
675
+ opts.callback(true, false, null, { 'message': 'Failed to load JSONP script.' });
676
+ try { delete window[cb]; } catch (e) { window[cb] = undefined; }
677
+ } else {
678
+ try { delete window[cb + '_loaded']; } catch (e) { window[cb + '_loaded'] = undefined; }
679
+ }
680
+ script.onload = script.onreadystatechange = null; // Handle memory leak in IE
681
+ head.removeChild(script);
565
682
  }
566
- if (opts['X-Algolia-UserToken']) {
567
- script.src += '&X-Algolia-UserToken=' + opts['X-Algolia-UserToken'];
683
+ };
684
+
685
+ script.onerror = function() {
686
+ clearTimeout(ontimeout);
687
+ ontimeout = null;
688
+
689
+ opts.callback(true, false, null, { 'message': 'Failed to load JSONP script.' });
690
+ head.removeChild(script);
691
+ try { delete window[cb]; } catch (e) { window[cb] = undefined; }
692
+ };
693
+
694
+ head.appendChild(script);
695
+ },
696
+
697
+ /**
698
+ * Make a XmlHttpRequest
699
+ *
700
+ * @param url request url (includes endpoint and path)
701
+ * @param opts all request opts
702
+ */
703
+ _makeXmlHttpRequestByHost: function(url, opts) {
704
+ var self = this;
705
+ var xmlHttp = window.XMLHttpRequest ? new XMLHttpRequest() : {};
706
+ var body = null;
707
+ var ontimeout = null;
708
+
709
+ if (!this._isUndefined(opts.body)) {
710
+ body = JSON.stringify(opts.body);
711
+ }
712
+
713
+ if ('withCredentials' in xmlHttp) {
714
+ xmlHttp.open(opts.method, url , true);
715
+ if (this._isUndefined(opts.removeCustomHTTPHeaders) || !opts.removeCustomHTTPHeaders) {
716
+ xmlHttp.setRequestHeader('X-Algolia-API-Key', this.apiKey);
717
+ xmlHttp.setRequestHeader('X-Algolia-Application-Id', this.applicationID);
568
718
  }
569
- if (opts.body && opts.body.params) {
570
- script.src += '&' + opts.body.params;
719
+ xmlHttp.timeout = this.requestTimeoutInMs;
720
+ for (var i = 0; i < this.extraHeaders.length; ++i) {
721
+ xmlHttp.setRequestHeader(this.extraHeaders[i].key, this.extraHeaders[i].value);
571
722
  }
572
- var head = document.getElementsByTagName('head')[0];
573
- script.onerror = function() {
574
- opts.callback(true, false, null, { 'message': 'Failed to load JSONP script.' });
575
- head.removeChild(script);
576
- try { delete window[cb]; } catch (e) { window[cb] = undefined; }
577
- };
578
- var done = false;
579
- script.onload = script.onreadystatechange = function() {
580
- if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
581
- done = true;
582
- if (typeof window[cb + '_loaded'] === 'undefined') {
583
- opts.callback(true, false, null, { 'message': 'Failed to load JSONP script.' });
584
- try { delete window[cb]; } catch (e) { window[cb] = undefined; }
585
- } else {
586
- try { delete window[cb + '_loaded']; } catch (e) { window[cb + '_loaded'] = undefined; }
587
- }
588
- script.onload = script.onreadystatechange = null; // Handle memory leak in IE
589
- head.removeChild(script);
590
- }
591
- };
592
- head.appendChild(script);
723
+ if (body !== null) {
724
+ xmlHttp.setRequestHeader('Content-type', 'application/json');
725
+ }
726
+ } else if (typeof XDomainRequest !== 'undefined') {
727
+ // Handle IE8/IE9
728
+ // XDomainRequest only exists in IE, and is IE's way of making CORS requests.
729
+ xmlHttp = new XDomainRequest();
730
+ xmlHttp.open(opts.method, url);
593
731
  } else {
594
- var body = null;
595
- if (!this._isUndefined(opts.body)) {
596
- body = JSON.stringify(opts.body);
732
+ // very old browser, not supported
733
+ console && console.log('Your browser is too old to support CORS requests');
734
+ opts.callback(false, false, null, { 'message': 'CORS not supported' });
735
+ return;
736
+ }
737
+
738
+ ontimeout = setTimeout(function() {
739
+ xmlHttp.abort();
740
+ // Prevent Internet Explorer 9, JScript Error c00c023f
741
+ if (xmlHttp.aborted === true) {
742
+ stopLoadAnimation();
743
+ return;
597
744
  }
598
- var xmlHttp = window.XMLHttpRequest ? new XMLHttpRequest() : {};
599
- if ('withCredentials' in xmlHttp) {
600
- xmlHttp.open(opts.method, url , true);
601
- xmlHttp.setRequestHeader('X-Algolia-API-Key', this.apiKey);
602
- xmlHttp.setRequestHeader('X-Algolia-Application-Id', this.applicationID);
603
- for (var i = 0; i < this.extraHeaders.length; ++i) {
604
- xmlHttp.setRequestHeader(this.extraHeaders[i].key, this.extraHeaders[i].value);
745
+ opts.callback(true, false, null, { 'message': 'Timeout - Could not connect to endpoint ' + url } );
746
+
747
+ clearTimeout(ontimeout);
748
+ ontimeout = null;
749
+
750
+ }, this.requestTimeoutInMs);
751
+
752
+ xmlHttp.onload = function(event) {
753
+ clearTimeout(ontimeout);
754
+ ontimeout = null;
755
+
756
+ if (!self._isUndefined(event) && event.target !== null) {
757
+ var retry = (event.target.status === 0 || event.target.status === 503);
758
+ var success = false;
759
+ var response = null;
760
+
761
+ if (typeof XDomainRequest !== 'undefined') {
762
+ // Handle CORS requests IE8/IE9
763
+ response = event.target.responseText;
764
+ success = (response && response.length > 0);
605
765
  }
606
- if (body != null) {
607
- xmlHttp.setRequestHeader('Content-type', 'application/json');
766
+ else {
767
+ response = event.target.response;
768
+ success = (event.target.status === 200 || event.target.status === 201);
608
769
  }
609
- } else if (typeof XDomainRequest != 'undefined') {
610
- // Handle IE8/IE9
611
- // XDomainRequest only exists in IE, and is IE's way of making CORS requests.
612
- xmlHttp = new XDomainRequest();
613
- xmlHttp.open(opts.method, url);
770
+
771
+ opts.callback(retry, success, event.target, response ? JSON.parse(response) : null);
614
772
  } else {
615
- // very old browser, not supported
616
- if (window.console) { console.log('Your browser is too old to support CORS requests'); }
617
- opts.callback(false, false, null, { 'message': 'CORS not supported' });
618
- return;
773
+ opts.callback(false, true, event, JSON.parse(xmlHttp.responseText));
619
774
  }
620
- xmlHttp.send(body);
621
- xmlHttp.onload = function(event) {
622
- if (!self._isUndefined(event) && event.target != null) {
623
- var retry = (event.target.status === 0 || event.target.status === 503);
624
- var success = (event.target.status === 200 || event.target.status === 201);
625
- opts.callback(retry, success, event.target, event.target.response != null ? JSON.parse(event.target.response) : null);
626
- } else {
627
- opts.callback(false, true, event, JSON.parse(xmlHttp.responseText));
628
- }
629
- };
630
- xmlHttp.onerror = function(event) {
631
- opts.callback(true, false, null, { 'message': 'Could not connect to host', 'error': event } );
632
- };
633
- }
775
+ };
776
+ xmlHttp.ontimeout = function(event) { // stop the network call but rely on ontimeout to call opt.callback
777
+ };
778
+ xmlHttp.onerror = function(event) {
779
+ clearTimeout(ontimeout);
780
+ ontimeout = null;
781
+ opts.callback(true, false, null, { 'message': 'Could not connect to host', 'error': event } );
782
+ };
783
+
784
+ xmlHttp.send(body);
634
785
  },
635
786
 
636
787
  /**
637
788
  * Wait until JSONP flag has been set to perform the first query
638
789
  */
639
790
  _waitReady: function(cb) {
640
- if (this.jsonp == null) {
791
+ if (this.jsonp === null) {
641
792
  this.jsonpWait += 100;
642
793
  if (this.jsonpWait > 2000) {
643
794
  this.jsonp = true;
@@ -650,11 +801,11 @@ AlgoliaSearch.prototype = {
650
801
  * Transform search param object in query string
651
802
  */
652
803
  _getSearchParams: function(args, params) {
653
- if (this._isUndefined(args) || args == null) {
804
+ if (this._isUndefined(args) || args === null) {
654
805
  return params;
655
806
  }
656
807
  for (var key in args) {
657
- if (key != null && args.hasOwnProperty(key)) {
808
+ if (key !== null && args.hasOwnProperty(key)) {
658
809
  params += (params.length === 0) ? '?' : '&';
659
810
  params += key + '=' + encodeURIComponent(Object.prototype.toString.call(args[key]) === '[object Array]' ? JSON.stringify(args[key]) : args[key]);
660
811
  }
@@ -742,7 +893,7 @@ AlgoliaSearch.prototype.Index.prototype = {
742
893
  * @param attributes (optional) if set, contains the array of attribute names to retrieve
743
894
  */
744
895
  getObject: function(objectID, callback, attributes) {
745
- if (this.as.jsonp == null) {
896
+ if (this.as.jsonp === null) {
746
897
  var self = this;
747
898
  this.as._waitReady(function() { self.getObject(objectID, callback, attributes); });
748
899
  return;
@@ -847,7 +998,7 @@ AlgoliaSearch.prototype.Index.prototype = {
847
998
  * content: the server answer that contains 3 elements: createAt, taskId and objectID
848
999
  */
849
1000
  deleteObject: function(objectID, callback) {
850
- if (objectID == null || objectID.length === 0) {
1001
+ if (objectID === null || objectID.length === 0) {
851
1002
  callback(false, { message: 'empty objectID'});
852
1003
  return;
853
1004
  }
@@ -927,11 +1078,11 @@ AlgoliaSearch.prototype.Index.prototype = {
927
1078
  search: function(query, callback, args, delay) {
928
1079
  var indexObj = this;
929
1080
  var params = 'query=' + encodeURIComponent(query);
930
- if (!this.as._isUndefined(args) && args != null) {
1081
+ if (!this.as._isUndefined(args) && args !== null) {
931
1082
  params = this.as._getSearchParams(args, params);
932
1083
  }
933
1084
  window.clearTimeout(indexObj.onDelayTrigger);
934
- if (!this.as._isUndefined(delay) && delay != null && delay > 0) {
1085
+ if (!this.as._isUndefined(delay) && delay !== null && delay > 0) {
935
1086
  var onDelayTrigger = window.setTimeout( function() {
936
1087
  indexObj._search(params, callback);
937
1088
  }, delay);
@@ -1185,7 +1336,7 @@ AlgoliaSearch.prototype.Index.prototype = {
1185
1336
  /// Internal methods only after this line
1186
1337
  ///
1187
1338
  _search: function(params, callback) {
1188
- if (this.as.jsonp == null) {
1339
+ if (this.as.jsonp === null) {
1189
1340
  var self = this;
1190
1341
  this.as._waitReady(function() { self._search(params, callback); });
1191
1342
  return;
@@ -1208,7 +1359,8 @@ AlgoliaSearch.prototype.Index.prototype = {
1208
1359
  method: 'POST',
1209
1360
  url: '/1/indexes/' + encodeURIComponent(this.indexName) + '/query',
1210
1361
  body: pObj,
1211
- callback: callback });
1362
+ callback: callback,
1363
+ removeCustomHTTPHeaders: true});
1212
1364
  }
1213
1365
  },
1214
1366
 
@@ -1530,6 +1682,9 @@ AlgoliaSearch.prototype.Index.prototype = {
1530
1682
  return extend({}, this.searchParams, {
1531
1683
  hitsPerPage: 1,
1532
1684
  page: 0,
1685
+ attributesToRetrieve: [],
1686
+ attributesToHighlight: [],
1687
+ attributesToSnippet: [],
1533
1688
  facets: facet,
1534
1689
  facetFilters: this._getFacetFilters(facet)
1535
1690
  });
@@ -1565,6 +1720,75 @@ AlgoliaSearch.prototype.Index.prototype = {
1565
1720
  };
1566
1721
  })();
1567
1722
 
1723
+ /*
1724
+ * Copyright (c) 2014 Algolia
1725
+ * http://www.algolia.com/
1726
+ *
1727
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
1728
+ * of this software and associated documentation files (the "Software"), to deal
1729
+ * in the Software without restriction, including without limitation the rights
1730
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1731
+ * copies of the Software, and to permit persons to whom the Software is
1732
+ * furnished to do so, subject to the following conditions:
1733
+ *
1734
+ * The above copyright notice and this permission notice shall be included in
1735
+ * all copies or substantial portions of the Software.
1736
+ *
1737
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1738
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1739
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1740
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1741
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1742
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1743
+ * THE SOFTWARE.
1744
+ */
1745
+
1746
+ (function($) {
1747
+
1748
+ /**
1749
+ * Algolia Places API
1750
+ * @param {string} Your application ID
1751
+ * @param {string} Your API Key
1752
+ */
1753
+ window.AlgoliaPlaces = function(applicationID, apiKey) {
1754
+ this.init(applicationID, apiKey);
1755
+ };
1756
+
1757
+ AlgoliaPlaces.prototype = {
1758
+ /**
1759
+ * @param {string} Your application ID
1760
+ * @param {string} Your API Key
1761
+ */
1762
+ init: function(applicationID, apiKey) {
1763
+ this.client = new AlgoliaSearch(applicationID, apiKey, 'http', true, ['places-1.algolia.io', 'places-2.algolia.io', 'places-3.algolia.io']);
1764
+ this.cache = {};
1765
+ },
1766
+
1767
+ /**
1768
+ * Perform a query
1769
+ * @param {string} q the user query
1770
+ * @param {function} searchCallback the result callback called with two arguments:
1771
+ * success: boolean set to true if the request was successfull
1772
+ * content: the query answer with an extra 'disjunctiveFacets' attribute
1773
+ * @param {hash} the list of search parameters
1774
+ */
1775
+ search: function(q, searchCallback, searchParams) {
1776
+ var indexObj = this;
1777
+ var params = 'query=' + encodeURIComponent(q);
1778
+ if (!this.client._isUndefined(searchParams) && searchParams != null) {
1779
+ params = this.client._getSearchParams(searchParams, params);
1780
+ }
1781
+ var pObj = {params: params, apiKey: this.client.apiKey, appID: this.client.applicationID};
1782
+ this.client._jsonRequest({ cache: this.cache,
1783
+ method: 'POST',
1784
+ url: '/1/places/query',
1785
+ body: pObj,
1786
+ callback: searchCallback,
1787
+ removeCustomHTTPHeaders: true });
1788
+ }
1789
+ };
1790
+ })();
1791
+
1568
1792
  /*
1569
1793
  json2.js
1570
1794
  2014-02-04
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * algoliasearch 2.5.3
2
+ * algoliasearch 2.7.0
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.5.3",AlgoliaSearch=function(a,b,c,d,e){var f=this;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 g=0;g<e.length;++g)Math.random()>.5&&this.hosts.reverse(),this.hosts.push(this._isUndefined(c)||null==c?("https:"==document.location.protocol?"https":"http")+"://"+e[g]:"https"===c||"HTTPS"===c?"https://"+e[g]:"http://"+e[g]);Math.random()>.5&&this.hosts.reverse(),this.jsonp=null,this.jsonpWait=0,this._jsonRequest({method:"GET",url:"/1/isalive",callback:function(a){f.jsonp=!a}}),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,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){var c=this,d={requests:[],apiKey:this.apiKey,appID:this.applicationID};this.userToken&&(d["X-Algolia-UserToken"]=this.userToken),this.tagFilters&&(d["X-Algolia-TagFilters"]=this.tagFilters);for(var 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){if(null==this.jsonp){var c=this;return void this._waitReady(function(){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)+"&"}this._jsonRequest({cache:this.cache,method:"GET",jsonp:!0,url:"/1/indexes/*",body:{params:d},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));var f=function(g){var h=0;return b._isUndefined(g)||(h=g),b.hosts.length<=h?void(b._isUndefined(c)||c(!1,{message:"Cannot contact server"})):(a.callback=function(g,i,j,k){i||b._isUndefined(k)||window.console&&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],void b._jsonRequestByHost(a))};f()},_jsonRequestByHost:function(a){var b=this,c=a.hostname+a.url;if(this.jsonp){if(!a.jsonp)return void a.callback(!0,!1,null,{message:"Method "+a.method+" "+c+" is not supported by JSONP."});this.jsonpCounter=this.jsonpCounter||0,this.jsonpCounter+=1;var d="algoliaJSONP_"+this.jsonpCounter;window[d]=function(b){a.callback(!1,!0,null,b);try{delete window[d]}catch(c){window[d]=void 0}};var e=document.createElement("script");e.type="text/javascript",e.src=c+"?callback="+d+","+this.applicationID+","+this.apiKey,a["X-Algolia-TagFilters"]&&(e.src+="&X-Algolia-TagFilters="+a["X-Algolia-TagFilters"]),a["X-Algolia-UserToken"]&&(e.src+="&X-Algolia-UserToken="+a["X-Algolia-UserToken"]),a.body&&a.body.params&&(e.src+="&"+a.body.params);var f=document.getElementsByTagName("head")[0];e.onerror=function(){a.callback(!0,!1,null,{message:"Failed to load JSONP script."}),f.removeChild(e);try{delete window[d]}catch(b){window[d]=void 0}};var g=!1;e.onload=e.onreadystatechange=function(){if(!(g||this.readyState&&"loaded"!=this.readyState&&"complete"!=this.readyState)){if(g=!0,"undefined"==typeof window[d+"_loaded"]){a.callback(!0,!1,null,{message:"Failed to load JSONP script."});try{delete window[d]}catch(b){window[d]=void 0}}else try{delete window[d+"_loaded"]}catch(b){window[d+"_loaded"]=void 0}e.onload=e.onreadystatechange=null,f.removeChild(e)}},f.appendChild(e)}else{var h=null;this._isUndefined(a.body)||(h=JSON.stringify(a.body));var i=window.XMLHttpRequest?new XMLHttpRequest:{};if("withCredentials"in i){i.open(a.method,c,!0),i.setRequestHeader("X-Algolia-API-Key",this.apiKey),i.setRequestHeader("X-Algolia-Application-Id",this.applicationID);for(var j=0;j<this.extraHeaders.length;++j)i.setRequestHeader(this.extraHeaders[j].key,this.extraHeaders[j].value);null!=h&&i.setRequestHeader("Content-type","application/json")}else{if("undefined"==typeof XDomainRequest)return window.console&&console.log("Your browser is too old to support CORS requests"),void a.callback(!1,!1,null,{message:"CORS not supported"});i=new XDomainRequest,i.open(a.method,c)}i.send(h),i.onload=function(c){if(b._isUndefined(c)||null==c.target)a.callback(!1,!0,c,JSON.parse(i.responseText));else{var d=0===c.target.status||503===c.target.status,e=200===c.target.status||201===c.target.status;a.callback(d,e,c.target,null!=c.target.response?JSON.parse(c.target.response):null)}},i.onerror=function(b){a.callback(!0,!1,null,{message:"Could not connect to host",error:b})}}},_waitReady:function(a){null==this.jsonp&&(this.jsonpWait+=100,this.jsonpWait>2e3&&(this.jsonp=!0),setTimeout(a,100))},_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){if(null==this.as.jsonp){var d=this;return void this.as._waitReady(function(){d.getObject(a,b,c)})}var e=this,f="";if(!this.as._isUndefined(c)){f="?attributes=";for(var g=0;g<c.length;++g)0!==g&&(f+=","),f+=c[g]}this.as._jsonRequest({method:"GET",jsonp:!0,url:"/1/indexes/"+encodeURIComponent(e.indexName)+"/"+encodeURIComponent(a)+f,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 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;_.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){if(null==this.as.jsonp){var c=this;return void this.as._waitReady(function(){c._search(a,b)})}var d={params:a,apiKey:this.as.apiKey,appID:this.as.applicationID};this.as.tagFilters&&(d["X-Algolia-TagFilters"]=this.as.tagFilters),this.as.userToken&&(d["X-Algolia-UserToken"]=this.as.userToken),this.as._jsonRequest(this.as.jsonp?{cache:this.cache,method:"GET",jsonp:!0,url:"/1/indexes/"+encodeURIComponent(this.indexName),body:d,callback:b}:{cache:this.cache,method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/query",body:d,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};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={}},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},_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=0;a<this.options.disjunctiveFacets.length;++a)this.client.addQueryInBatch(this.index,this.q,this._getDisjunctiveFacetSearchParams(this.options.disjunctiveFacets[a]));var b=this;this.client.sendQueriesBatch(function(a,c){if(!a)return void b.searchCallback(!1,c);var d=c.results[0];d.disjunctiveFacets={},d.facetStats={};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],b.disjunctiveRefinements[f])for(var g in b.disjunctiveRefinements[f])!d.disjunctiveFacets[f][g]&&b.disjunctiveRefinements[f][g]&&(d.disjunctiveFacets[f][g]=0);for(var h in c.results[e].facets_stats)d.facetStats[h]=c.results[e].facets_stats[h]}b.searchCallback(!0,d)})},_getHitsSearchParams:function(){return a({},{hitsPerPage:this.options.hitsPerPage,page:this.page,facets:this.options.facets,facetFilters:this._getFacetFilters()},this.searchParams)},_getDisjunctiveFacetSearchParams:function(b){return a({},this.searchParams,{hitsPerPage:1,page:0,facets:b,facetFilters:this._getFacetFilters(b)})},_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}}}(),"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.7.0",AlgoliaSearch=function(a,b,c,d,e){var f=this;this.applicationID=a,this.apiKey=b,this.dsn=!1,this.dsnHost=null,this.hosts=[];var g;if("string"==typeof c)g=c;else{var h=c;this._isUndefined(h.method)||(g=h.method),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(e)&&(e=[this.applicationID+"-1.algolia.io",this.applicationID+"-2.algolia.io",this.applicationID+"-3.algolia.io"]),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 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.io"),this.requestTimeoutInMs=2e3,this.currentHostIndex=0,this.jsonp=null,this.jsonpWait=0,this._jsonRequest({method:"GET",url:"/1/isalive",callback:function(a){f.jsonp=!a},removeCustomHTTPHeaders:!0}),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,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){var c=this,d={requests:[],apiKey:this.apiKey,appID:this.applicationID};this.userToken&&(d["X-Algolia-UserToken"]=this.userToken),this.tagFilters&&(d["X-Algolia-TagFilters"]=this.tagFilters);for(var 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;return void this._waitReady(function(){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)+"&"}this._jsonRequest({cache:this.cache,method:"GET",jsonp:!0,url:"/1/indexes/*",body:{params:d},callback:b})}else this._jsonRequest({cache:this.cache,method:"POST",url:"/1/indexes/*/queries",body:a,callback:b,removeCustomHTTPHeaders:!0})},_jsonRequest:function(a){var b=0,c=this,d=a.callback,e=null,f=a.url;if(this._isUndefined(a.body)||(f=a.url+"_body_"+JSON.stringify(a.body)),!this._isUndefined(a.cache)&&(e=a.cache,!this._isUndefined(e[f])))return void(this._isUndefined(d)||setTimeout(function(){d(!0,e[f])},1));var g=function(){return b>=c.hosts.length?void(c._isUndefined(d)||(b=0,d(!1,{message:"Cannot connect the Algolia's Search API. Please send an email to support@algolia.com to report the issue."}))):(a.callback=function(h,i,j,k){i||c._isUndefined(k)||console&&console.log("Error: "+k.message),i&&!c._isUndefined(a.cache)&&(e[f]=k),!i&&h?(c.currentHostIndex=++c.currentHostIndex%c.hosts.length,b+=1,g()):(b=0,c._isUndefined(d)||d(i,k))},a.hostname=c.hosts[c.currentHostIndex],void c._jsonRequestByHost(a))};g()},_jsonRequestByHost:function(a){var b=a.hostname+a.url;this.jsonp?this._makeJsonpRequestByHost(b,a):this._makeXmlHttpRequestByHost(b,a)},_makeJsonpRequestByHost:function(a,b){if(!b.jsonp)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+","+this.applicationID+","+this.apiKey,b.body["X-Algolia-TagFilters"]&&(d.src+="&X-Algolia-TagFilters="+encodeURIComponent(b.body["X-Algolia-TagFilters"])),b.body["X-Algolia-UserToken"]&&(d.src+="&X-Algolia-UserToken="+encodeURIComponent(b.body["X-Algolia-UserToken"])),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;if(this._isUndefined(b.body)||(e=JSON.stringify(b.body)),"withCredentials"in d){d.open(b.method,a,!0),(this._isUndefined(b.removeCustomHTTPHeaders)||!b.removeCustomHTTPHeaders)&&(d.setRequestHeader("X-Algolia-API-Key",this.apiKey),d.setRequestHeader("X-Algolia-Application-Id",this.applicationID)),d.timeout=this.requestTimeoutInMs;for(var g=0;g<this.extraHeaders.length;++g)d.setRequestHeader(this.extraHeaders[g].key,this.extraHeaders[g].value);null!==e&&d.setRequestHeader("Content-type","application/json")}else{if("undefined"==typeof XDomainRequest)return console&&console.log("Your browser is too old to support CORS requests"),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),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)},_waitReady:function(a){null===this.jsonp&&(this.jsonpWait+=100,this.jsonpWait>2e3&&(this.jsonp=!0),setTimeout(a,100))},_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){if(null===this.as.jsonp){var d=this;return void this.as._waitReady(function(){d.getObject(a,b,c)})}var e=this,f="";if(!this.as._isUndefined(c)){f="?attributes=";for(var g=0;g<c.length;++g)0!==g&&(f+=","),f+=c[g]}this.as._jsonRequest({method:"GET",jsonp:!0,url:"/1/indexes/"+encodeURIComponent(e.indexName)+"/"+encodeURIComponent(a)+f,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 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;_.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){if(null===this.as.jsonp){var c=this;return void this.as._waitReady(function(){c._search(a,b)})}var d={params:a,apiKey:this.as.apiKey,appID:this.as.applicationID};this.as.tagFilters&&(d["X-Algolia-TagFilters"]=this.as.tagFilters),this.as.userToken&&(d["X-Algolia-UserToken"]=this.as.userToken),this.as._jsonRequest(this.as.jsonp?{cache:this.cache,method:"GET",jsonp:!0,url:"/1/indexes/"+encodeURIComponent(this.indexName),body:d,callback:b}:{cache:this.cache,method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/query",body:d,callback:b,removeCustomHTTPHeaders:!0})},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};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={}},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},_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=0;a<this.options.disjunctiveFacets.length;++a)this.client.addQueryInBatch(this.index,this.q,this._getDisjunctiveFacetSearchParams(this.options.disjunctiveFacets[a]));var b=this;this.client.sendQueriesBatch(function(a,c){if(!a)return void b.searchCallback(!1,c);var d=c.results[0];d.disjunctiveFacets={},d.facetStats={};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],b.disjunctiveRefinements[f])for(var g in b.disjunctiveRefinements[f])!d.disjunctiveFacets[f][g]&&b.disjunctiveRefinements[f][g]&&(d.disjunctiveFacets[f][g]=0);for(var h in c.results[e].facets_stats)d.facetStats[h]=c.results[e].facets_stats[h]}b.searchCallback(!0,d)})},_getHitsSearchParams:function(){return a({},{hitsPerPage:this.options.hitsPerPage,page:this.page,facets:this.options.facets,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)})},_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}}}(),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
4
+ version: 1.11.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Algolia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-05 00:00:00.000000000 Z
11
+ date: 2014-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json