algoliasearch-rails 1.3.2 → 1.3.3

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: d428c61f7c4dc2a09a1cf096ea4a3ff8f473a371
4
- data.tar.gz: 6ff620725b76b9d753a6a01078c216168e33d0ab
3
+ metadata.gz: 0e29ac47364a507c6d864668517822cffce9c2d6
4
+ data.tar.gz: 66acdcd30134e3b656e03eab50400c3424853e52
5
5
  SHA512:
6
- metadata.gz: bd7bf16ad2c6ca12e1850b5cc0e33c6990a03bae6aca68c6b97185fef5d1e842b6a6f56c5f7700b85936c8c26ca136542cf68b334fec1bde0eadd77601e24d79
7
- data.tar.gz: 361a11ba7ba9c81f572b773f0bc97afc0e8fea5d324c552963c06fd248d22b93fe69f54c87503910361656c86a11bb9ba05c9de69c76373c90570e9f202fa2b6
6
+ metadata.gz: daa6bdbe2bd086b90c710942c87474684cad0a1af44406e2a2ffdc6033baf7ef4a4eac7d9a566bab4e6b4f4a34f0d3b4a1f4ac8ff1fe3527da14ec0178a5edf1
7
+ data.tar.gz: fd0ab69277ac18436e0fa3a789fd0844621360a3310d81721732234530b240d561b5c821864c55151491818244ce0fb14b80e95574456f8fdf5d7e4595698e90
data/ChangeLog CHANGED
@@ -1,5 +1,11 @@
1
1
  CHANGELOG
2
2
 
3
+ 2013-11-07 1.3.3
4
+
5
+ * new :per_environment options suffixing index's name by the Rails environment
6
+ * index's settings are now initialized on first usage, not at include time
7
+ * plug attributesForFaceting setting
8
+
3
9
  2013-10-17 1.3.2
4
10
 
5
11
  * while detecting settings changes, fixed array comparison
@@ -1,32 +1,32 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- ZenTest (4.9.4)
5
- actionpack (4.0.0)
6
- activesupport (= 4.0.0)
4
+ ZenTest (4.9.5)
5
+ actionpack (4.0.1)
6
+ activesupport (= 4.0.1)
7
7
  builder (~> 3.1.0)
8
8
  erubis (~> 2.7.0)
9
9
  rack (~> 1.5.2)
10
10
  rack-test (~> 0.6.2)
11
- activemodel (4.0.0)
12
- activesupport (= 4.0.0)
11
+ activemodel (4.0.1)
12
+ activesupport (= 4.0.1)
13
13
  builder (~> 3.1.0)
14
- activerecord (4.0.0)
15
- activemodel (= 4.0.0)
14
+ activerecord (4.0.1)
15
+ activemodel (= 4.0.1)
16
16
  activerecord-deprecated_finders (~> 1.0.2)
17
- activesupport (= 4.0.0)
17
+ activesupport (= 4.0.1)
18
18
  arel (~> 4.0.0)
19
19
  activerecord-deprecated_finders (1.0.3)
20
- activesupport (4.0.0)
20
+ activesupport (4.0.1)
21
21
  i18n (~> 0.6, >= 0.6.4)
22
22
  minitest (~> 4.2)
23
23
  multi_json (~> 1.3)
24
24
  thread_safe (~> 0.1)
25
25
  tzinfo (~> 0.3.37)
26
26
  addressable (2.3.5)
27
- algoliasearch (1.1.4)
27
+ algoliasearch (1.1.5)
28
28
  curb
29
- arel (4.0.0)
29
+ arel (4.0.1)
30
30
  atomic (1.1.14)
31
31
  autotest (4.4.6)
32
32
  ZenTest (>= 4.4.1)
@@ -46,7 +46,7 @@ GEM
46
46
  multipart-post (~> 1.2.0)
47
47
  faraday_middleware (0.9.0)
48
48
  faraday (>= 0.7.4, < 0.9)
49
- ffi (1.9.0)
49
+ ffi (1.9.3)
50
50
  gh (0.13.0)
51
51
  addressable
52
52
  backports
@@ -63,7 +63,7 @@ GEM
63
63
  nokogiri (~> 1.5.2)
