algoliasearch-rails 1.15.1 → 1.16.0

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: 9e2aa7b700a1456246e3433c6b6c8a36803df9de
4
- data.tar.gz: 2fe47b07529091cb7854dad7e4bbdb253bab934d
3
+ metadata.gz: 896c5f230813d18ff8e9690822d0a4306333db91
4
+ data.tar.gz: aebeff6835f6dd017dede213dcce29671cf3ef6b
5
5
  SHA512:
6
- metadata.gz: a9256c815fa8fcd96eb7702a446f9b8d5f592c6f668b773816478f11495e5ffcfc3fd7ffbb0eeca2864a6bed654f6432eecba0b5eec9605b2a0d61bcd40d361c
7
- data.tar.gz: b7bf19b0adade7b484fde9f1084ad7e66dd8a3cce947bd3df65c856f26b55f19663e6f45f0b84a433b63e3e9b204c247013039a6c9516ef0b08cd41dec815b18
6
+ metadata.gz: 5e53db4e89af8d4ed8432f6cb918d62050348d7ebc6ee54f42839714a695f0199a7c6c65d17e1a9341c88b76751b305eca24919dbd7f91f0e765388215ecbe11
7
+ data.tar.gz: 7a11bf529e54d4b2024b0e0947baa7d1c985246945eafc910513301b7a79525609dd102f465119a9e68ca09ddc5e047966ba43e743467b905dfb9a4aba3efaa8
data/.travis.yml CHANGED
@@ -38,6 +38,8 @@ matrix:
38
38
  # env: RAILS_VERSION=4.2
39
39
  # - rvm: rbx-3.20
40
40
  # env: RAILS_VERSION=5.0
41
+ allow_failures:
42
+ - rvm: rbx-2
41
43
  install: rm -f Gemfile.lock && bundle install
42
44
  cache: bundler
43
45
  env:
data/ChangeLog CHANGED
@@ -1,5 +1,10 @@
1
1
  CHANGELOG
2
2
 
3
+ 2016-10-02 1.16.0
4
+
5
+ * Upgrade `algoliasearch` to 1.12.0
6
+ * Add `search_facet` method
7
+
3
8
  2016-10-02 1.15.1
4
9
 
5
10
  * Missing `advancedSyntax` index setting forward
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  gem 'json', '~> 1.5', '>= 1.5.1'
4
- gem 'algoliasearch', '~> 1.11.0'
4
+ gem 'algoliasearch', '~> 1.12.0'
5
5
  gem 'rubysl', '~> 2.0', :platform => :rbx
6
6
 
7
7
  group :test do
@@ -13,11 +13,18 @@ group :test do
13
13
  gem 'addressable', '<= 2.2.7'
14
14
  gem 'rack-cache', '< 1.3'
15
15
  gem 'mime-types', '< 2.6'
16
+ gem 'net-http-persistent', '< 3.0'
16
17
  elsif defined?(RUBY_VERSION) && RUBY_VERSION == "1.9.3"
17
18
  if Gem::Version.new(ENV['RAILS_VERSION'] || '3.2.0') >= Gem::Version.new('4.0')
18
19
  gem 'mime-types', '~> 2.6'
19
20
  end
20
21
  end
22
+ if defined?(RUBY_VERSION) &&
23
+ defined?(RUBY_ENGINE) &&
24
+ RUBY_ENGINE == 'ruby' &&
25
+ Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.1')
26
+ gem 'net-http-persistent', '< 3.0'
27
+ end
21
28
  gem 'rspec', '>= 2.5.0', '< 3.0'
22
29
  gem 'sqlite3', :platform => [:rbx, :ruby]
23
30
  gem 'jdbc-sqlite3', :platform => :jruby
data/Gemfile.lock CHANGED
@@ -39,8 +39,8 @@ GEM
39
39
  minitest (~> 5.1)
40
40
  tzinfo (~> 1.1)
41
41
  addressable (2.4.0)
42
- algoliasearch (1.11.0)
43
- httpclient (~> 2.8.2)
42
+ algoliasearch (1.12.0)
43
+ httpclient (~> 2.8.2.4)
44
44
  json (>= 1.5.1)
45
45
  arel (7.1.0)
46
46
  backports (3.6.8)
@@ -66,7 +66,7 @@ GEM
66
66
  globalid (0.3.6)
67
67
  activesupport (>= 4.1.0)
68
68
  highline (1.7.8)
