searchkick 0.3.5 → 0.4.1

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: c8a8a68edbdd1ac1b03fc9fa7396391082a13a64
4
- data.tar.gz: 9933087ad09633fbb2b9b0607fc2ec591a62e35b
3
+ metadata.gz: 84aa6414f91ce1c76d0c247e9a11dfce4417c2ee
4
+ data.tar.gz: f072c08de08bac3808112ad165199b98b5b2e507
5
5
  SHA512:
6
- metadata.gz: edbfccd85651bbfb32c13a8c7de4ea15663cc0ff04fcc03969d7268d2c365b59e7272045541b116e9bb0234d8e5976190265d699d6549cc0a6710489927638f6
7
- data.tar.gz: eea0fe79ae6396f7c07769a3437640162ded10494600bc69179403e2f11609a9c24609c4eaa08dd287840328417d54323850657fd7791f51212aa287549e6993
6
+ metadata.gz: b866b6ba7f26bca01b13043c42ae1e9917b664be9bf77ce0c269dde30298fc8d2a08a54ce247dd465e500ebe8e122e804685ab4855984c1a09088b46422900e7
7
+ data.tar.gz: ab9bae0de9a80123cb85e0a34f221b6dce56efc91471c3037fbce10b2c7e284635291704965c1894c419e3b7610da8e1ffa4d83cde4a76039a530ef0b26e7407
data/.gitignore CHANGED
@@ -3,7 +3,7 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
- Gemfile.lock
6
+ *.lock
7
7
  InstalledFiles
8
8
  _yardoc
9
9
  coverage
data/.travis.yml CHANGED
@@ -4,6 +4,7 @@ rvm:
4
4
  - 2.0.0
5
5
  services:
6
6
  - elasticsearch
7
+ - mongodb
7
8
  script: bundle exec rake test
8
9
  before_script:
9
10
  - psql -c 'create database searchkick_test;' -U postgres
@@ -11,3 +12,7 @@ notifications:
11
12
  email:
12
13
  on_success: never
13
14
  on_failure: change
15
+ gemfile:
16
+ - Gemfile
17
+ - gemfiles/mongoid3.gemfile
18
+ - gemfiles/mongoid4.gemfile
data/CHANGELOG.md CHANGED
@@ -1,7 +1,16 @@
1
+ ## 0.4.1
2
+
3
+ - Fixed issue w/ inheritance mapping
4
+
5
+ ## 0.4.0
6
+
7
+ - Added support for Mongoid 4
8
+ - Added support for multiple locations
9
+
1
10
  ## 0.3.5
2
11
 
3
12
  - Added facet ranges
4
- - Add all operator
13
+ - Added all operator
5
14
 
6
15
  ## 0.3.4
7
16
 
data/Gemfile CHANGED
@@ -3,7 +3,5 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in searchkick.gemspec
4
4
  gemspec
5
5
 
6
- # gem "mongoid", github: "mongoid/mongoid"
7
- # gem "mongoid", "~> 3.1.0"
8
6
  # gem "activerecord", "~> 3.2.0"
9
7
  # gem "activerecord", "~> 3.1.0"
data/README.md CHANGED
@@ -446,6 +446,12 @@ Animal.search "*" # all animals
446
446
  Dog.search "*" # just dogs
447
447
  ```
448
448
 
449
+ **Note:** The `suggest` option retrieves suggestions from the parent at the moment.
450
+
451
+ ```ruby
452
+ Dog.search "airbudd", suggest: true # suggestions for all animals
453
+ ```
454
+
449
455
  ## Deployment
450
456
 
451
457
  Searchkick uses `ENV["ELASTICSEARCH_URL"]` for the Elasticsearch server. This defaults to `http://localhost:9200`.
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in searchkick.gemspec
4
+ gemspec path: "../"
5
+
6
+ gem "mongoid", "~> 3.1.0"
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in searchkick.gemspec
4
+ gemspec path: "../"
5
+
6
+ gem "mongoid", github: "mongoid/mongoid"
@@ -43,6 +43,9 @@ module Searchkick
43
43
  # stringify fields
44
44
  source = source.inject({}){|memo,(k,v)| memo[k.to_s] = v; memo}
45
45
 
46
+ # Mongoid 4 hack
47
+ source["_id"] = source["_id"].to_s if source["_id"]
48
+
46
49
  options = self.class.searchkick_options
47
50
 
48
51
  # conversions
@@ -58,7 +61,13 @@ module Searchkick
58
61
 
59
62
  # locations
60
63
  (options[:locations] || []).map(&:to_s).each do |field|
