searchkick 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +6 -0
- data/README.md +9 -1
- data/gemfiles/mongoid2.gemfile +7 -0
- data/gemfiles/mongoid4.gemfile +1 -1
- data/lib/searchkick.rb +5 -1
- data/lib/searchkick/model.rb +8 -1
- data/lib/searchkick/query.rb +2 -1
- data/lib/searchkick/results.rb +6 -1
- data/lib/searchkick/similar.rb +1 -1
- data/lib/searchkick/version.rb +1 -1
- data/test/facets_test.rb +11 -2
- data/test/sql_test.rb +20 -1
- data/test/test_helper.rb +29 -3
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dfbf6c27b23821e31c3de0338259ee8c2adf5130
|
4
|
+
data.tar.gz: f3b47e7a6d98f990f53d95410c88e2a2fc791b36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b0d6d2d11bde9c7a3f316a6ac6dc4886f639b8a02ddc6b49e280ae0535b38f7f43e53e1507528587cdc578b0b1ad165816aa23b89d4e21043a4e480790f181c
|
7
|
+
data.tar.gz: 39b962185cf9b507be764e1175e8bbe2d27822eed2005ad02923849577237c348d80b77e3ee8b3128676f7191ac43f23b2044075051751b532260a32597a877b
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -651,6 +651,8 @@ For the best performance, add [Patron](https://github.com/toland/patron) to your
|
|
651
651
|
gem 'patron'
|
652
652
|
```
|
653
653
|
|
654
|
+
Searchkick will automatically use it.
|
655
|
+
|
654
656
|
**Note:** Patron is not available for Windows.
|
655
657
|
|
656
658
|
### Automatic Failover
|
@@ -757,6 +759,12 @@ Product.enable_search_callbacks # or use Searchkick.enable_callbacks for all mod
|
|
757
759
|
Product.reindex
|
758
760
|
```
|
759
761
|
|
762
|
+
Change the search method name in `config/initializers/searchkick.rb`
|
763
|
+
|
764
|
+
```ruby
|
765
|
+
Searchkick.search_method_name = :lookup
|
766
|
+
```
|
767
|
+
|
760
768
|
Eager load associations
|
761
769
|
|
762
770
|
```ruby
|
@@ -822,7 +830,7 @@ class Product < ActiveRecord::Base
|
|
822
830
|
end
|
823
831
|
```
|
824
832
|
|
825
|
-
Reindex all models
|
833
|
+
Reindex all models - Rails only
|
826
834
|
|
827
835
|
```sh
|
828
836
|
rake searchkick:reindex:all
|
data/gemfiles/mongoid4.gemfile
CHANGED
data/lib/searchkick.rb
CHANGED
@@ -6,7 +6,6 @@ require "searchkick/index"
|
|
6
6
|
require "searchkick/reindex"
|
7
7
|
require "searchkick/results"
|
8
8
|
require "searchkick/query"
|
9
|
-
require "searchkick/search"
|
10
9
|
require "searchkick/similar"
|
11
10
|
require "searchkick/model"
|
12
11
|
require "searchkick/tasks"
|
@@ -17,6 +16,11 @@ module Searchkick
|
|
17
16
|
class UnsupportedVersionError < StandardError; end
|
18
17
|
class InvalidQueryError < Elasticsearch::Transport::Transport::Errors::BadRequest; end
|
19
18
|
|
19
|
+
class << self
|
20
|
+
attr_accessor :search_method_name
|
21
|
+
end
|
22
|
+
self.search_method_name = :search
|
23
|
+
|
20
24
|
def self.client
|
21
25
|
@client ||= Elasticsearch::Client.new(url: ENV["ELASTICSEARCH_URL"])
|
22
26
|
end
|
data/lib/searchkick/model.rb
CHANGED
@@ -19,7 +19,14 @@ module Searchkick
|
|
19
19
|
Searchkick::Index.new(index)
|
20
20
|
end
|
21
21
|
|
22
|
-
|
22
|
+
define_singleton_method(Searchkick.search_method_name) do |term = nil, options={}|
|
23
|
+
query = Searchkick::Query.new(self, term, options)
|
24
|
+
if options[:execute] == false
|
25
|
+
query
|
26
|
+
else
|
27
|
+
query.execute
|
28
|
+
end
|
29
|
+
end
|
23
30
|
extend Searchkick::Reindex
|
24
31
|
include Searchkick::Similar
|
25
32
|
|
data/lib/searchkick/query.rb
CHANGED
@@ -228,7 +228,8 @@ module Searchkick
|
|
228
228
|
# order
|
229
229
|
if options[:order]
|
230
230
|
order = options[:order].is_a?(Enumerable) ? options[:order] : {options[:order] => :asc}
|
231
|
-
|
231
|
+
# TODO id transformation for arrays
|
232
|
+
payload[:sort] = order.is_a?(Array) ? order : Hash[ order.map{|k, v| [k.to_s == "id" ? :_id : k, v] } ]
|
232
233
|
end
|
233
234
|
|
234
235
|
# filters
|
data/lib/searchkick/results.rb
CHANGED
@@ -27,9 +27,14 @@ module Searchkick
|
|
27
27
|
records = records.includes(options[:includes])
|
28
28
|
end
|
29
29
|
results[type] =
|
30
|
-
if records.respond_to?(:primary_key)
|
30
|
+
if records.respond_to?(:primary_key) and records.primary_key
|
31
|
+
# ActiveRecord
|
31
32
|
records.where(records.primary_key => grouped_hits.map{|hit| hit["_id"] }).to_a
|
33
|
+
elsif records.respond_to?(:all) and records.all.respond_to?(:for_ids)
|
34
|
+
# Mongoid 2
|
35
|
+
records.all.for_ids(grouped_hits.map{|hit| hit["_id"] }).to_a
|
32
36
|
else
|
37
|
+
# Mongoid 3+
|
33
38
|
records.queryable.for_ids(grouped_hits.map{|hit| hit["_id"] }).to_a
|
34
39
|
end
|
35
40
|
end
|
data/lib/searchkick/similar.rb
CHANGED
data/lib/searchkick/version.rb
CHANGED
data/test/facets_test.rb
CHANGED
@@ -5,8 +5,8 @@ class TestFacets < Minitest::Unit::TestCase
|
|
5
5
|
def setup
|
6
6
|
super
|
7
7
|
store [
|
8
|
-
{name: "Product Show", latitude: 37.7833, longitude: 12.4167, store_id: 1, in_stock: true, color: "blue", price: 21},
|
9
|
-
{name: "Product Hide", latitude: 29.4167, longitude: -98.5000, store_id: 2, in_stock: false, color: "green", price: 25},
|
8
|
+
{name: "Product Show", latitude: 37.7833, longitude: 12.4167, store_id: 1, in_stock: true, color: "blue", price: 21, created_at: 2.days.ago},
|
9
|
+
{name: "Product Hide", latitude: 29.4167, longitude: -98.5000, store_id: 2, in_stock: false, color: "green", price: 25, created_at: 2.days.from_now},
|
10
10
|
{name: "Product B", latitude: 43.9333, longitude: -122.4667, store_id: 2, in_stock: false, color: "red", price: 5},
|
11
11
|
{name: "Foo", latitude: 43.9333, longitude: 12.4667, store_id: 3, in_stock: false, color: "yellow", price: 15}
|
12
12
|
]
|
@@ -39,6 +39,15 @@ class TestFacets < Minitest::Unit::TestCase
|
|
39
39
|
assert_equal 2, facet["ranges"][2]["count"]
|
40
40
|
end
|
41
41
|
|
42
|
+
def test_ranges_dates
|
43
|
+
ranges = [{to: 1.day.ago}, {from: 1.day.ago, to: 1.day.from_now}, {from: 1.day.from_now}]
|
44
|
+
facet = Product.search("Product", facets: {created_at: {ranges: ranges}}).facets["created_at"]
|
45
|
+
|
46
|
+
assert_equal 1, facet["ranges"][0]["count"]
|
47
|
+
assert_equal 1, facet["ranges"][1]["count"]
|
48
|
+
assert_equal 1, facet["ranges"][2]["count"]
|
49
|
+
end
|
50
|
+
|
42
51
|
def test_where_no_smart_facets
|
43
52
|
assert_equal ({2 => 2}), store_facet(where: {color: "red"}, facets: {store_id: {where: {in_stock: false}}})
|
44
53
|
end
|
data/test/sql_test.rb
CHANGED
@@ -205,6 +205,11 @@ class TestSql < Minitest::Unit::TestCase
|
|
205
205
|
assert_order "product", [], order: {not_mapped: {ignore_unmapped: true}}, conversions: false
|
206
206
|
end
|
207
207
|
|
208
|
+
def test_order_array
|
209
|
+
store [{name: "San Francisco", latitude: 37.7833, longitude: -122.4167}]
|
210
|
+
assert_order "francisco", ["San Francisco"], order: [{_geo_distance: {location: "0,0"}}], conversions: false
|
211
|
+
end
|
212
|
+
|
208
213
|
def test_partial
|
209
214
|
store_names ["Honey"]
|
210
215
|
assert_search "fresh honey", []
|
@@ -281,7 +286,21 @@ class TestSql < Minitest::Unit::TestCase
|
|
281
286
|
|
282
287
|
def test_select
|
283
288
|
store [{name: "Product A", store_id: 1}]
|
284
|
-
|
289
|
+
result = Product.search("product", load: false, select: [:name, :store_id]).first
|
290
|
+
assert_equal %w[id name store_id], result.keys.reject{|k| k.start_with?("_") }.sort
|
291
|
+
assert_equal ["Product A"], result.name # this is not great
|
292
|
+
end
|
293
|
+
|
294
|
+
def test_select_array
|
295
|
+
store [{name: "Product A", user_ids: [1, 2]}]
|
296
|
+
result = Product.search("product", load: false, select: [:user_ids]).first
|
297
|
+
assert_equal [1, 2], result.user_ids
|
298
|
+
end
|
299
|
+
|
300
|
+
def test_nested_object
|
301
|
+
aisle = {"id" => 1, "name" => "Frozen"}
|
302
|
+
store [{name: "Product A", aisle: aisle}]
|
303
|
+
assert_equal aisle, Product.search("product", load: false).first.aisle.to_hash
|
285
304
|
end
|
286
305
|
|
287
306
|
# TODO see if Mongoid is loaded
|
data/test/test_helper.rb
CHANGED
@@ -10,8 +10,28 @@ File.delete("elasticsearch.log") if File.exists?("elasticsearch.log")
|
|
10
10
|
Searchkick.client.transport.logger = Logger.new("elasticsearch.log")
|
11
11
|
|
12
12
|
if defined?(Mongoid)
|
13
|
+
|
14
|
+
def mongoid2?
|
15
|
+
Mongoid::VERSION.starts_with?("2.")
|
16
|
+
end
|
17
|
+
|
18
|
+
if mongoid2?
|
19
|
+
# enable comparison of BSON::ObjectIds
|
20
|
+
module BSON
|
21
|
+
class ObjectId
|
22
|
+
def <=>(other)
|
23
|
+
self.data <=> other.data
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
13
29
|
Mongoid.configure do |config|
|
14
|
-
|
30
|
+
if mongoid2?
|
31
|
+
config.master = Mongo::Connection.new.db("searchkick_test")
|
32
|
+
else
|
33
|
+
config.connect_to "searchkick_test"
|
34
|
+
end
|
15
35
|
end
|
16
36
|
|
17
37
|
class Product
|
@@ -121,10 +141,16 @@ class Product
|
|
121
141
|
word_middle: [:name],
|
122
142
|
word_end: [:name]
|
123
143
|
|
124
|
-
attr_accessor :conversions, :user_ids
|
144
|
+
attr_accessor :conversions, :user_ids, :aisle
|
125
145
|
|
126
146
|
def search_data
|
127
|
-
serializable_hash.except("id").merge
|
147
|
+
serializable_hash.except("id").merge(
|
148
|
+
conversions: conversions,
|
149
|
+
user_ids: user_ids,
|
150
|
+
location: [latitude, longitude],
|
151
|
+
multiple_locations: [[latitude, longitude], [0, 0]],
|
152
|
+
aisle: aisle
|
153
|
+
)
|
128
154
|
end
|
129
155
|
|
130
156
|
def should_index?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: searchkick
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -108,6 +108,7 @@ files:
|
|
108
108
|
- LICENSE.txt
|
109
109
|
- README.md
|
110
110
|
- Rakefile
|
111
|
+
- gemfiles/mongoid2.gemfile
|
111
112
|
- gemfiles/mongoid3.gemfile
|
112
113
|
- gemfiles/mongoid4.gemfile
|
113
114
|
- lib/searchkick.rb
|
@@ -179,3 +180,4 @@ test_files:
|
|
179
180
|
- test/suggest_test.rb
|
180
181
|
- test/synonyms_test.rb
|
181
182
|
- test/test_helper.rb
|
183
|
+
has_rdoc:
|