64
64
  oauth2
65
65
  hashie (2.0.5)
66
- highline (1.6.19)
66
+ highline (1.6.20)
67
67
  httpauth (0.2.0)
68
68
  i18n (0.6.5)
69
69
  jeweler (1.8.8)
@@ -75,7 +75,7 @@ GEM
75
75
  nokogiri (= 1.5.10)
76
76
  rake
77
77
  rdoc
78
- json (1.8.0)
78
+ json (1.8.1)
79
79
  jwt (0.1.8)
80
80
  multi_json (>= 1.5)
81
81
  kaminari (0.14.1)
@@ -104,8 +104,7 @@ GEM
104
104
  coderay (~> 1.0.5)
105
105
  method_source (~> 0.8)
106
106
  slop (~> 3.4)
107
- pusher-client (0.3.1)
108
- ruby-hmac (~> 0.4.0)
107
+ pusher-client (0.4.0)
109
108
  websocket (~> 1.0.0)
110
109
  rack (1.5.2)
111
110
  rack-test (0.6.2)
@@ -118,19 +117,18 @@ GEM
118
117
  rspec-core (~> 2.14.0)
119
118
  rspec-expectations (~> 2.14.0)
120
119
  rspec-mocks (~> 2.14.0)
121
- rspec-core (2.14.5)
120
+ rspec-core (2.14.7)
122
121
  rspec-expectations (2.14.3)
123
122
  diff-lcs (>= 1.1.3, < 2.0)
124
- rspec-mocks (2.14.3)
125
- ruby-hmac (0.4.0)
123
+ rspec-mocks (2.14.4)
126
124
  slop (3.4.6)
127
125
  sqlite3 (1.3.8)
128
126
  sys-uname (0.9.2)
129
127
  ffi (>= 1.0.0)
130
- terminal-notifier (1.5.1)
131
128
  thread_safe (0.1.3)
132
129
  atomic
133
- travis (1.5.5)
130
+ travis (1.5.8)
131
+ addressable (~> 2.3)
134
132
  backports
135
133
  faraday (~> 0.8.7)
136
134
  faraday_middleware (~> 0.9)
@@ -139,10 +137,9 @@ GEM
139
137
  launchy (~> 2.1)
140
138
  netrc (~> 0.7)
141
139
  pry (~> 0.9)
142
- pusher-client (~> 0.3, >= 0.3.1)
143
- terminal-notifier (>= 1.4.2)
140
+ pusher-client (~> 0.4)
144
141
  typhoeus (~> 0.6)
145
- typhoeus (0.6.5)
142
+ typhoeus (0.6.6)
146
143
  ethon (~> 0.6.1)
147
144
  tzinfo (0.3.38)
148
145
  websocket (1.0.7)
