algoliasearch-rails 1.11.18 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b90eda1033e39094342631bc26f4356b2fb77723
4
- data.tar.gz: b2b8a9acdc2814b526f69c30c7bb85de3998f039
3
+ metadata.gz: 0d74f56ff72c3c4e345e66f172b6be8d29378bee
4
+ data.tar.gz: 0363a42c7a6c17e842c561807b151095ef7e23f7
5
5
  SHA512:
6
- metadata.gz: fae998c2943cbaa65c7fd588a96aaee86fe7b5c8937dda84c3708e5c09fe6c94367361230a3e264023f4d6d585cc3b7641ac41b11b14a7e4b4cc689e23cfc7c3
7
- data.tar.gz: d079747d3a7fcc582b4dce2ec76a225abf6c9c46dd8f340d893448e67e7d87d73a231ab2bb89b3c5631993f5dc9dc6964191fc9473f9cdac74b8382ba2104ef9
6
+ metadata.gz: 4196b33784fc23a9b8dbd3d66318a3c32c9bca6dfb3c132c0b6679c0182a6e6857261e6db9164c86d2133b3899b048bbedc1dde8a9fc6e99126a54e77a0fbe48
7
+ data.tar.gz: 92be73f9302e3081eff020bee02410491d35523488554f6f511cf00d5c9a99f6c7712006de9a2bb287655a616b22f9d5a7d3f378d08ced3b746f78b1b58eb6ea
data/ChangeLog CHANGED
@@ -1,5 +1,9 @@
1
1
  CHANGELOG
2
2
 
3
+ 2015-04-29 1.12.0
4
+
5
+ * Add Sequel support.
6
+
3
7
  2015-03-31 1.11.18
4
8
 
5
9
  * Embed AlgoliaSearch JS API client v3 as well. Default is still the v2 to keep the backward compatibility.
data/Gemfile CHANGED
@@ -15,6 +15,7 @@ group :test do
15
15
  gem 'autotest-fsevent', '~> 0.2.10'
16
16
  gem 'redgreen'
17
17
  gem 'autotest-growl'
18
+ gem 'sequel'
18
19
  end
19
20
 
20
21
  group :development do
data/Gemfile.lock CHANGED
@@ -339,6 +339,7 @@ GEM
339
339
  rubysl-xmlrpc (2.0.0)
340
340
  rubysl-yaml (2.0.4)
341
341
  rubysl-zlib (2.0.1)
342
+ sequel (4.21.0)
342
343
  slop (3.6.0)
343
344
  spoon (0.0.4)
344
345
  ffi
@@ -392,6 +393,7 @@ DEPENDENCIES
392
393
  redgreen
393
394
  rspec (>= 2.5.0, < 3.0)
394
395
  rubysl (~> 2.0)
396
+ sequel
395
397
  sqlite3
396
398
  travis
397
399
  will_paginate (>= 2.3.15)
data/README.md CHANGED
@@ -5,7 +5,7 @@ This gem let you easily integrate the Algolia Search API to your favorite ORM. I
5
5
 
