swiftype-app-search 0.5.0 → 0.6.0

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
  SHA256:
3
- metadata.gz: 8409dce98dbe9ef896e5cc4533cb6b2e6f320fc00b2e1d6d7091c9c1976f3d15
4
- data.tar.gz: f3fcbee95672e8a930c7b1f1d182b49b5391e9d843fcdf9875b4b3e26d8b2c0e
3
+ metadata.gz: 171ac3ad757cd4d799653d5db78110c6001cbb025059410b7b8f32e180aa26c4
4
+ data.tar.gz: 93d90fba2fed89c39847675520eb4a63d549e41ea63db578f979f7b81e398011
5
5
  SHA512:
6
- metadata.gz: 1f94fc9f964ebbba4e37401cd455a551116f9041b5aeba8b6caa56c3fb0bf0ba324f2dca3e434cff3717e9d444b3fa934e21d7a6cbb3401ee7e3f9527f8606a3
7
- data.tar.gz: 57d7533faa0660c2b542e1438f514e1aa22978bcd6de13af6d320d4d26f6c675b3cde2d5f3585cf4f7fa2595aeba2c75fe20da05fb1f3655af149110a6d96395
6
+ metadata.gz: 811715bd4df0576ac07213595464aed2cb989a32336c1d98c12c6b001e6c03f0cb5981dfbb8fb8bf5d919b4d6b44f9e192e83672d3b00ac6e2ca95c0abfaca26
7
+ data.tar.gz: a7ba625d89a1a681666dcf75180cf3ad4208990d15e49380f0b47e19846b79e8d9d5baa19ce3b288b004e05a4883e1ea98549c666b22c4033789925264369800
data/README.md CHANGED
@@ -25,7 +25,7 @@ To install the gem, execute:
25
25
  gem install swiftype-app-search
26
26
  ```
27
27
 
28
- Or place `gem 'swiftype-app-search', '~> 0.5.0'` in your `Gemfile` and run `bundle install`.
28
+ Or place `gem 'swiftype-app-search', '~> 0.6.0'` in your `Gemfile` and run `bundle install`.
29
29
 
30
30
  ## Usage
31
31
 
@@ -206,6 +206,59 @@ options = {
206
206
  client.query_suggestion(engine_name, 'cat', options)
207
207
  ```
208
208
 
209
+ #### Show Search Settings
210
+
211
+ ```ruby
212
+ engine_name = 'favorite-videos'
213
+
214
+ client.show_settings(engine_name)
215
+ ```
216
+
217
+ #### Update Search Settings
218
+
219
+ ```ruby
220
+ engine_name = 'favorite-videos'
221
+
222
+ settings = {
223
+ "search_fields" => {
224
+ "id" => {
225
+ "weight" => 1
226
+ },
227
+ "url" => {
228
+ "weight" => 1
229
+ },
230
+ "title" => {
231
+ "weight" => 1
232
+ },
233
+ "body" => {
234
+ "weight" => 1
235
+ },
236
+ },
237
+ "boosts" => {
238
+ "title" => [
239
+ {
240
+ "type" => "value",
241
+ "factor" => 9.5,
242
+ "operation" => "multiply",
243
+ "value" => [
244
+ "Titanic"
245
+ ]
246
+ }
247
+ ]
248
+ }
249
+ }
250
+
251
+ client.update_settings(engine_name, settings)
252
+ ```
253
+
254
+ #### Reset Search Settings
255
+
256
+ ```ruby
257
+ engine_name = 'favorite-videos'
258
+
259
+ client.reset_settings(engine_name)
260
+ ```
261
+
209
262
  ## Running Tests
210
263
 
211
264
  ```bash
@@ -0,0 +1,35 @@
1
+ # Search Settings is used to adjust weights and boosts
2
+ module SwiftypeAppSearch
3
+ class Client
4
+ module SearchSettings
5
+
6
+ # Show all Weights and Boosts applied to the search fields of an Engine.
7
+ #
8
+ # @param [String] engine_name the unique Engine name
9
+ #
10
+ # @return [Hash] current Search Settings
11
+ def show_settings(engine_name)
12
+ get("engines/#{engine_name}/search_settings")
13
+ end
14
+
15
+ # Update Weights or Boosts for search fields of an Engine.
16
+ #
17
+ # @param [String] engine_name the unique Engine name
18
+ # @param [Hash] settings new Search Settings Hash
19
+ #
20
+ # @return [Hash] new Search Settings
21
+ def update_settings(engine_name, settings)
22
+ put("engines/#{engine_name}/search_settings", settings)
23
+ end
24
+
25
+ # Reset Engine's Search Settings to default values.
26
+ #
27
+ # @param [String] engine_name the unique Engine name
28
+ #
29
+ # @return [Hash] default Search Settings
30
+ def reset_settings(engine_name)
31
+ post("engines/#{engine_name}/search_settings/reset")
32
+ end
33
+ end
34
+ end
35
+ end
@@ -10,6 +10,7 @@ module SwiftypeAppSearch
10
10
  autoload :Engines, 'swiftype-app-search/client/engines'
11
11
  autoload :Search, 'swiftype-app-search/client/search'
12
12
  autoload :QuerySuggestion, 'swiftype-app-search/client/query_suggestion'
13
+ autoload :SearchSettings, 'swiftype-app-search/client/search_settings'
13
14
 
14
15
  DEFAULT_TIMEOUT = 15
15
16
 
@@ -59,5 +60,6 @@ module SwiftypeAppSearch
59
60
  include SwiftypeAppSearch::Client::Search
60
61
  include SwiftypeAppSearch::Client::SignedSearchOptions
61
62
  include SwiftypeAppSearch::Client::QuerySuggestion
63
+ include SwiftypeAppSearch::Client::SearchSettings
62
64
  end
63
65
  end
@@ -1,3 +1,3 @@
1
1
  module SwiftypeAppSearch
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.0'
3
3
  end
data/spec/client_spec.rb CHANGED
@@ -353,6 +353,67 @@ describe SwiftypeAppSearch::Client do
353
353
  end
354
354
  end
355
355
 
356
+ context 'SearchSettings' do
357
+ let(:default_settings) { {
358
+ "search_fields" => {
359
+ "id" => {
360
+ "weight" => 1
361
+ }
362
+ },
363
+ "boosts" => {}
364
+ } }
365
+
366
+ let(:updated_settings) { {
367
+ "search_fields" => {
368
+ "id" => {
369
+ "weight" => 3
370
+ }
371
+ },
372
+ "boosts" => {}
373
+ } }
374
+
375
+ before(:each) do
376
+ client.create_engine(engine_name) rescue SwiftypeAppSearch::BadRequest
377
+ end
378
+
379
+ after(:each) do
380
+ client.destroy_engine(engine_name) rescue SwiftypeAppSearch::NonExistentRecord
381
+ end
382
+
383
+ describe '#show_settings' do
384
+ subject { client.show_settings(engine_name) }
385
+
386
+ it 'should return default settings' do
387
+ expect(subject).to match(default_settings)
388
+ end
389
+ end
390
+
391
+ describe '#update_settings' do
392
+ subject { client.show_settings(engine_name) }
393
+
394
+ before do
395
+ client.update_settings(engine_name, updated_settings)
396
+ end
397
+
398
+ it 'should update search settings' do
399
+ expect(subject).to match(updated_settings)
400
+ end
401
+ end
402
+
403
+ describe '#reset_settings' do
404
+ subject { client.show_settings(engine_name) }
405
+
406
+ before do
407
+ client.update_settings(engine_name, updated_settings)
408
+ client.reset_settings(engine_name)
409
+ end
410
+
411
+ it 'should reset search settings' do
412
+ expect(subject).to match(default_settings)
413
+ end
414
+ end
415
+ end
416
+
356
417
  context 'Engines' do
357
418
  after do
358
419
  client.destroy_engine(engine_name) rescue SwiftypeAppSearch::NonExistentRecord
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swiftype-app-search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Quin Hoxie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-05 00:00:00.000000000 Z
11
+ date: 2019-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -109,6 +109,7 @@ files:
109
109
  - lib/swiftype-app-search/client/engines.rb
110
110
  - lib/swiftype-app-search/client/query_suggestion.rb
111
111
  - lib/swiftype-app-search/client/search.rb
112
+ - lib/swiftype-app-search/client/search_settings.rb
112
113
  - lib/swiftype-app-search/exceptions.rb
113
114
  - lib/swiftype-app-search/request.rb
114
115
  - lib/swiftype-app-search/utils.rb