elastic-app-search 7.4.1 → 7.9.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: 6ad2aa4de4232586f616793b6f55332dde5d122fbe79ac5f80c62c42fa93bb07
4
- data.tar.gz: 5413783fa304ac1c71b317f982a20d4d2d35b2eb6782721df285dd9ce58eadb0
3
+ metadata.gz: efad053bb4bb7a4d9c0728b30859859d7c05dec002ca2be7db6b14fc9bf6d266
4
+ data.tar.gz: efed177fb0ac62bc23183b950bebf16236a7222ef933a698c1b66677ebc1d8c3
5
5
  SHA512:
6
- metadata.gz: 4896a9fb557f51ad81e44af96114d38463743781c777e93ff4b07d770b8cd941f48cb3cb5e7005a4282ea92d7859e8286bd1572152a10539bd50e63b07593b94
7
- data.tar.gz: b235d0390fcb69242ad2dc23e400d042ea33278cdcb8038b06b4c9f32b8aec7cc9ccbd6117aaa06301f7858a88696c020aa8fc1710f2237da493f64de1768f33
6
+ metadata.gz: e1bdab12e9e55db046f03b55ad263f56b59d70a48b959768c418961247bf7d91187531e74a007ec99ed0329c9d11574e6af21fa4426a8c5fb3f25282de008be4
7
+ data.tar.gz: a90180b52b7ad3a615fbb2d6bc9f89729893343b3a9a671067c8c02323b2e3959dcd081d03064db129927f550f16142424ec9b16e3198e01fe3898b35d3d4635
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  <p align="center"><a href="https://circleci.com/gh/elastic/app-search-ruby"><img src="https://circleci.com/gh/elastic/app-search-ruby.svg?style=svg" alt="CircleCI build"></a></p>
4
4
 