69
- httpclient (2.8.2.2)
69
+ httpclient (2.8.2.4)
70
70
  i18n (0.7.0)
71
71
  json (1.8.3)
72
72
  kaminari (0.17.0)
@@ -372,7 +372,7 @@ PLATFORMS
372
372
  DEPENDENCIES
373
373
  activerecord-jdbc-adapter
374
374
  activerecord-jdbcsqlite3-adapter
375
- algoliasearch (~> 1.11.0)
375
+ algoliasearch (~> 1.12.0)
376
376
  jdbc-sqlite3
377
377
  json (~> 1.5, >= 1.5.1)
378
378
  kaminari
data/README.md CHANGED
@@ -7,7 +7,7 @@ Algolia Search for Rails
7
7
 
8
8
  This gem let you easily integrate the Algolia Search API to your favorite ORM. It's based on the [algoliasearch-client-ruby](https://github.com/algolia/algoliasearch-client-ruby) gem. Rails 3.x, 4.x and 5.x are all supported.
9
9
 
10
- You might be interested in the sample Ruby on Rails application providing a ```autocomplete.js```-based auto-completion and ```instantsearch.js```-based instant search results page: [algoliasearch-rails-example](https://github.com/algolia/algoliasearch-rails-example/).
10
+ You might be interested in the sample Ruby on Rails application providing a `autocomplete.js`-based auto-completion and `instantsearch.js`-based instant search results page: [algoliasearch-rails-example](https://github.com/algolia/algoliasearch-rails-example/).
11
11
 
12
12
  [![Build Status](https://travis-ci.org/algolia/algoliasearch-rails.svg?branch=master)](https://travis-ci.org/algolia/algoliasearch-rails) [![Gem Version](https://badge.fury.io/rb/algoliasearch-rails.svg)](http://badge.fury.io/rb/algoliasearch-rails) [![Code Climate](https://codeclimate.com/github/algolia/algoliasearch-rails.svg)](https://codeclimate.com/github/algolia/algoliasearch-rails) ![ActiveRecord](https://img.shields.io/badge/ActiveRecord-yes-blue.svg?style=flat-square) ![Mongoid](https://img.shields.io/badge/Mongoid-yes-blue.svg?style=flat-square) ![Sequel](https://img.shields.io/badge/Sequel-yes-blue.svg?style=flat-square)
13
13
 
@@ -28,6 +28,7 @@ Table of Content
28
28
  1. [Tags](#tags)
29
29
  1. [Search](#search)
30
30
  1. [Faceting](#faceting)
31
+ 1. [Facet search](#facet-search)
31
32
  1. [Group by](#group-by)
32
33
  1. [Geo-search](#geo-search)
33
34
  1. [Caveats](#caveats)
@@ -161,7 +162,7 @@ Traditional search implementations tend to have search logic and functionality o
161
162
 
162
163
  Implementing search on the backend is no longer necessary. In fact, in most cases it is harmful to performance because of added network and processing latency. We highly recommend the usage of our [JavaScript API Client](https://github.com/algolia/algoliasearch-client-js) issuing all search requests directly from the end user's browser, mobile device, or client. It will reduce the overall search latency while offloading your servers at the same time.
163
164
 
164
- The JS API client is part of the gem, just require ```algolia/v3/algoliasearch.min``` somewhere in your JavaScript manifest, for example in ```application.js``` if you are using Rails 3.1+:
165
+ The JS API client is part of the gem, just require `algolia/v3/algoliasearch.min` somewhere in your JavaScript manifest, for example in `application.js` if you are using Rails 3.1+:
165
166
 
166
167
  ```javascript
167
168
  //= require algolia/v3/algoliasearch.min
@@ -223,7 +224,7 @@ Then, as soon as you use the `search` method, the returning results will be a pa
223
224
 
224
225
  ### Notes
225
226
 
226
- All methods injected by the ```AlgoliaSearch``` include are prefixed by ```algolia_``` and aliased to the associated short names if they aren't already defined.
227
+ All methods injected by the `AlgoliaSearch` include are prefixed by `algolia_` and aliased to the associated short names if they aren't already defined.
227
228
 
228
229
  ```ruby
229
230
  Contact.algolia_reindex! # <=> Contact.reindex!
@@ -472,7 +473,7 @@ class Profile < ActiveRecord::Base
472
473
  end
473
474
  ```
474
475
 
475
- ### Custom ```objectID```
476
+ ### Custom `objectID`
476
477
 
477
478
  By default, the `objectID` is based on your record's `id`. You can change this behavior specifying the `:id` option (be sure to use a uniq field).
478
479
 
@@ -487,7 +488,7 @@ end
487
488
 
488
489
  ### Restrict indexing to a subset of your data
489
490
 
490
- You can add constraints controlling if a record must be indexed by using options the ```:if``` or ```:unless``` options.
491
+ You can add constraints controlling if a record must be indexed by using options the `:if` or `:unless` options.
491
492
 
492
493
  It allows you to do conditional indexing on a per document basis.
493
494
 
@@ -508,7 +509,7 @@ class Post < ActiveRecord::Base
508
509
  end
509
510
  ```
510
511
 
511
- **Notes:** As soon as you use those constraints, ```addObjects``` and ```deleteObjects``` calls will be performed in order to keep the index synced with the DB (The state-less gem doesn't know if the object don't match your constraints anymore or never matched, so we force ADD/DELETE operations to be sent). You can work-around this behavior creating a `_changed?` method:
512
+ **Notes:** As soon as you use those constraints, `addObjects` and `deleteObjects` calls will be performed in order to keep the index synced with the DB (The state-less gem doesn't know if the object don't match your constraints anymore or never matched, so we force ADD/DELETE operations to be sent). You can work-around this behavior creating a `_changed?` method:
512
513
 
513
514
  ```ruby
514
515
  class Contact < ActiveRecord::Base
@@ -543,7 +544,7 @@ MyModel.index_objects MyModel.limit(5)
543
544
 
544
545
  ### Sanitizer
545
546
 
546
- You can sanitize all your attributes using the ```sanitize``` option. It will strip all HTML tags from your attributes.
547
+ You can sanitize all your attributes using the `sanitize` option. It will strip all HTML tags from your attributes.
547
548
 
548
549
  ```ruby
549
550
  class User < ActiveRecord::Base
@@ -565,7 +566,7 @@ gem 'rails-html-sanitizer'
565
566
 
566
567
  ### UTF-8 Encoding
567
568
 
568
- You can force the UTF-8 encoding of all your attributes using the ```force_utf8_encoding``` option:
569
+ You can force the UTF-8 encoding of all your attributes using the `force_utf8_encoding` option:
569
570
 
570
571
  ```ruby
571
572
  class User < ActiveRecord::Base
@@ -875,7 +876,7 @@ p json_answer['hits']
875
876
  p json_answer['facets']
876
877
  ```
877
878
 
878
- Search parameters can be specified either through the index's [settings](https://github.com/algolia/algoliasearch-client-ruby#index-settings) statically in your model or dynamically at search time specifying [search parameters](https://github.com/algolia/algoliasearch-client-ruby#search) as second argument of the ```search``` method:
879
+ Search parameters can be specified either through the index's [settings](https://github.com/algolia/algoliasearch-client-ruby#index-settings) statically in your model or dynamically at search time specifying [search parameters](https://github.com/algolia/algoliasearch-client-ruby#search) as second argument of the `search` method:
879
880
 
880
881
  ```ruby
881
882
  class Contact < ActiveRecord::Base
@@ -892,6 +893,7 @@ class Contact < ActiveRecord::Base
892
893
  end
893
894
  ```
894
895
 
896
+
895
897
  ```ruby
896
898
  # dynamical search parameters
897
899
  p Contact.raw_search("jon doe", { :hitsPerPage => 5, :page => 2 })
@@ -899,7 +901,7 @@ p Contact.raw_search("jon doe", { :hitsPerPage => 5, :page => 2 })
899
901
 
900
902
  ### Faceting
901
903
 
902
- Facets can be retrieved calling the extra ```facets``` method of the search answer.
904
+ Facets can be retrieved calling the extra `facets` method of the search answer.
903
905
 
904
906
  ```ruby
905
907
  class Contact < ActiveRecord::Base
@@ -914,6 +916,7 @@ class Contact < ActiveRecord::Base
914
916
  end
915
917
  ```
916
918
 
919
+
917
920
  ```ruby
918
921
  hits = Contact.search("jon doe", { :facets => '*' })
919
922
  p hits # ORM-compliant array of objects
@@ -922,11 +925,31 @@ p hits.facets['company'] # facet values+count of facet 'company'
922
925
  p hits.facets['zip_code'] # facet values+count of facet 'zip_code'
923
926
  ```
924
927
 
928
+
925
929
  ```ruby
926
930
  raw_json = Contact.raw_search("jon doe", { :facets => '*' })
927
931
  p raw_json['facets']
928
932
  ```
929
933
 
934
+ ### Facet search
935
+
936
+ You can also search for facet values.
937
+
938
+ ```ruby
939
+ Product.search_facet('category', 'Headphones') # Array of {value, highlighted, count}
940
+ ```
941
+
942
+ This method can also take any parameter a query can take.
943
+ This will adjust the search to only hits which would have matched the query.
944
+
945
+ ```ruby
946
+ # Only sends back the categories containing red Apple products (and only counts those)
947
+ Product.search_facet('category', 'phone', {
948
+ query: 'red',
949
+ filters: 'brand:Apple'
950
+ }) # Array of phone categories linked to red Apple products
951
+ ```
952
+
930
953
  ### Group by
931
954
 
932
955
  More info on distinct for grouping can be found
@@ -964,7 +987,7 @@ At query time, specify <code>{ aroundLatLng: "37.33, -121.89", aroundRadius: 500
964
987
 
965
988
  ### Caveats
966
989
 
967
- This gem makes intensive use of Rails' callbacks to trigger the indexing tasks. If you're using methods bypassing ```after_validation```, ```before_save``` or ```after_commit``` callbacks, it will not index your changes. For example: ```update_attribute``` doesn't perform validations checks, to perform validations when updating use ```update_attributes```.
990
+ This gem makes intensive use of Rails' callbacks to trigger the indexing tasks. If you're using methods bypassing `after_validation`, `before_save` or `after_commit` callbacks, it will not index your changes. For example: `update_attribute` doesn't perform validations checks, to perform validations when updating use `update_attributes`.
968
991
 
969
992
  ### Timeouts
970
993
 
@@ -986,7 +1009,7 @@ AlgoliaSearch.configuration = {
986
1009
 
987
1010
  To run the specs, please set the <code>ALGOLIA_APPLICATION_ID</code> and <code>ALGOLIA_API_KEY</code> environment variables. Since the tests are creating and removing indexes, DO NOT use your production account.
988
1011
 
989
- You may want to disable all indexing (add, update & delete operations) API calls, you can set the ```disable_indexing``` option:
1012
+ You may want to disable all indexing (add, update & delete operations) API calls, you can set the `disable_indexing` option:
990
1013
 
991
1014
  ```ruby
992
1015
  class User < ActiveRecord::Base
@@ -1026,3 +1049,4 @@ describe 'With a mocked client' do
1026
1049
 
1027
1050
  end
1028
1051
  ```
1052
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.15.1
1
+ 1.16.0
@@ -301,6 +301,7 @@ module AlgoliaSearch
301
301
  alias_method :clear_index!, :algolia_clear_index! unless method_defined? :clear_index!
302
302
  alias_method :search, :algolia_search unless method_defined? :search
303
303
  alias_method :raw_search, :algolia_raw_search unless method_defined? :raw_search
304
+ alias_method :search_facet, :algolia_search_facet unless method_defined? :search_facet
304
305
  alias_method :index, :algolia_index unless method_defined? :index
305
306
  alias_method :index_name, :algolia_index_name unless method_defined? :index_name
306
307
  alias_method :must_reindex?, :algolia_must_reindex? unless method_defined? :must_reindex?
@@ -600,6 +601,13 @@ module AlgoliaSearch
600
601
  res
601
602
  end
602
603
 
604
+ def algolia_search_facet(facet, text, params = {})
605
+ index_name = params.delete(:index) || params.delete('index') || params.delete(:slave) || params.delete('slave')
606
+ index = algolia_index(index_name)
607
+ query = Hash[params.map { |k, v| [k.to_s, v.to_s] }]
608
+ index.search_facet(facet, text, query)['facetHits']
609
+ end
610
+
603
611
  def algolia_index(name = nil)
604
612
  if name
605
613
  algolia_configurations.each do |o, s|
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.15.1
4
+ version: 1.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Algolia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-02 00:00:00.000000000 Z
11
+ date: 2016-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -183,9 +183,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
183
  version: '0'
184
184
  requirements: []
185
185
  rubyforge_project:
186
- rubygems_version: 2.4.1
186
+ rubygems_version: 2.5.1
187
187
  signing_key:
188
188
  specification_version: 4
189
189
  summary: AlgoliaSearch integration to your favorite ORM
190
190
  test_files: []
191
- has_rdoc: