algoliasearch-rails 1.10.6 → 1.10.7

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: 0abd869d8b7021676051417ff8f3a54d64cd6c01
4
- data.tar.gz: d84fbe3c59f997e518c27393b3c7b70d315c6c49
3
+ metadata.gz: 80b4afee8f3b76e7ae6bc4a85e36f7a2ac11404d
4
+ data.tar.gz: 293b6baee5f060f5524ae2f573c9bccdb044e4fa
5
5
  SHA512:
6
- metadata.gz: f3023ccffd38aab0ad8f2bcf657fcdb1bfc027bc1b8fd78bd50184881f8e1cb25e24f318bc30ceb960d2d7421264f4c967385d8f08818749d4aac773f7cff725
7
- data.tar.gz: 3286d414ed42da850ff3640c5f15d78296ea1feb4c250404acbe0d26fa0f883066f3bc27e8da292ff8e1f8770619d1a8f4ed1e1f52df41c930348c2a5a9c9602
6
+ metadata.gz: a471bf1df7cf7d5c4a2645b8aaeff63baaf7e7e2dc970e33e07a7e23fe6d5cfc48d0e773c06ca730ff5bc55b4263449ef25018e9128a0e01dacdd67485d3c27e
7
+ data.tar.gz: e6c60c16d668d91e7960ee79532d20567e6d29d9fdf1c51948f05358eec0759749ee0adc1999eaeb00e35d7e3ad3ec07952eb547c5a0771c3e71f390efd46df3
data/ChangeLog CHANGED
@@ -1,5 +1,9 @@
1
1
  CHANGELOG
2
2
 
3
+ 2014-07-17 1.10.7
4
+
5
+ * Query optimization: load search results from database using a single query (author: @outoftime)
6
+
3
7
  2014-07-10 1.10.6
4
8
 
5
9
  * Pass the configuration hash to the underlying ```Algolia.init``` method.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.10.6
1
+ 1.10.7
@@ -6,11 +6,11 @@
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "algoliasearch-rails"
9
- s.version = "1.10.6"
9
+ s.version = "1.10.7"
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-07-10"
13
+ s.date = "2014-07-17"
14
14
  s.description = "AlgoliaSearch integration to your favorite ORM"
15
15
  s.email = "contact@algolia.com"
16
16
  s.extra_rdoc_files = [
@@ -86,11 +86,20 @@ module AlgoliaSearch
86
86
  alias :add_attributes :add_attribute
87
87
 
88
88
  def get_attributes(object)
89
- object.class.unscoped do
89
+ clazz = object.class
90
+ if defined?(::Mongoid::Document) && clazz.include?(::Mongoid::Document)
91
+ # work-around mongoid 2.4's unscoped method, not accepting a block
90
92
  res = @attributes.nil? || @attributes.length == 0 ? object.attributes :
91
93
  Hash[@attributes.map { |name, value| [name.to_s, value.call(object) ] }]
92
94
  @additional_attributes.each { |name, value| res[name.to_s] = value.call(object) } if @additional_attributes
93
95
  res
96
+ else
97
+ object.class.unscoped do
98
+ res = @attributes.nil? || @attributes.length == 0 ? object.attributes :
99
+ Hash[@attributes.map { |name, value| [name.to_s, value.call(object) ] }]
100
+ @additional_attributes.each { |name, value| res[name.to_s] = value.call(object) } if @additional_attributes
101
+ res
102
+ end
94
103
  end
95
104
  end
96
105
 
@@ -347,8 +356,12 @@ module AlgoliaSearch
347
356
  params[:page] -= 1 if params[:page].to_i > 0
348
357
  end
349
358
  json = algolia_raw_search(q, params)
359
+ hit_ids = json['hits'].map { |hit| hit['objectID'] }
360
+ results_by_id = algoliasearch_options[:type].where(algolia_object_id_method => hit_ids).index_by do |hit|
361
+ algolia_object_id_of(hit)
362
+ end
350
363
  results = json['hits'].map do |hit|
351
- o = algoliasearch_options[:type].where(algolia_object_id_method => hit['objectID']).first
364
+ o = results_by_id[hit['objectID']]
352
365
  if o
353
366
  o.highlight_result = hit['_highlightResult']
354
367
  o
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.10.6
4
+ version: 1.10.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Algolia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-10 00:00:00.000000000 Z
11
+ date: 2014-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json