data/README.md CHANGED
@@ -56,7 +56,7 @@ AlgoliaSearch.configuration = { application_id: 'YourApplicationID', api_key: 'Y
56
56
  Quick Start
57
57
  -------------
58
58
 
59
- The following code will create a <code>contact</code> index and add search capabilities to your <code>Contact</code> model:
59
+ The following code will create a <code>Contact</code> index and add search capabilities to your <code>Contact</code> model:
60
60
 
61
61
  ```ruby
62
62
  class Contact < ActiveRecord::Base
@@ -113,13 +113,25 @@ class Contact < ActiveRecord::Base
113
113
  end
114
114
  ```
115
115
 
116
- You can force force the index name using the following option:
116
+ You can force the index name using the following option:
117
117
 
118
118
  ```ruby
119
119
  class Contact < ActiveRecord::Base
120
120
  include AlgoliaSearch
121
121
 
122
- algoliasearch index_name: "contacts_#{Rails.env}" do
122
+ algoliasearch index_name: "MyCustomName" do
123
+ attribute :first_name, :last_name, :email
124
+ end
125
+ end
126
+ ```
127
+
128
+ You can suffix the index name with the current Rails environment using the following option:
129
+
130
+ ```ruby
131
+ class Contact < ActiveRecord::Base
132
+ include AlgoliaSearch
133
+
134
+ algoliasearch per_environment: true do # index name will be "Contact_#{Rails.env}"
123
135
  attribute :first_name, :last_name, :email
124
136
  end
125
137
  end
@@ -164,7 +176,7 @@ All [settings](https://github.com/algolia/algoliasearch-client-ruby#index-settin
164
176
  class Contact < ActiveRecord::Base
165
177
  include AlgoliaSearch
166
178
 
167
- algoliasearch auto_index: false, auto_remove: false do
179
+ algoliasearch do
168
180
  attribute :first_name, :last_name, :email
169
181
  minWordSizeForApprox1 2
170
182
  minWordSizeForApprox2 5
@@ -180,7 +192,7 @@ p Contact.search("jon doe", hitsPerPage: 5, page: 2)
180
192
  Typeahead UI
181
193
  -------------
182
194
 
183
- Require ```algolia/algoliasearch.min``` (see [algoliasearch-client-js](https://github.com/algolia/algoliasearch-client-js)) and ```algolia/typeahead.js``` (a modified version of typeahead.js with custom transports, see the [pull request](https://github.com/twitter/typeahead.js/pull/473)) somewhere in your JavaScript manifest, for example in application.js if you are using Rails 3.1+:
195
+ Require ```algolia/algoliasearch.min``` (see [algoliasearch-client-js](https://github.com/algolia/algoliasearch-client-js)) and ```algolia/typeahead.js``` (a modified version of typeahead.js with custom transports, see the [pull request](https://github.com/twitter/typeahead.js/pull/473)) somewhere in your JavaScript manifest, for example in ```application.js``` if you are using Rails 3.1+:
184
196
 
185
197
  ```javascript
186
198
  //= require algolia/algoliasearch.min
@@ -199,10 +211,10 @@ Turns any ```input[type="text"]``` element into a typeahead, for example:
199
211
  <input name="email" placeholder="test@example.org" id="user_email" />
200
212
  <script type="text/javascript">
201
213
  $(document).ready(function() {
202
- var client = new AlgoliaSearch('YourApplicationID', 'ReadOnlyApplicationKey');
214
+ var client = new AlgoliaSearch('YourApplicationID', 'SearchOnlyApplicationKey');
203
215
  $('input#user_email').typeahead({
204
216
  name: 'emails',
205
- remote: client.initIndex('YourIndex').getTypeaheadTransport(),
217
+ remote: client.initIndex('#{Contact.index_name}').getTypeaheadTransport(),
206
218
  engine: Hogan,
207
219
  template: '{{{_highlightResult.email.value}}} ({{{_highlightResult.first_name.value}}} {{{_highlightResult.last_name.value}}})',
208
220
  valueKey: 'email'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.2
1
+ 1.3.3
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "algoliasearch-rails"
8
- s.version = "1.3.2"
8
+ s.version = "1.3.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Algolia"]
12
- s.date = "2013-10-17"
12
+ s.date = "2013-11-07"
13
13
  s.description = "AlgoliaSearch integration to your favorite ORM"
14
14
  s.email = "contact@algolia.com"
15
15
  s.extra_rdoc_files = [
@@ -46,7 +46,7 @@ Gem::Specification.new do |s|
46
46
  s.homepage = "http://github.com/algolia/algoliasearch-rails"
47
47
  s.licenses = ["MIT"]
48
48
  s.require_paths = ["lib"]
49
- s.rubygems_version = "2.0.3"
49
+ s.rubygems_version = "2.0.12"
50
50
  s.summary = "AlgoliaSearch integration to your favorite ORM"
51
51
 
52
52
  if s.respond_to? :specification_version then
@@ -48,7 +48,7 @@ module AlgoliaSearch
48
48
  OPTIONS = [:attributesToIndex, :minWordSizefor1Typo,
49
49
  :minWordSizefor2Typos, :hitsPerPage, :attributesToRetrieve,
50
50
  :attributesToHighlight, :attributesToSnippet, :attributesToIndex,
51
- :ranking, :customRanking, :queryType]
51
+ :ranking, :customRanking, :queryType, :attributesForFaceting]
52
52
  OPTIONS.each do |k|
53
53
  define_method k do |v|
54
54
  instance_variable_set("@#{k}", v)
@@ -89,11 +89,11 @@ module AlgoliaSearch
89
89
  attr_accessor :highlight_result
90
90
 
91
91
  if options[:synchronous] == true
92
- before_save :mark_synchronous if respond_to?(:before_save)
92
+ after_validation :mark_synchronous if respond_to?(:before_validation)
93
93
  end
94
94
  unless options[:auto_index] == false
95
- before_save :mark_for_auto_indexing if respond_to?(:before_save)
96
95
  after_validation :mark_must_reindex if respond_to?(:after_validation)
96
+ before_save :mark_for_auto_indexing if respond_to?(:before_save)
97
97
  after_save :perform_index_tasks if respond_to?(:after_save)
98
98
  end
99
99
  unless options[:auto_remove] == false
@@ -101,10 +101,10 @@ module AlgoliaSearch
101
101
  end
102
102
 
103
103
  @options = { type: model_name, per_page: @index_options.get(:hitsPerPage) || 10, page: 1 }.merge(options)
104
- init
105
104
  end
106
105
 
107
106
  def reindex!(batch_size = 1000, synchronous = false)
107
+ ensure_init
108
108
  last_task = nil
109
109
  find_in_batches(batch_size: batch_size) do |group|
110
110
  objects = group.map { |o| attributes(o).merge 'objectID' => o.id.to_s }
@@ -114,6 +114,7 @@ module AlgoliaSearch
114
114
  end
115
115
 
116
116
  def index!(object, synchronous = false)
117
+ ensure_init
117
118
  if synchronous
118
119
  @index.add_object!(attributes(object), object.id.to_s)
119
120
  else
@@ -122,6 +123,7 @@ module AlgoliaSearch
122
123
  end
123
124
 
124
125
  def remove_from_index!(object, synchronous = false)
126
+ ensure_init
125
127
  if synchronous
126
128
  @index.delete_object!(object.id.to_s)
127
129
  else
@@ -130,9 +132,9 @@ module AlgoliaSearch
130
132
  end
131
133
 
132
134
  def clear_index!
133
- @index.delete rescue "already deleted, not fatal"
135
+ ensure_init
136
+ @index.delete
134
137
  @index = nil
135
- init
136
138
  end
137
139
 
138
140
  def search(q, settings = {})
@@ -145,11 +147,13 @@ module AlgoliaSearch
145
147
  AlgoliaSearch::Pagination.create(results, json['nbHits'].to_i, @options)
146
148
  end
147
149
 
148
- def init
149
- @index ||= Algolia::Index.new(@options[:index_name] || model_name)
150
- settings = @index_options.to_settings
151
- prev_settings = @index.get_settings rescue nil # if the index doesn't exist
152
- @index.set_settings(settings) if index_settings_changed?(prev_settings, settings)
150
+ def ensure_init
151
+ new_settings = @index_options.to_settings
152
+ return if @index and !index_settings_changed?(@settings, new_settings)
153
+ @index = Algolia::Index.new(index_name)
154
+ current_settings = @index.get_settings rescue nil # if the index doesn't exist
155
+ @index.set_settings(new_settings) if index_settings_changed?(current_settings, new_settings)
156
+ @settings = new_settings
153
157
  end
154
158
 
155
159
  def must_reindex?(object)
@@ -161,6 +165,12 @@ module AlgoliaSearch
161
165
  return false
162
166
  end
163
167
 
168
+ def index_name
169
+ name = @options[:index_name] || model_name
170
+ name = "#{name}_#{Rails.env.to_s}" if @options[:per_environment]
171
+ name
172
+ end
173
+
164
174
  private
165
175
 
166
176
  def attributes(object)
@@ -1,4 +1,6 @@
1
1
  require 'rubygems'
2
+ require 'bundler'
3
+
2
4
  Bundler.setup :test
3
5
 
4
6
  $LOAD_PATH.unshift(File.dirname(__FILE__))
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.3.2
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Algolia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-17 00:00:00.000000000 Z
11
+ date: 2013-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -147,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
147
  version: '0'
148
148
  requirements: []
149
149
  rubyforge_project:
150
- rubygems_version: 2.0.3
150
+ rubygems_version: 2.0.12
151
151
  signing_key:
152
152
  specification_version: 4
153
153
  summary: AlgoliaSearch integration to your favorite ORM