6
6
  You might be interested in the sample Ruby on Rails application providing a ```typeahead.js```-based auto-completion and ```Google```-like instant search: [algoliasearch-rails-example](https://github.com/algolia/algoliasearch-rails-example/).
7
7
 
8
- [![Build Status](https://travis-ci.org/algolia/algoliasearch-rails.png?branch=master)](https://travis-ci.org/algolia/algoliasearch-rails) [![Gem Version](https://badge.fury.io/rb/algoliasearch-rails.png)](http://badge.fury.io/rb/algoliasearch-rails) [![Code Climate](https://codeclimate.com/github/algolia/algoliasearch-rails.png)](https://codeclimate.com/github/algolia/algoliasearch-rails)
8
+ [![Build Status](https://travis-ci.org/algolia/algoliasearch-rails.png?branch=master)](https://travis-ci.org/algolia/algoliasearch-rails) [![Gem Version](https://badge.fury.io/rb/algoliasearch-rails.png)](http://badge.fury.io/rb/algoliasearch-rails) [![Code Climate](https://codeclimate.com/github/algolia/algoliasearch-rails.png)](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)
9
9
 
10
10
  Table of Content
11
11
  -------------
@@ -56,6 +56,8 @@ Create a new file <code>config/initializers/algoliasearch.rb</code> to setup you
56
56
  AlgoliaSearch.configuration = { application_id: 'YourApplicationID', api_key: 'YourAPIKey' }
57
57
  ```
58
58
 
59
+ The gem is compatible with [ActiveRecord](https://github.com/rails/rails/tree/master/activerecord), [Mongoid](https://github.com/mongoid/mongoid) and [Sequel](https://github.com/jeremyevans/sequel).
60
+
59
61
  We support both [will_paginate](https://github.com/mislav/will_paginate) and [kaminari](https://github.com/amatsuda/kaminari) as pagination backend. For example to use <code>:will_paginate</code>, specify the <code>:pagination_backend</code> as follow:
60
62
 
61
63
  ```ruby
@@ -158,16 +160,16 @@ index.search('something', function(success, hits) {
158
160
 
159
161
  #### Backend Search
160
162
 
161
- A search returns ORM-compliant objects reloading them from your database.
163
+ If you want to search from your backend you can use the `raw_search` method. It retrieves the raw JSON answer from the API:
162
164
 
163
165
  ```ruby
164
- p Contact.search("jon doe")
166
+ p Contact.raw_search("jon doe")
165
167
  ```
166
168
 
167
- If you want to retrieve the raw JSON answer from the API, without re-loading the objects from the database, you can use:
169
+ You could also use `search` but it's not recommended. This method will fetch the matching `objectIDs` from the API and perform a database query to retrieve an array of matching models:
168
170
 
169
171
  ```ruby
170
- p Contact.raw_search("jon doe")
172
+ p Contact.search("jon doe") # we recommend to use `raw_search` to avoid the database lookup
171
173
  ```
172
174
 
173
175
  #### Notes
@@ -691,7 +693,7 @@ end
691
693
 
692
694
  ```ruby
693
695
  # dynamical search parameters
694
- p Contact.search("jon doe", { :hitsPerPage => 5, :page => 2 })
696
+ p Contact.raw_search("jon doe", { :hitsPerPage => 5, :page => 2 })
695
697
  ```
696
698
 
697
699
  Faceting
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.11.18
1
+ 1.12.0
@@ -71,7 +71,7 @@ module AlgoliaSearch
71
71
  raise ArgumentError.new('Cannot pass multiple attribute names if block given') if block_given? and names.length > 1
72
72
  raise ArgumentError.new('Cannot specify additional attributes on a slave index') if @options[:slave]
73
73
  @attributes ||= {}
74
- names.each do |name|
74
+ names.flatten.each do |name|
75
75
  @attributes[name.to_s] = block_given? ? Proc.new { |o| o.instance_eval(&block) } : Proc.new { |o| o.send(name) }
76
76
  end
77
77
  end
@@ -95,6 +95,11 @@ module AlgoliaSearch
95
95
  Hash[@attributes.map { |name, value| [name.to_s, value.call(object) ] }]
96
96
  @additional_attributes.each { |name, value| res[name.to_s] = value.call(object) } if @additional_attributes
97
97
  res
98
+ elsif defined?(::Sequel) && clazz < ::Sequel::Model
99
+ res = @attributes.nil? || @attributes.length == 0 ? object.to_hash :
100
+ Hash[@attributes.map { |name, value| [name.to_s, value.call(object) ] }]
101
+ @additional_attributes.each { |name, value| res[name.to_s] = value.call(object) } if @additional_attributes
102
+ res
98
103
  else
99
104
  object.class.unscoped do
100
105
  res = @attributes.nil? || @attributes.length == 0 ? object.attributes :
@@ -229,12 +234,49 @@ module AlgoliaSearch
229
234
  attr_accessor :highlight_result, :snippet_result
230
235
 
231
236
  if options[:synchronous] == true
232
- after_validation :algolia_mark_synchronous if respond_to?(:after_validation)
237
+ if defined?(::Sequel) && self < Sequel::Model
238
+ class_eval do
239
+ copy_after_validation = instance_method(:after_validation)
240
+ define_method(:after_validation) do |*args|
241
+ super(*args)
242
+ copy_after_validation.bind(self).call
243
+ algolia_mark_synchronous
244
+ end
245
+ end
246
+ else
247
+ after_validation :algolia_mark_synchronous if respond_to?(:after_validation)
248
+ end
233
249
  end
234
250
  unless options[:auto_index] == false
235
- after_validation :algolia_mark_must_reindex if respond_to?(:after_validation)
236
- before_save :algolia_mark_for_auto_indexing if respond_to?(:before_save)
237
- after_save :algolia_perform_index_tasks if respond_to?(:after_save)
251
+ if defined?(::Sequel) && self < Sequel::Model
252
+ class_eval do
253
+ copy_after_validation = instance_method(:after_validation)
254
+ copy_before_save = instance_method(:before_save)
255
+ copy_after_save = instance_method(:after_save)
256
+
257
+ define_method(:after_validation) do |*args|
258
+ super(*args)
259
+ copy_after_validation.bind(self).call
260
+ algolia_mark_must_reindex
261
+ end
262
+
263
+ define_method(:before_save) do |*args|
264
+ copy_before_save.bind(self).call
265
+ algolia_mark_for_auto_indexing
266
+ super(*args)
267
+ end
268
+
269
+ define_method(:after_save) do |*args|
270
+ super(*args)
271
+ copy_after_save.bind(self).call
272
+ algolia_perform_index_tasks
273
+ end
274
+ end
275
+ else
276
+ after_validation :algolia_mark_must_reindex if respond_to?(:after_validation)
277
+ before_save :algolia_mark_for_auto_indexing if respond_to?(:before_save)
278
+ after_save :algolia_perform_index_tasks if respond_to?(:after_save)
279
+ end
238
280
  end
239
281
  unless options[:auto_remove] == false
240
282
  after_destroy { |searchable| searchable.remove_from_index! } if respond_to?(:after_destroy)
@@ -263,13 +305,18 @@ module AlgoliaSearch
263
305
  # delete non-indexable objects
264
306
  objects = group.select { |o| !algolia_indexable?(o, options) }.map { |o| algolia_object_id_of(o, options) }
265
307
  index.delete_objects(objects)
266
- # select only indexable objects
308
+ # select only indexable objects
267
309
  group = group.select { |o| algolia_indexable?(o, options) }
268
310
  end
269
- objects = group.map { |o| settings.get_attributes(o).merge 'objectID' => algolia_object_id_of(o, options) }
311
+ objects = group.map do |o|
312
+ attributes = settings.get_attributes(o)
313
+ unless attributes.class == Hash
314
+ attributes = attributes.to_hash
315
+ end
316
+ attributes.merge 'objectID' => algolia_object_id_of(o, options)
317
+ end
270
318
  last_task = index.save_objects(objects)
271
319
  end
272
-
273
320
  index.wait_task(last_task["taskID"]) if last_task and synchronous == true
274
321
  end
275
322
  nil
@@ -590,6 +637,8 @@ module AlgoliaSearch
590
637
  def algolia_find_in_batches(batch_size, &block)
591
638
  if (defined?(::ActiveRecord) && ancestors.include?(::ActiveRecord::Base)) || respond_to?(:find_in_batches)
592
639
  find_in_batches(:batch_size => batch_size, &block)
640
+ elsif defined?(::Sequel) && self < Sequel::Model
641
+ each_page(batch_size, &block)
593
642
  else
594
643
  # don't worry, mongoid has its own underlying cursor/streaming mechanism
595
644
  items = []
@@ -638,7 +687,12 @@ module AlgoliaSearch
638
687
  end
639
688
 
640
689
  def algolia_mark_must_reindex
641
- @algolia_must_reindex = new_record? || self.class.algolia_must_reindex?(self)
690
+ @algolia_must_reindex =
691
+ if defined?(::Sequel) && is_a?(Sequel::Model)
692
+ new? || self.class.algolia_must_reindex?(self)
693
+ else
694
+ new_record? || self.class.algolia_must_reindex?(self)
695
+ end
642
696
  true
643
697
  end
644
698
 
metadata CHANGED
@@ -1,111 +1,111 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: algoliasearch-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.18
4
+ version: 1.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Algolia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-31 00:00:00.000000000 Z
11
+ date: 2015-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.5.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.5.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: algoliasearch
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: 1.2.14
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.2.14
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: will_paginate
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: 2.3.15
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: 2.3.15
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: kaminari
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: travis
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rdoc
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  description: AlgoliaSearch integration to your favorite ORM
@@ -117,9 +117,9 @@ extra_rdoc_files:
117
117
  - LICENSE
118
118
  - README.md
119
119
  files:
120
- - .document
121
- - .rspec
122
- - .travis.yml
120
+ - ".document"
121
+ - ".rspec"
122
+ - ".travis.yml"
123
123
  - ChangeLog
124
124
  - Gemfile
125
125
  - Gemfile.lock
@@ -172,17 +172,17 @@ require_paths:
172
172
  - lib
173
173
  required_ruby_version: !ruby/object:Gem::Requirement
174
174
  requirements:
175
- - - '>='
175
+ - - ">="
176
176
  - !ruby/object:Gem::Version
177
177
  version: '0'
178
178
  required_rubygems_version: !ruby/object:Gem::Requirement
179
179
  requirements:
180
- - - '>='
180
+ - - ">="
181
181
  - !ruby/object:Gem::Version
182
182
  version: '0'
183
183
  requirements: []
184
184
  rubyforge_project:
185
- rubygems_version: 2.0.14
185
+ rubygems_version: 2.2.2
186
186
  signing_key:
187
187
  specification_version: 4
188
188
  summary: AlgoliaSearch integration to your favorite ORM