elastic-app-search 7.5.0 → 7.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +44 -14
- data/lib/elastic/app-search/client.rb +2 -0
- data/lib/elastic/app-search/client/meta_engines.rb +23 -0
- data/lib/elastic/app-search/version.rb +1 -1
- data/spec/meta_engines_spec.rb +73 -0
- data/spec/spec_helper.rb +4 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1effdc4efc72a9c098033c0d8b034b40d1ed7e84a8f9ffc4b57cf1e684facdba
|
4
|
+
data.tar.gz: 4ed84fe6c73f2613009843a42bea47e1dc768c6a78ce2ef677febfdac049b017
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65e3675e3767ae71702ee73ddd440f5675dc881ebded19ec652bec8df6f2f0e327028f9d09169d3e070f488cb5175fc049bd8211445b02b659c59d39b8ad1118
|
7
|
+
data.tar.gz: 4b5e6ceaa5b122573daea52c08e704ad4f740dec458fc10a5b14bf414b1092ee0c61f31ba6c16deba58b97a4f99a97c0f23b7e3e3dad338157f7a9138103833c
|
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.
|
28
|
+
Or place `gem 'elastic-app-search', '~> 7.6.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
|
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
|
-
|
42
|
+
#### Setup: Configuring the client and authentication
|
43
43
|
|
44
|
-
|
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
|
-
|
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(:
|
51
|
+
client = Elastic::AppSearch::Client.new(:api_key => 'private-xxxxxxxxxxxxxxxxxxx', :api_endpoint => 'http://localhost:3002/api/as/v1/')
|
54
52
|
```
|
55
53
|
|
56
|
-
|
54
|
+
Note:
|
57
55
|
|
58
|
-
The
|
59
|
-
|
60
|
-
,
|
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/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/ascredentials) menu.
|
61
64
|
|
62
65
|
```ruby
|
63
66
|
require 'elastic-app-search'
|
64
67
|
|
65
|
-
client = Elastic::AppSearch::Client.new(:
|
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
|
@@ -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
|
@@ -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
|
data/spec/spec_helper.rb
CHANGED
@@ -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
|
+
version: 7.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:
|
11
|
+
date: 2020-02-13 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
|
@@ -135,6 +136,7 @@ files:
|
|
135
136
|
- spec/engines_spec.rb
|
136
137
|
- spec/exceptions_spec.rb
|
137
138
|
- spec/logs_spec.rb
|
139
|
+
- spec/meta_engines_spec.rb
|
138
140
|
- spec/query_suggestion_spec.rb
|
139
141
|
- spec/schema_spec.rb
|
140
142
|
- spec/search_settings_spec.rb
|
@@ -160,8 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
162
|
- !ruby/object:Gem::Version
|
161
163
|
version: '0'
|
162
164
|
requirements: []
|
163
|
-
|
164
|
-
rubygems_version: 2.7.6
|
165
|
+
rubygems_version: 3.0.6
|
165
166
|
signing_key:
|
166
167
|
specification_version: 4
|
167
168
|
summary: Official gem for accessing the Elastic App Search API
|
@@ -176,6 +177,7 @@ test_files:
|
|
176
177
|
- spec/engines_spec.rb
|
177
178
|
- spec/exceptions_spec.rb
|
178
179
|
- spec/logs_spec.rb
|
180
|
+
- spec/meta_engines_spec.rb
|
179
181
|
- spec/query_suggestion_spec.rb
|
180
182
|
- spec/schema_spec.rb
|
181
183
|
- spec/search_settings_spec.rb
|