solidus_searchkick 0.2.2 → 0.2.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: 402dbdfb5175c200fedf8c9926fdc385722cf86c
4
- data.tar.gz: a254760c9d46d504dcc4d6d70b6d9419811069a6
3
+ metadata.gz: ca0b78287e2633baa26f6c7ddeff14b16dc00af3
4
+ data.tar.gz: 6b2053d60718e3636b27e2b40259cc74a03a084b
5
5
  SHA512:
6
- metadata.gz: 1c0bb2c7c15e09ddfd9b139c4d7caa2bcd78e3ca85f25262efc27835b25f53bfb6f64a182223c22ba4d48acab9edb65a8cd2e69d9af3fe2a837349347fdcd8d4
7
- data.tar.gz: 19a6df8d6d4a786b5df540f67ab9b491b21a0dd3d6ff387bb39c743035249d59115217ad629a4d6c215ebc2cfc29b47e05a869268e5b3d56a46d2e1fcb02a938
6
+ metadata.gz: a9a69a01475029299acc03e1b6df00f26a812404984b789271b4568c6698c8db787907681725383d3fc26b127530d389996a146d5e187d7a6683aec6d741f799
7
+ data.tar.gz: c90fb75cbd91aebb1e2b4124c81eb8e0d37ce4e31abc910ad0d4c40cc50ba22987aaecbca1812b9de5728f4183bd3bab78846d3f35b97b12a715cf4cfa87f956
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- solidus_searchkick (0.2.1)
4
+ solidus_searchkick (0.2.3)
5
5
  searchkick (~> 1.2)
6
6
  solidus (~> 1.4, >= 1.4.0)
7
7
 
@@ -30,7 +30,7 @@ GEM
30
30
  activejob (4.2.7.1)
31
31
  activesupport (= 4.2.7.1)
32
32
  globalid (>= 0.3.0)
33
- activemerchant (1.60.0)
33
+ activemerchant (1.62.0)
34
34
  activesupport (>= 3.2.14, < 5.1)
35
35
  builder (>= 2.1.2, < 4.0.0)
36
36
  i18n (>= 0.6.9)
@@ -50,8 +50,9 @@ GEM
50
50
  tzinfo (~> 1.1)
51
51
  acts_as_list (0.8.2)
52
52
  activerecord (>= 3.0)
53
- addressable (2.4.0)
54
- arel (6.0.3)
53
+ addressable (2.5.0)
54
+ public_suffix (~> 2.0, >= 2.0.2)
55
+ arel (6.0.4)
55
56
  awesome_nested_set (3.1.1)
56
57
  activerecord (>= 4.0.0, < 5.1)
57
58
  bcrypt (3.1.11)
@@ -94,10 +95,10 @@ GEM
94
95
  coffee-script (2.4.1)
95
96
  coffee-script-source
96
97
  execjs
97
- coffee-script-source (1.10.0)
98
+ coffee-script-source (1.12.2)
98
99
  colorize (0.8.1)
99
- concurrent-ruby (1.0.2)
100
- css_parser (1.4.5)
100
+ concurrent-ruby (1.0.4)
101
+ css_parser (1.4.7)
101
102
  addressable
102
103
  database_cleaner (1.5.3)
103
104
  debug_inspector (0.0.2)
@@ -116,25 +117,25 @@ GEM
116
117
  devise (>= 2.1.0)
117
118
  diff-lcs (1.2.5)
118
119
  docile (1.1.5)
119
- elasticsearch (2.0.0)
120
- elasticsearch-api (= 2.0.0)
121
- elasticsearch-transport (= 2.0.0)
122
- elasticsearch-api (2.0.0)
120
+ elasticsearch (5.0.0)
121
+ elasticsearch-api (= 5.0.0)
122
+ elasticsearch-transport (= 5.0.0)
123
+ elasticsearch-api (5.0.0)
123
124
  multi_json
124
- elasticsearch-transport (2.0.0)
125
+ elasticsearch-transport (5.0.0)
125
126
  faraday
126
127
  multi_json
127
128
  erubis (2.7.0)