61
- source[field] = source[field].map(&:to_f).reverse if source[field]
64
+ if source[field]
65
+ if source[field].first.is_a?(Array) # array of arrays
66
+ source[field] = source[field].map{|a| a.map(&:to_f).reverse }
67
+ else
68
+ source[field] = source[field].map(&:to_f).reverse
69
+ end
70
+ end
62
71
  end
63
72
 
64
73
  # change all BigDecimal values to floats due to
@@ -84,6 +93,8 @@ module Searchkick
84
93
 
85
94
  cast_big_decimal.call(source)
86
95
 
96
+ # p search_data
97
+
87
98
  source.to_json
88
99
  end
89
100
 
@@ -35,6 +35,8 @@ module Searchkick
35
35
  searchkick_import(index) # import after swap
36
36
  end
37
37
 
38
+ index.refresh
39
+
38
40
  true
39
41
  end
40
42
 
@@ -223,7 +225,7 @@ module Searchkick
223
225
  end
224
226
 
225
227
  mappings = {
226
- searchkick_klass.document_type.to_sym => {
228
+ _default_: {
227
229
  properties: mapping,
228
230
  # https://gist.github.com/kimchy/2898285
229
231
  dynamic_templates: [
@@ -161,6 +161,8 @@ module Searchkick
161
161
  proc do |where|
162
162
  filters = []
163
163
  (where || {}).each do |field, value|
164
+ field = :_id if field.to_s == "id"
165
+
164
166
  if field == :or
165
167
  value.each do |or_clause|
166
168
  filters << {or: or_clause.map{|or_statement| {and: where_filters.call(or_statement)} }}
@@ -325,7 +327,7 @@ module Searchkick
325
327
  status_code = e.message[0..3].to_i
326
328
  if status_code == 404
327
329
  raise "Index missing - run #{searchkick_klass.name}.reindex"
328
- elsif status_code == 500 and e.message.include?("IllegalArgumentException[minimumSimilarity >= 1]")
330
+ elsif status_code == 500 and (e.message.include?("IllegalArgumentException[minimumSimilarity >= 1]") or e.message.include?("No query registered for [multi_match]"))
329
331
  raise "Upgrade Elasticsearch to 0.90.0 or greater"
330
332
  else
331
333
  raise e
@@ -9,7 +9,7 @@ module Searchkick
9
9
  # TODO deep merge method
10
10
  options[:where] ||= {}
11
11
  options[:where][:_id] ||= {}
12
- options[:where][:_id][:not] = id
12
+ options[:where][:_id][:not] = id.to_s
13
13
  options[:limit] ||= 10
14
14
  options[:similar] = true
15
15
  self.class.search(like_text, options)
@@ -1,3 +1,3 @@
1
1
  module Searchkick
2
- VERSION = "0.3.5"
2
+ VERSION = "0.4.1"
3
3
  end
data/searchkick.gemspec CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.3"
25
25
  spec.add_development_dependency "rake"
26
- spec.add_development_dependency "minitest"
26
+ spec.add_development_dependency "minitest", "~> 4.7"
27
27
  spec.add_development_dependency "activerecord"
28
28
  spec.add_development_dependency "pg"
29
29
  end
@@ -30,4 +30,28 @@ class TestInheritance < Minitest::Unit::TestCase
30
30
  assert_equal 2, Animal.search("bear").size
31
31
  end
32
32
 
33
+ def test_child_autocomplete
34
+ store_names ["Max"], Cat
35
+ store_names ["Mark"], Dog
36
+ assert_equal ["Max"], Cat.search("ma", fields: [:name], autocomplete: true).map(&:name)
37
+ end
38
+
39
+ def test_parent_autocomplete
40
+ store_names ["Max"], Cat
41
+ store_names ["Bear"], Dog
42
+ assert_equal ["Bear"], Animal.search("bea", fields: [:name], autocomplete: true).map(&:name).sort
43
+ end
44
+
45
+ # def test_child_suggest
46
+ # store_names ["Shark"], Cat
47
+ # store_names ["Sharp"], Dog
48
+ # assert_equal ["shark"], Cat.search("shar", fields: [:name], suggest: true).suggestions
49
+ # end
50
+
51
+ def test_parent_suggest
52
+ store_names ["Shark"], Cat
53
+ store_names ["Tiger"], Dog
54
+ assert_equal ["tiger"], Animal.search("tige", fields: [:name], suggest: true).suggestions.sort
55
+ end
56
+
33
57
  end
data/test/sql_test.rb CHANGED
@@ -87,7 +87,7 @@ class TestSql < Minitest::Unit::TestCase
87
87
  def test_where_id
88
88
  store_names ["Product A"]
89
89
  product = Product.last
90
- assert_search "product", ["Product A"], where: {id: product.id}
90
+ assert_search "product", ["Product A"], where: {id: product.id.to_s}
91
91
  end
92
92
 
93
93
  def test_near
@@ -115,6 +115,14 @@ class TestSql < Minitest::Unit::TestCase
115
115
  assert_search "san", ["San Francisco"], where: {location: {top_left: [38, -123], bottom_right: [37, -122]}}
116
116
  end
117
117
 
118
+ def test_multiple_locations
119
+ store [
120
+ {name: "San Francisco", latitude: 37.7833, longitude: -122.4167},
121
+ {name: "San Antonio", latitude: 29.4167, longitude: -98.5000}
122
+ ]
123
+ assert_search "san", ["San Francisco"], where: {multiple_locations: {near: [37.5, -122.5]}}
124
+ end
125
+
118
126
  def test_order_hash
119
127
  store_names ["Product A", "Product B", "Product C", "Product D"]
120
128
  assert_order "product", ["Product D", "Product C", "Product B", "Product A"], order: {name: :desc}
@@ -186,9 +194,12 @@ class TestSql < Minitest::Unit::TestCase
186
194
  assert_kind_of Tire::Results::Item, Product.search("product", load: false, include: [:store]).first
187
195
  end
188
196
 
189
- def test_include
190
- store_names ["Product A"]
191
- assert Product.search("product", include: [:store]).first.association(:store).loaded?
197
+ # TODO see if Mongoid is loaded
198
+ if !defined?(Mongoid)
199
+ def test_include
200
+ store_names ["Product A"]
201
+ assert Product.search("product", include: [:store]).first.association(:store).loaded?
202
+ end
192
203
  end
193
204
 
194
205
  end
data/test/test_helper.rb CHANGED
@@ -11,14 +11,24 @@ Tire.configure do
11
11
  pretty true
12
12
  end
13
13
 
14
- if ENV["MONGOID"]
14
+ if defined?(Mongoid)
15
15
  Mongoid.configure do |config|
16
16
  config.connect_to "searchkick_test"
17
17
  end
18
18
 
19
19
  class Product
20
20
  include Mongoid::Document
21
- # include Mongoid::Attributes::Dynamic
21
+ include Mongoid::Timestamps
22
+
23
+ field :name
24
+ field :store_id, type: Integer
25
+ field :in_stock, type: Boolean
26
+ field :backordered, type: Boolean
27
+ field :orders_count, type: Integer
28
+ field :price, type: Integer
29
+ field :color
30
+ field :latitude, type: BigDecimal
31
+ field :longitude, type: BigDecimal
22
32
  end
23
33
 
24
34
  class Store
@@ -27,6 +37,8 @@ if ENV["MONGOID"]
27
37
 
28
38
  class Animal
29
39
  include Mongoid::Document
40
+
41
+ field :name
30
42
  end
31
43
 
32
44
  class Dog < Animal
@@ -100,17 +112,17 @@ class Product
100
112
  suggest: [:name, :color],
101
113
  conversions: "conversions",
102
114
  personalize: "user_ids",
103
- locations: ["location"]
115
+ locations: ["location", "multiple_locations"]
104
116
 
105
117
  attr_accessor :conversions, :user_ids
106
118
 
107
119
  def search_data
108
- attributes.merge conversions: conversions, user_ids: user_ids, location: [latitude, longitude]
120
+ serializable_hash.merge conversions: conversions, user_ids: user_ids, location: [latitude, longitude], multiple_locations: [[latitude, longitude], [0, 0]]
109
121
  end
110
122
  end
111
123
 
112
124
  class Animal
113
- searchkick
125
+ searchkick autocomplete: [:name], suggest: [:name]
114
126
  end
115
127
 
116
128
  Product.searchkick_index.delete if Product.searchkick_index.exists?
@@ -119,7 +131,7 @@ Product.reindex # run twice for both index paths
119
131
 
120
132
  Animal.reindex
121
133
 
122
- class MiniTest::Unit::TestCase
134
+ class Minitest::Unit::TestCase
123
135
 
124
136
  def setup
125
137
  Product.destroy_all
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.3.5
4
+ version: 0.4.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: 2013-12-08 00:00:00.000000000 Z
11
+ date: 2013-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tire
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: minitest
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ~>
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: '4.7'
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
- version: '0'
82
+ version: '4.7'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: activerecord
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +122,8 @@ files:
122
122
  - LICENSE.txt
123
123
  - README.md
124
124
  - Rakefile
125
+ - gemfiles/mongoid3.gemfile
126
+ - gemfiles/mongoid4.gemfile
125
127
  - lib/searchkick.rb
126
128
  - lib/searchkick/logger.rb
127
129
  - lib/searchkick/model.rb