5
- > A first-party Ruby client for building excellent, relevant search experiences with Elastic App Search.
5
+ > A first-party Ruby client for building excellent, relevant search experiences with [Elastic App Search](https://www.elastic.co/products/app-search).
6
6
 
7
7
  ## Contents
8
8
 
@@ -25,7 +25,7 @@ To install the gem, execute:
25
25
  gem install elastic-app-search
26
26
  ```
27
27
 
28
- Or place `gem 'elastic-app-search', '~> 7.4.1'` in your `Gemfile` and run `bundle install`.
28
+ Or place `gem 'elastic-app-search', '~> 7.9.0'` in your `Gemfile` and run `bundle install`.
29
29
 
30
30
  ## Versioning
31
31
 
@@ -35,34 +35,37 @@ To guarantee compatibility, use the most recent version of this library within t
35
35
 
36
36
  For example, for App Search `7.3`, use `7.3` of this library or above, but not `8.0`.
37
37
 
38
- If you are a [SaaS](https://app.swiftype.com/as) user, simply use the most recent version of this library.
38
+ If you are using the [SaaS version available on swiftype.com](https://app.swiftype.com/as) of App Search, you should use the version 7.5.x of the client.
39
39
 
40
40
  ## Usage
41
41
 
42
- ### Setup: Configuring the client and authentication
42
+ #### Setup: Configuring the client and authentication
43
43
 
44
- Create a new instance of the Elastic App Search Client. This requires your `[HOST_IDENTIFIER]`, which
45
- identifies the unique hostname of the App Search API that is associated with your App Search account.
46
- It also requires a valid `[API_KEY]`, which authenticates requests to the API. You can use any key type with the client, however each has a different scope. For more information on keys, check out the [documentation](https://swiftype.com/documentation/app-search/credentials).
44
+ Using this client assumes that you have already an instance of [Elastic App Search](https://www.elastic.co/products/app-search) up and running.
47
45
 
48
- You can find your `[API_KEY]` and your `[HOST_IDENTIFIER]` within the [Credentials](https://app.swiftype.com/as/credentials) menu:
46
+ Once done, a client can be instantiated using the `[API_KEY]` and the `[API_ENDPOINT]` URL of your App Search setup:
49
47
 
50
48
  ```ruby
51
49
  require 'elastic-app-search'
52
50
 
53
- client = Elastic::AppSearch::Client.new(:host_identifier => 'host-c5s2mj', :api_key => 'private-mu75psc5egt9ppzuycnc2mc3')
51
+ client = Elastic::AppSearch::Client.new(:api_key => 'private-xxxxxxxxxxxxxxxxxxx', :api_endpoint => 'http://localhost:3002/api/as/v1/')
54
52
  ```
55
53
 
56
- ### Using with App Search Managed Deploys
54
+ Note:
57
55
 
58
- The client can be configured to use a managed deploy by using the
59
- `api_endpoint` parameter. Since managed deploys do not rely on a `[HOST_IDENTIFIER]`
60
- , it can be omitted.
56
+ The `[API_KEY]` authenticates requests to the API.
57
+ You can use any key type with the client, however each has a different scope.
58
+ For more information on keys, check out the [documentation](https://swiftype.com/documentation/app-search/api/credentials).
59
+
60
+ ##### Swiftype.com App Search users:
61
+
62
+ When using the [SaaS version available on swiftype.com](https://app.swiftype.com/as) of App Search, you can configure the client using your `[HOST_IDENTIFIER]` instead of the `[API_ENDPOINT]`.
63
+ The `[HOST_IDENTIFIER]` can be found within the [Credentials](https://app.swiftype.com/as#/credentials) menu.
61
64
 
62
65
  ```ruby
63
66
  require 'elastic-app-search'
64
67
 
65
- client = Elastic::AppSearch::Client.new(:api_key => 'private-mu75psc5egt9ppzuycnc2mc3', :api_endpoint => 'http://localhost:3002/api/as/v1/')
68
+ client = Elastic::AppSearch::Client.new(:host_identifier => 'host-c5s2mj', :api_key => 'private-xxxxxxxxxxxxxxxxxxx')
66
69
  ```
67
70
 
68
71
  ### API Methods
@@ -176,6 +179,33 @@ engine_name = 'favorite-videos'
176
179
  client.destroy_engine(engine_name)
177
180
  ```
178
181
 
182
+ #### Creating Meta Engines
183
+
184
+ ```ruby
185
+ engine_name = 'videos-engine'
186
+ sources_engines = ['favorite-videos', 'all-videos']
187
+
188
+ client.create_meta_engine(engine_name, source_engines)
189
+ ```
190
+
191
+ #### Adding Meta Engines Source
192
+
193
+ ```ruby
194
+ engine_name = 'videos-engine'
195
+ sources_engines = ['fun-videos', 'cat-videos']
196
+
197
+ client.add_meta_engine_sources(engine_name, source_engines)
198
+ ```
199
+
200
+ #### Adding Meta Engines Source
201
+
202
+ ```ruby
203
+ engine_name = 'videos-engine'
204
+ sources_engines = ['nsfw-videos']
205
+
206
+ client.delete_meta_engine_sources(engine_name, source_engines)
207
+ ```
208
+
179
209
  #### Searching
180
210
 
181
211
  ```ruby
@@ -277,6 +307,7 @@ Creating a search key that will only return the title field.
277
307
 
278
308
  ```ruby
279
309
  public_search_key = 'search-xxxxxxxxxxxxxxxxxxxxxxxx'
310
+ # This name must match the name of the key above from your App Search dashboard
280
311
  public_search_key_name = 'search-key'
281
312
  enforced_options = {
282
313
  result_fields: { title: { raw: {} } },
@@ -285,7 +316,8 @@ enforced_options = {
285
316
 
286
317
  signed_search_key = Elastic::AppSearch::Client.create_signed_search_key(public_search_key, public_search_key_name, enforced_options)
287
318
 
288
- client = Elastic::AppSearch::Client.new(host_identifier: 'host-c5s2mj', api_key: signed_search_key)
319
+ client = Elastic::AppSearch::Client.new(:api_key => signed_search_key, :api_endpoint => 'http://localhost:3002/api/as/v1/')
320
+
289
321
  client.search('national-parks-demo', 'everglade')
290
322
  ```
291
323
 
@@ -13,6 +13,7 @@ module Elastic
13
13
  autoload :Curations, 'elastic/app-search/client/curations'
14
14
  autoload :Documents, 'elastic/app-search/client/documents'
15
15
  autoload :Engines, 'elastic/app-search/client/engines'
16
+ autoload :MetaEngines, 'elastic/app-search/client/meta_engines'
16
17
  autoload :Logs, 'elastic/app-search/client/logs'
17
18
  autoload :Schema, 'elastic/app-search/client/schema'
18
19
  autoload :Search, 'elastic/app-search/client/search'
@@ -69,6 +70,7 @@ module Elastic
69
70
  include Elastic::AppSearch::Client::Curations
70
71
  include Elastic::AppSearch::Client::Documents
71
72
  include Elastic::AppSearch::Client::Engines
73
+ include Elastic::AppSearch::Client::MetaEngines
72
74
  include Elastic::AppSearch::Client::Logs
73
75
  include Elastic::AppSearch::Client::Schema
74
76
  include Elastic::AppSearch::Client::Search
@@ -0,0 +1,23 @@
1
+ module Elastic
2
+ module AppSearch
3
+ class Client
4
+ module MetaEngines
5
+
6
+ ENGINE_TYPE_META = 'meta'.freeze()
7
+
8
+ def create_meta_engine(engine_name, source_engines)
9
+ post('engines', :name => engine_name, :type => ENGINE_TYPE_META, :source_engines => source_engines)
10
+ end
11
+
12
+ def add_meta_engine_sources(engine_name, source_engines)
13
+ post("engines/#{engine_name}/source_engines", source_engines)
14
+ end
15
+
16
+ def delete_meta_engine_sources(engine_name, source_engines)
17
+ delete("engines/#{engine_name}/source_engines", source_engines)
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,5 +1,5 @@
1
1
  module Elastic
2
2
  module AppSearch
3
- VERSION = '7.4.1'
3
+ VERSION = '7.9.0'
4
4
  end
5
5
  end
@@ -27,17 +27,33 @@ describe Elastic::AppSearch::Client do
27
27
 
28
28
  describe 'Requests' do
29
29
  it 'should include client name and version in headers' do
30
- stub_request(:any, "#{client_options[:host_identifier]}.api.swiftype.com/api/as/v1/engines")
31
- client.list_engines
32
- expect(WebMock).to(
33
- have_requested(:get, "https://#{client_options[:host_identifier]}.api.swiftype.com/api/as/v1/engines")
34
- .with(
35
- :headers => {
36
- 'X-Swiftype-Client' => 'elastic-app-search-ruby',
37
- 'X-Swiftype-Client-Version' => Elastic::AppSearch::VERSION
38
- }
30
+ if (client_options[:api_endpoint])
31
+ stub_request(:any, "#{client_options[:api_endpoint]}engines")
32
+ client.list_engines
33
+ expect(WebMock).to(
34
+ have_requested(:get, "#{client_options[:api_endpoint]}engines")
35
+ .with(
36
+ :headers => {
37
+ 'X-Swiftype-Client' => 'elastic-app-search-ruby',
38
+ 'X-Swiftype-Client-Version' => Elastic::AppSearch::VERSION
39
+ }
40
+ )
39
41
  )
40
- )
42
+ else
43
+ # CI runs against saas, so we keep this around for now. CI should be updated
44
+ # to use slef-managed and we should drop support "host_identifier" this.
45
+ stub_request(:any, "#{client_options[:host_identifier]}.api.swiftype.com/api/as/v1/engines")
46
+ client.list_engines
47
+ expect(WebMock).to(
48
+ have_requested(:get, "https://#{client_options[:host_identifier]}.api.swiftype.com/api/as/v1/engines")
49
+ .with(
50
+ :headers => {
51
+ 'X-Swiftype-Client' => 'elastic-app-search-ruby',
52
+ 'X-Swiftype-Client-Version' => Elastic::AppSearch::VERSION
53
+ }
54
+ )
55
+ )
56
+ end
41
57
  end
42
58
  end
43
59
 
@@ -126,34 +126,5 @@ describe Elastic::AppSearch::Client::Documents do
126
126
  expect(response[1]['id']).to(eq(second_document_id))
127
127
  end
128
128
  end
129
-
130
- describe '#list_documents' do
131
- let(:documents) { [first_document, second_document] }
132
- let(:first_document_id) { 'id' }
133
- let(:first_document) { { 'id' => first_document_id, 'url' => 'https://www.youtube.com/watch?v=v1uyQZNg2vE' } }
134
- let(:second_document_id) { 'another_id' }
135
- let(:second_document) { { 'id' => second_document_id, 'url' => 'https://www.youtube.com/watch?v=9T1vfsHYiKY' } }
136
-
137
- before do
138
- client.index_documents(engine_name, documents)
139
- end
140
-
141
- context 'when no options are specified' do
142
- it 'will return all documents' do
143
- response = client.list_documents(engine_name)
144
- expect(response['results'].size).to(eq(2))
145
- expect(response['results'][0]['id']).to(eq(first_document_id))
146
- expect(response['results'][1]['id']).to(eq(second_document_id))
147
- end
148
- end
149
-
150
- context 'when options are specified' do
151
- it 'will return all documents' do
152
- response = client.list_documents(engine_name, :page => { :size => 1, :current => 2 })
153
- expect(response['results'].size).to(eq(1))
154
- expect(response['results'][0]['id']).to(eq(second_document_id))
155
- end
156
- end
157
- end
158
129
  end
159
130
  end
@@ -0,0 +1,25 @@
1
+ describe Elastic::AppSearch::Client::Documents do
2
+ include_context 'App Search Credentials'
3
+ include_context 'Static Test Engine'
4
+
5
+ let(:client) { Elastic::AppSearch::Client.new(client_options) }
6
+
7
+ context 'Documents' do
8
+ describe '#list_documents' do
9
+ context 'when no options are specified' do
10
+ it 'will return all documents' do
11
+ response = client.list_documents(engine_name)
12
+ expect(response['results'].size).to(eq(2))
13
+ expect(response['results'].map { |d| d['id'] }).to(include(document1['id'], document2['id']))
14
+ end
15
+ end
16
+
17
+ context 'when options are specified' do
18
+ it 'will return all documents' do
19
+ response = client.list_documents(engine_name, :page => { :size => 1, :current => 2 })
20
+ expect(response['results'].size).to(eq(1))
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,73 @@
1
+ describe Elastic::AppSearch::Client::MetaEngines do
2
+ include_context 'App Search Credentials'
3
+ include_context 'Engine Name'
4
+ include_context 'Meta Engine Name'
5
+ include_context 'Test Engine'
6
+
7
+ let(:client) { Elastic::AppSearch::Client.new(client_options) }
8
+ let(:source_engines) { [engine_name] }
9
+
10
+ # CI currently runs against SaaS. This feature is a Self-Managed only feature.
11
+ context 'Meta Engines', :skip => "Unable to test Self-Managed features in CI." do
12
+
13
+ after do
14
+ client.destroy_engine(meta_engine_name) rescue Elastic::AppSearch::NonExistentRecord
15
+ end
16
+
17
+ context '#create_meta_engine' do
18
+ it 'should create a meta engine when given a right set of parameters' do
19
+ expect { client.get_engine(meta_engine_name) }.to raise_error(Elastic::AppSearch::NonExistentRecord)
20
+ client.create_meta_engine(meta_engine_name, source_engines)
21
+ expect { client.get_engine(meta_engine_name) }.to_not raise_error
22
+ end
23
+
24
+ it 'should return a meta engine object' do
25
+ engine = client.create_meta_engine(meta_engine_name, source_engines)
26
+ expect(engine).to be_kind_of(Hash)
27
+ expect(engine['name']).to eq(meta_engine_name)
28
+ expect(engine['type']).to eq('meta')
29
+ expect(engine['source_engines']).to eq(source_engines)
30
+ end
31
+
32
+ it 'should return an error when the engine source engine is empty' do
33
+ expect { client.create_meta_engine(engine_name, []) }.to(raise_error) do |e|
34
+ expect(e).to be_a(Elastic::AppSearch::BadRequest)
35
+ expect(e.errors).to eq(['Source engines are required for meta engines'])
36
+ end
37
+ end
38
+ end
39
+
40
+ context '#add_meta_engine_sources' do
41
+ before do
42
+ client.create_meta_engine(meta_engine_name, source_engines)
43
+ client.delete_meta_engine_sources(meta_engine_name, source_engines)
44
+ end
45
+
46
+ it 'should add the source engine' do
47
+ expect { client.add_meta_engine_sources(meta_engine_name, source_engines) }.to_not raise_error do |engine|
48
+ expect(engine).to be_kind_of(Hash)
49
+ expect(engine['name']).to eq(meta_engine_name)
50
+ expect(engine['type']).to eq('meta')
51
+ expect(engine['source_engines']).to be_kind_of(Array)
52
+ expect(engine['source_engines']).to eq(source_engines)
53
+ end
54
+ end
55
+ end
56
+
57
+ context '#delete_meta_engine_sources' do
58
+ before do
59
+ client.create_meta_engine(meta_engine_name, source_engines)
60
+ end
61
+
62
+ it 'should remove the source engine' do
63
+ expect { client.delete_meta_engine_sources(meta_engine_name, source_engines) }.to_not raise_error do |engine|
64
+ expect(engine).to be_kind_of(Hash)
65
+ expect(engine['name']).to eq(meta_engine_name)
66
+ expect(engine['type']).to eq('meta')
67
+ expect(engine['source_engines']).to be_kind_of(Array)
68
+ expect(engine['source_engines']).to be_empty
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -54,6 +54,10 @@ RSpec.shared_context 'Engine Name' do
54
54
  let(:engine_name) { "ruby-client-test-#{SecureRandom.hex}" }
55
55
  end
56
56
 
57
+ RSpec.shared_context 'Meta Engine Name' do
58
+ let(:meta_engine_name) { "ruby-client-test-#{SecureRandom.hex}" }
59
+ end
60
+
57
61
  RSpec.shared_context 'Test Engine' do
58
62
  let(:engine_name) { "ruby-client-test-#{SecureRandom.hex}" }
59
63
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elastic-app-search
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.4.1
4
+ version: 7.9.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-10-09 00:00:00.000000000 Z
11
+ date: 2020-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -114,6 +114,7 @@ files:
114
114
  - lib/elastic/app-search/client/documents.rb
115
115
  - lib/elastic/app-search/client/engines.rb
116
116
  - lib/elastic/app-search/client/logs.rb
117
+ - lib/elastic/app-search/client/meta_engines.rb
117
118
  - lib/elastic/app-search/client/query_suggestion.rb
118
119
  - lib/elastic/app-search/client/schema.rb
119
120
  - lib/elastic/app-search/client/search.rb
@@ -134,7 +135,9 @@ files:
134
135
  - spec/documents_spec.rb
135
136
  - spec/engines_spec.rb
136
137
  - spec/exceptions_spec.rb
138
+ - spec/list_documents_spec.rb
137
139
  - spec/logs_spec.rb
140
+ - spec/meta_engines_spec.rb
138
141
  - spec/query_suggestion_spec.rb
139
142
  - spec/schema_spec.rb
140
143
  - spec/search_settings_spec.rb
@@ -160,8 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
163
  - !ruby/object:Gem::Version
161
164
  version: '0'
162
165
  requirements: []
163
- rubyforge_project:
164
- rubygems_version: 2.7.6
166
+ rubygems_version: 3.0.3
165
167
  signing_key:
166
168
  specification_version: 4
167
169
  summary: Official gem for accessing the Elastic App Search API
@@ -175,7 +177,9 @@ test_files:
175
177
  - spec/documents_spec.rb
176
178
  - spec/engines_spec.rb
177
179
  - spec/exceptions_spec.rb
180
+ - spec/list_documents_spec.rb
178
181
  - spec/logs_spec.rb
182
+ - spec/meta_engines_spec.rb
179
183
  - spec/query_suggestion_spec.rb
180
184
  - spec/schema_spec.rb
181
185
  - spec/search_settings_spec.rb