128
129
  execjs (2.7.0)
129
130
  factory_girl (4.7.0)
130
131
  activesupport (>= 3.0.0)
131
- faraday (0.9.2)
132
+ faraday (0.10.1)
132
133
  multipart-post (>= 1.2, < 3)
133
- ffaker (2.2.0)
134
+ ffaker (2.4.0)
134
135
  ffi (1.9.14)
135
- font-awesome-rails (4.6.3.1)
136
+ font-awesome-rails (4.7.0.1)
136
137
  railties (>= 3.2, < 5.1)
137
- friendly_id (5.1.0)
138
+ friendly_id (5.2.0)
138
139
  activerecord (>= 4.0.0)
139
140
  globalid (0.3.7)
140
141
  activesupport (>= 4.1.0)
@@ -147,7 +148,7 @@ GEM
147
148
  highline (1.6.21)
148
149
  htmlentities (4.3.4)
149
150
  i18n (0.7.0)
150
- jquery-rails (4.2.1)
151
+ jquery-rails (4.2.2)
151
152
  rails-dom-testing (>= 1, < 3)
152
153
  railties (>= 4.2.0)
153
154
  thor (>= 0.14, < 2.0)
@@ -167,17 +168,16 @@ GEM
167
168
  mime-types-data (3.2016.0521)
168
169
  mimemagic (0.3.0)
169
170
  mini_portile2 (2.1.0)
170
- minitest (5.9.1)
171
- monetize (1.4.0)
171
+ minitest (5.10.1)
172
+ monetize (1.5.0)
172
173
  money (~> 6.7)
173
- money (6.7.1)
174
+ money (6.8.0)
174
175
  i18n (>= 0.6.4, <= 0.7.0)
175
176
  sixarm_ruby_unaccent (>= 1.1.1, < 2)
176
177
  multi_json (1.12.1)
177
178
  multipart-post (2.0.0)
178
- nokogiri (1.6.8)
179
+ nokogiri (1.6.8.1)
179
180
  mini_portile2 (~> 2.1.0)
180
- pkg-config (~> 1.1.7)
181
181
  orm_adapter (0.5.0)
182
182
  paperclip (4.3.7)
183
183
  activemodel (>= 3.2.0)
@@ -185,25 +185,25 @@ GEM
185
185
  cocaine (~> 0.5.5)
186
186
  mime-types
187
187
  mimemagic (= 0.3.0)
188
- paranoia (2.1.5)
189
- activerecord (~> 4.0)
190
- pkg-config (1.1.7)
188
+ paranoia (2.2.0)
189
+ activerecord (>= 4.0, < 5.1)
191
190
  polyamorous (1.3.1)
192
191
  activerecord (>= 3.0)
193
192
  polyglot (0.3.5)
194
193
  premailer (1.8.7)
195
194
  css_parser (>= 1.4.5)
196
195
  htmlentities (>= 4.0.0)
197
- premailer-rails (1.9.4)
196
+ premailer-rails (1.9.5)
198
197
  actionmailer (>= 3, < 6)
199
198
  premailer (~> 1.7, >= 1.7.9)
200
199
  pry (0.10.4)
201
200
  coderay (~> 1.1.0)
202
201
  method_source (~> 0.8.1)
203
202
  slop (~> 3.4)
203
+ public_suffix (2.0.5)
204
204
  rabl (0.11.8)
205
205
  activesupport (>= 2.3.14)
206
- rack (1.6.4)
206
+ rack (1.6.5)
207
207
  rack-test (0.6.3)
208
208
  rack (>= 1.0)
209
209
  rails (4.2.7.1)
@@ -219,9 +219,9 @@ GEM
219
219
  sprockets-rails
220
220
  rails-deprecated_sanitizer (1.0.3)
221
221
  activesupport (>= 4.2.0.alpha)
222
- rails-dom-testing (1.0.7)
222
+ rails-dom-testing (1.0.8)
223
223
  activesupport (>= 4.2.0.beta, < 5.0)
224
- nokogiri (~> 1.6.0)
224
+ nokogiri (~> 1.6)
225
225
  rails-deprecated_sanitizer (>= 1.0.1)
226
226
  rails-html-sanitizer (1.0.3)
227
227
  loofah (~> 2.0)
@@ -230,7 +230,7 @@ GEM
230
230
  activesupport (= 4.2.7.1)
231
231
  rake (>= 0.8.7)
232
232
  thor (>= 0.18.1, < 2.0)
233
- rake (11.3.0)
233
+ rake (12.0.0)
234
234
  ransack (1.8.2)
235
235
  actionpack (>= 3.0)
236
236
  activerecord (>= 3.0)
@@ -257,14 +257,14 @@ GEM
257
257
  rspec-support (~> 3.5.0)
258
258
  rspec-support (3.5.0)
259
259
  rubyzip (1.2.0)
260
- sass (3.4.22)
260
+ sass (3.4.23)
261
261
  sass-rails (5.0.6)
262
262
  railties (>= 4.0.0, < 6)
263
263
  sass (~> 3.1)
264
264
  sprockets (>= 2.8, < 4.0)
265
265
  sprockets-rails (>= 2.0, < 4.0)
266
266
  tilt (>= 1.1, < 3)
267
- searchkick (1.3.5)
267
+ searchkick (1.5.1)
268
268
  activemodel
269
269
  elasticsearch (>= 1)
270
270
  hashie
@@ -340,7 +340,7 @@ GEM
340
340
  solidus_core (= 1.4.0)
341
341
  solidus_sample (1.4.0)
342
342
  solidus_core (= 1.4.0)
343
- sprockets (3.7.0)
343
+ sprockets (3.7.1)
344
344
  concurrent-ruby (~> 1.0)
345
345
  rack (> 1, < 3)
346
346
  sprockets-rails (3.2.0)
@@ -356,13 +356,13 @@ GEM
356
356
  activerecord (>= 4.1, < 5.1)
357
357
  state_machines-activemodel (>= 0.3.0)
358
358
  stringex (1.5.1)
359
- thor (0.19.1)
359
+ thor (0.19.4)
360
360
  thread_safe (0.3.5)
361
361
  tilt (2.0.5)
362
362
  truncate_html (0.9.3)
363
- twitter_cldr (3.5.0)
363
+ twitter_cldr (3.6.0)
364
364
  camertron-eprun
365
- cldr-plurals-runtime-rb (~> 1.0.0)
365
+ cldr-plurals-runtime-rb (~> 1.0)
366
366
  tzinfo
367
367
  tzinfo (1.2.2)
368
368
  thread_safe (~> 0.1)
data/README.md CHANGED
@@ -3,17 +3,17 @@
3
3
  [![Test Coverage](https://codeclimate.com/github/elevatorup/solidus_searchkick/badges/coverage.svg)](https://codeclimate.com/github/elevatorup/solidus_searchkick/coverage)
4
4
 
5
5
  Solidus + Searchkick
6
- ===============
6
+ ====================
7
7
 
8
- Add [Elasticsearch](http://elastic.co) goodies to Solidus, powered by [searchkick](http://searchkick.org).
8
+ Add [Elasticsearch](http://elastic.co) to Solidus, powered by [searchkick](http://searchkick.org).
9
9
 
10
10
  Features
11
11
  --------
12
12
 
13
- * Full search (keyword, in_taxon)
14
- * Taxons Aggregations (aggs)
15
- * Search Autocomplete ([Typeahead](https://twitter.github.io/typeahead.js/))
16
-
13
+ * Search products by sku, name, description, taxon, and more out of the box.
14
+ * Customize the product search fields to your liking.
15
+ * Search Autocomplete by name out of the box ([Typeahead](https://twitter.github.io/typeahead.js/)).
16
+ * Product filtering based on ElasticSearch queries.
17
17
 
18
18
  Installation
19
19
  ------------
@@ -36,23 +36,83 @@ Installing solidus_searchkick will copy over a new `spree/shared/_filters.html.e
36
36
 
37
37
  [Install elasticsearch](https://www.elastic.co/downloads/elasticsearch)
38
38
 
39
- Implementation
40
- -------------
41
- Initially, you are started with a very basic filtering system which includes a price filter in order to show how the filtering works within elasticsearch. In order to add more filtering or change the price filtering, the following steps will need to be taken.
39
+ Searchkick Integration
40
+ ----------------------
41
+
42
+ By default, Searchkick is initialized on the Product model in SolidusSearchkick's `product_decorator` with:
43
+ ```
44
+ searchkick word_start: [:name]
45
+ ```
46
+
47
+ If you need to modify this, you can do so in your own `product_decorator`, by adding something like:
48
+ ```
49
+ # app/models/spree/product_decorator.rb
50
+ Spree::Product.class_eval do
51
+ searchkick word_start: [:name], callbacks: :async unless Spree::Product.try(:searchkick_options)
52
+ ...
53
+ end
54
+ ```
55
+ In this example, the `unless Spree::product.try(:searchkick_options)` conditional is needed, since, by default, the development environment does not cache classes and will reload them.
56
+ Adding this condition prevents Rails from throwing an error when reloading the product decorator and trying to add searchkick multiple times.
57
+
58
+
59
+ Search Parameters
60
+ -----------------
61
+
62
+ By default, only the `Spree::Product` class is indexed. The following items are indexed by default:
63
+ * name
64
+ * description
65
+ * available? (indexed as `active`)
66
+ * price (needed in order to return products that have price != nil)
67
+ * currency
68
+ * sku
69
+ * orders.complete.count (indexed as `conversions`)
70
+ * taxon_ids
71
+ * taxon_names
72
+
73
+ In order to control what data is indexed, override the `Spree::Product#search_data` method. Call `Spree::Product.reindex` after changing this method.
74
+
75
+ Filtering
76
+ ---------
77
+
78
+ Initially, you start with a very basic filtering system which includes a price filter in order to show how the filtering works with SolidusSearchkick and ElasticSearch. In order to add additional filters or change the price filter, the following steps will need to be taken:
42
79
 
43
80
  1. Copy the `Spree::Core::SearchkickFilters` file from this gem and place it in `lib/spree/core/`
81
+
44
82
  2. Add it to the config load path, or require it in an initializer, e.g...
45
83
  ```
46
84
  # config/initializers/spree.rb
47
85
  require 'spree/core/searchkick_filters'
48
86
  ```
49
- 3. Modify SearchKickFilters as needed.
50
87
 
51
- The `conds` for `SearchkickFilters` are similar to the `ProductFilters` in the default version of spree. Although the first parameters of each is still the label, the second item is the ElasticSerach DSL that will be used for that filter, eg... `{ range: { price: { lt: 1 } } }`
88
+ 3. Modify SearchkickFilters as needed.
89
+
90
+ The `conds` for `SearchkickFilters` are similar to the `ProductFilters` in the default version of spree/solidus. Although the first parameters of each is still the label, the second item is the ElasticSearch DSL that will be used for that filter, eg...
91
+
92
+ ```
93
+ conds = [
94
+ ...
95
+ [Spree.t(:under_price, price: format_price(1)), { range: { price: { lt: 1 } } }],
96
+ ...
97
+ ]
98
+ ```
99
+
100
+ 4. Ensure that `Spree::Taxon#applicable_filters` returns the filters you want:
101
+
102
+ ```
103
+ # app/models/spree/taxon_decorator.rb
104
+ def applicable_filters
105
+ filters = []
106
+ ...
107
+ filters << Spree::Core::SearchkickFilters.price_filter if Spree::Core::SearchkickFilters.respond_to?(:price_filter)
108
+ ...
109
+ filters
110
+ end
111
+ ```
52
112
 
53
113
  Autocomplete
54
- -------------
55
- SolidusSearchkick provides autocomplete for the `name` field of your products. In order to get this working, all you need to do is add the following lines to the corresponding files:
114
+ ------------
115
+ By default, SolidusSearchkick provides autocomplete for the `name` field of your products. In order to get this working, all you need to do is add the following lines to the corresponding files:
56
116
 
57
117
  application.js
58
118
  ```
@@ -67,30 +127,122 @@ application.css
67
127
 
68
128
  After that, automplete should now be working in the search box.
69
129
 
130
+ _**Note:** These requires are not added by the generator in order to give you the option to add Autocomplete instead of forcing it._
131
+
70
132
  Advanced Autocomplete
71
- -------------
72
- Documentation Coming Soon
133
+ ---------------------
134
+ The default autocomplete provided by solidus_searchkick is pretty basic.
73
135
 
74
- Options
75
- -------------
76
- Order
77
- Fields (example of overriding fields)
136
+ In order to modify how the autocomplete for your site works, you will first need to create a `product_decorator` if you do not already have one.
137
+ You will then need to override the `self.autocomplete` method in order to suit your needs. Take a look at the `self.autocomplete` method in the solidus_searchkick `product_decorator` to get started.
78
138
 
79
- Documentation
80
- -------------
139
+ ```
140
+ # app/models/spree/product_decorator.rb
141
+ Spree::Product.class_eval do
142
+ ...
143
+ def self.autocomplete(keywords)
144
+ ...
145
+ end
146
+ ...
147
+ end
148
+ ```
81
149
 
82
- By default, only the `Spree::Product` class is indexed. The following items are indexed by default:
83
- * name
84
- * description
85
- * available? (indexed as `active`)
86
- * price (needed in order to return products that have price != nil)
87
- * currency
88
- * sku
89
- * orders.complete.count (indexed as `conversions`)
90
- * taxon_ids
91
- * taxon_names
150
+ Searchkick Options
151
+ ------------------
152
+ Since SolidusSearchkick uses Searchkick to interact with ElasticSearch, it also accepts all of the Searchkick options.
153
+
154
+ You can specify a limit or offset when searching, as well as any other options provided by Searchkick.
155
+ In order to use the options, all you need to do is to pass a `searchkick_options` hash along with your search.
156
+
157
+ ```
158
+ searcher = build_searcher(params.deep_merge(searchkick_options: { limit: 6, offset: 100 }))
159
+ @products = searcher.retrieve_products
160
+ ```
161
+
162
+ OR
163
+
164
+ ```
165
+ search_params = {
166
+ search: {
167
+ price: {
168
+ gt: 100
169
+ }
170
+ },
171
+ searchkick_options: {
172
+ order: {
173
+ price: :asc
174
+ },
175
+ limit: 100
176
+ }
177
+ }
178
+
179
+ searcher = build_searcher(params.merge(search_params))
180
+ @products = searcher.retrieve_products
181
+ ```
92
182
 
93
- In order to control what data is indexed, override `Spree::Product#search_data` method. Call `Spree::Product.reindex` after changing this method.
183
+
184
+ ElasticSearch DSL
185
+ -----------------
186
+ There are times where even the power of Searchkick will not be enough to get you the results you need from ElasitcSearch.
187
+ In these cases, you can use the full power of the ElasticSearch DSL by passing in the `query` param.
188
+
189
+ ```
190
+ query = {
191
+ {
192
+ 'bool': {
193
+ 'must': [
194
+ { 'match': { 'name': 'Product 1'} }
195
+ ],
196
+ 'filter': [
197
+ { 'range': { 'available_on': { 'gte': '2015-01-01' }}}
198
+ ]
199
+ }
200
+ }
201
+ }
202
+
203
+ searcher = build_searcher(query: query)
204
+ @products = searcher.retrieve_products
205
+ ```
206
+
207
+
208
+ Overriding and Extending Default Methods
209
+ ----------------------------------------
210
+
211
+ By creating an initializer, you have the ability to override or extend any of the default methods provided by SolidusSearchkick.
212
+
213
+ ### Overriding a Default Method
214
+
215
+ In order to override a method, simply add that method to the initializer.
216
+
217
+ _(Take care when overriding methods, as you may loose some functionality if not careful)_
218
+ ```
219
+ # config/initializers/solidus_searchkick.rb
220
+ Spree::Search::Searchkick.class_eval do
221
+ def where_clause
222
+ # Default items for where_clause
223
+ where_clause = {
224
+ active: true
225
+ }
226
+ where_clause.merge!({taxon_ids: taxon.id}) if taxon
227
+
228
+ # Add search attributes from params[:search]
229
+ add_search_attributes(where_clause)
230
+ end
231
+ end
232
+ ```
233
+
234
+ ### Extending a Default Method
235
+
236
+ In order to extend a method, alias the original method, then call the aliased method when defining the new method.
237
+ ```
238
+ # config/initializers/solidus_searchkick.rb
239
+ Spree::Search::Searchkick.class_eval do
240
+ alias_method :original_where_clause, :where_clause
241
+ def where_clause
242
+ original_where_clause.merge(param1: param1, param2: param2)
243
+ end
244
+ end
245
+ ```
94
246
 
95
247
  Testing
96
248
  -------
@@ -112,6 +264,7 @@ require 'solidus_searchkick/factories'
112
264
  Copyright (c) 2016 Jim Smith, released under the New BSD License
113
265
 
114
266
 
267
+ Special Thanks
268
+ --------------
115
269
 
116
- TODO:
117
- Add in information about sorting (maybe even add in default sorting, and sorting template, along with sorting javascript)
270
+ SolidusSearchkick was heavily inspired by [spree_searchkick](https://github.com/ronzalo/spree_searchkick), which was used as a starting point to getting Solidus to work nicely with Searchkick.
@@ -3,7 +3,7 @@ Spree::Product.class_eval do
3
3
  Rails.application.config.after_initialize do
4
4
  # Check if searchkick_options have been set by the application using this gem
5
5
  # If they have, then do not initialize searchkick on the model. If they have not, then set the defaults
6
- searchkick autocomplete: [:name] unless Spree::Product.try(:searchkick_options)
6
+ searchkick word_start: [:name] unless Spree::Product.try(:searchkick_options)
7
7
  end
8
8
 
9
9
  def search_data
@@ -30,14 +30,18 @@ Spree::Product.class_eval do
30
30
  if keywords
31
31
  Spree::Product.search(
32
32
  keywords,
33
- autocomplete: true,
34
- limit: 10, where: search_where
33
+ fields: ['name^5'],
34
+ match: :word_start,
35
+ limit: 10,
36
+ load: false,
37
+ misspellings: { below: 3 },
38
+ where: search_where,
35
39
  ).map(&:name).map(&:strip).uniq
36
40
  else
37
41
  Spree::Product.search(
38
42
  '*',
39
43
  where: search_where
40
- ).map(&:name).map(&:strip)
44
+ ).map(&:name).map(&:strip).uniq
41
45
  end
42
46
  end
43
47
 
@@ -1,3 +1,3 @@
1
1
  module SolidusSearchkick
2
- VERSION = '0.2.2'
2
+ VERSION = '0.2.3'
3
3
  end
@@ -4,17 +4,5 @@ RSpec.describe Spree::ProductsController, type: :routing do
4
4
  describe 'routing' do
5
5
  routes { Spree::Core::Engine.routes }
6
6
  let(:taxon) { create(:taxon) }
7
-
8
- context 'best selling products' do
9
- it 'routes to #best_selling' do
10
- expect(get: best_path).to route_to(controller: 'spree/products', action: 'best_selling')
11
- end
12
- end
13
-
14
- context 'best selling products by taxon' do
15
- it 'routes to #create' do
16
- expect(get: best_selling_taxon_path(taxon.permalink)).to route_to(controller: 'spree/products', action: 'best_selling', id: taxon.permalink)
17
- end
18
- end
19
7
  end
20
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_searchkick
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-06 00:00:00.000000000 Z
11
+ date: 2017-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: solidus
@@ -289,7 +289,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
289
289
  requirements:
290
290
  - none
291
291
  rubyforge_project:
292
- rubygems_version: 2.5.0
292
+ rubygems_version: 2.5.1
293
293
  signing_key:
294
294
  specification_version: 4
295
295
  summary: Add searchkick to Solidus