elastic-app-search 7.4.0 → 7.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.
@@ -0,0 +1,23 @@
1
+ describe Elastic::AppSearch::Client::Schema do
2
+ include_context 'App Search Credentials'
3
+ include_context 'Test Engine'
4
+
5
+ let(:client) { Elastic::AppSearch::Client.new(client_options) }
6
+
7
+ context '#get_schema' do
8
+ before { client.update_schema(engine_name, 'title' => 'text') }
9
+ subject { client.get_schema(engine_name) }
10
+
11
+ it 'will retrieve a schema' do
12
+ expect(subject).to(eq('title' => 'text'))
13
+ end
14
+ end
15
+
16
+ context '#update_schema' do
17
+ subject { client.update_schema(engine_name, 'square_km' => 'number') }
18
+
19
+ it 'will update a schema' do
20
+ expect(subject).to(eq('square_km' => 'number'))
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,65 @@
1
+ describe Elastic::AppSearch::Client::SearchSettings do
2
+ include_context 'App Search Credentials'
3
+ include_context 'Test Engine'
4
+
5
+ let(:client) { Elastic::AppSearch::Client.new(client_options) }
6
+
7
+ context 'SearchSettings' do
8
+ let(:default_settings) do
9
+ {
10
+ 'search_fields' => {
11
+ 'id' => {
12
+ 'weight' => 1
13
+ }
14
+ },
15
+ 'result_fields' => { 'id' => { 'raw' => {} } },
16
+ 'boosts' => {}
17
+ }
18
+ end
19
+
20
+ let(:updated_settings) do
21
+ {
22
+ 'search_fields' => {
23
+ 'id' => {
24
+ 'weight' => 3
25
+ }
26
+ },
27
+ 'result_fields' => { 'id' => { 'raw' => {} } },
28
+ 'boosts' => {}
29
+ }
30
+ end
31
+
32
+ describe '#show_settings' do
33
+ subject { client.show_settings(engine_name) }
34
+
35
+ it 'should return default settings' do
36
+ expect(subject).to(match(default_settings))
37
+ end
38
+ end
39
+
40
+ describe '#update_settings' do
41
+ subject { client.show_settings(engine_name) }
42
+
43
+ before do
44
+ client.update_settings(engine_name, updated_settings)
45
+ end
46
+
47
+ it 'should update search settings' do
48
+ expect(subject).to(match(updated_settings))
49
+ end
50
+ end
51
+
52
+ describe '#reset_settings' do
53
+ subject { client.show_settings(engine_name) }
54
+
55
+ before do
56
+ client.update_settings(engine_name, updated_settings)
57
+ client.reset_settings(engine_name)
58
+ end
59
+
60
+ it 'should reset search settings' do
61
+ expect(subject).to(match(default_settings))
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,96 @@
1
+ describe Elastic::AppSearch::Client::Search 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 'Search' do
8
+ describe '#search' do
9
+ subject { client.search(engine_name, query, options) }
10
+ let(:query) { '' }
11
+ let(:options) { { 'page' => { 'size' => 2 } } }
12
+
13
+ it 'should execute a search query' do
14
+ expected = {
15
+ 'meta' => anything,
16
+ 'results' => [anything, anything]
17
+ }
18
+ expect(subject).to(match(expected))
19
+ end
20
+ end
21
+
22
+ describe '#multi_search' do
23
+ subject { client.multi_search(engine_name, queries) }
24
+
25
+ context 'when options are provided' do
26
+ let(:queries) do
27
+ [
28
+ { 'query' => 'gatsby', 'options' => { 'page' => { 'size' => 1 } } },
29
+ { 'query' => 'catcher', 'options' => { 'page' => { 'size' => 1 } } }
30
+ ]
31
+ end
32
+
33
+ it 'should execute a multi search query' do
34
+ response = subject
35
+ expected = [
36
+ {
37
+ 'meta' => anything,
38
+ 'results' => [{ 'id' => { 'raw' => '1' }, 'title' => anything, '_meta' => anything }]
39
+ },
40
+ {
41
+ 'meta' => anything,
42
+ 'results' => [{ 'id' => { 'raw' => '2' }, 'title' => anything, '_meta' => anything }]
43
+ }
44
+ ]
45
+ expect(response).to(match(expected))
46
+ end
47
+ end
48
+
49
+ context 'when options are omitted' do
50
+ let(:queries) do
51
+ [
52
+ { 'query' => 'gatsby' },
53
+ { 'query' => 'catcher' }
54
+ ]
55
+ end
56
+
57
+ it 'should execute a multi search query' do
58
+ response = subject
59
+ expected = [
60
+ {
61
+ 'meta' => anything,
62
+ 'results' => [{ 'id' => { 'raw' => '1' }, 'title' => anything, '_meta' => anything }]
63
+ },
64
+ {
65
+ 'meta' => anything,
66
+ 'results' => [{ 'id' => { 'raw' => '2' }, 'title' => anything, '_meta' => anything }]
67
+ }
68
+ ]
69
+
70
+ expect(response).to(match(expected))
71
+ end
72
+ end
73
+
74
+ context 'when a search is bad' do
75
+ let(:queries) do
76
+ [
77
+ {
78
+ 'query' => 'cat',
79
+ 'options' => { 'search_fields' => { 'taco' => {} } }
80
+ }, {
81
+ 'query' => 'dog',
82
+ 'options' => { 'search_fields' => { 'body' => {} } }
83
+ }
84
+ ]
85
+ end
86
+
87
+ it 'should throw an appropriate error' do
88
+ expect { subject }.to(raise_error) do |e|
89
+ expect(e).to(be_a(Elastic::AppSearch::BadRequest))
90
+ expect(e.errors).to(eq(['Search fields contains invalid field: taco', 'Search fields contains invalid field: body']))
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -4,9 +4,68 @@ require 'webmock/rspec'
4
4
  require 'awesome_print'
5
5
  require 'elastic/app-search'
6
6
  require 'config_helper'
7
+ require 'securerandom'
7
8
 
8
9
  WebMock.allow_net_connect!
9
10
 
11
+ #
12
+ # Uses a static engine that will not change between tests. It comes preloaded
13
+ # with documents that *are already indexed*. This means tests can run operations
14
+ # that require documents to be indexed, like "search".
15
+ #
16
+ # This is optimal for tests that perform read-only operations, like "search".
17
+ #
18
+ RSpec.shared_context 'Static Test Engine' do
19
+ before(:all) do
20
+ @static_engine_name = "ruby-client-test-static-#{SecureRandom.hex}"
21
+ as_api_key = ConfigHelper.get_as_api_key
22
+ as_host_identifier = ConfigHelper.get_as_host_identifier
23
+ as_api_endpoint = ConfigHelper.get_as_api_endpoint
24
+ client_options = ConfigHelper.get_client_options(as_api_key, as_host_identifier, as_api_endpoint)
25
+ @static_client = Elastic::AppSearch::Client.new(client_options)
26
+ @static_client.create_engine(@static_engine_name)
27
+
28
+ @document1 = { 'id' => '1', 'title' => 'The Great Gatsby' }
29
+ @document2 = { 'id' => '2', 'title' => 'Catcher in the Rye' }
30
+ @documents = [@document1, @document2]
31
+ @static_client.index_documents(@static_engine_name, @documents)
32
+
33
+ # Wait until documents are indexed
34
+ start = Time.now
35
+ ready = false
36
+ until (ready)
37
+ sleep(3)
38
+ results = @static_client.search(@static_engine_name, '')
39
+ ready = true if results['results'].length == 2
40
+ ready = true if (Time.now - start).to_i >= 120 # Time out after 2 minutes
41
+ end
42
+ end
43
+
44
+ let(:engine_name) { @static_engine_name }
45
+ let(:document1) { @document1 }
46
+ let(:document2) { @document2 }
47
+
48
+ after(:all) do
49
+ @static_client.destroy_engine(@static_engine_name)
50
+ end
51
+ end
52
+
53
+ RSpec.shared_context 'Engine Name' do
54
+ let(:engine_name) { "ruby-client-test-#{SecureRandom.hex}" }
55
+ end
56
+
57
+ RSpec.shared_context 'Test Engine' do
58
+ let(:engine_name) { "ruby-client-test-#{SecureRandom.hex}" }
59
+
60
+ before(:each) do
61
+ client.create_engine(engine_name) rescue Elastic::AppSearch::BadRequest
62
+ end
63
+
64
+ after(:each) do
65
+ client.destroy_engine(engine_name) rescue Elastic::AppSearch::NonExistentRecord
66
+ end
67
+ end
68
+
10
69
  RSpec.shared_context 'App Search Credentials' do
11
70
  let(:as_api_key) { ConfigHelper.get_as_api_key }
12
71
  # AS_ACCOUNT_HOST_KEY is deprecated
@@ -17,6 +76,16 @@ RSpec.shared_context 'App Search Credentials' do
17
76
  end
18
77
  end
19
78
 
79
+ RSpec.shared_context 'App Search Admin Credentials' do
80
+ let(:as_api_key) { ConfigHelper.get_as_admin_key }
81
+ # AS_ACCOUNT_HOST_KEY is deprecated
82
+ let(:as_host_identifier) { ConfigHelper.get_as_host_identifier }
83
+ let(:as_api_endpoint) { ConfigHelper.get_as_api_endpoint }
84
+ let(:client_options) do
85
+ ConfigHelper.get_client_options(as_api_key, as_host_identifier, as_api_endpoint)
86
+ end
87
+ end
88
+
20
89
  RSpec.configure do |config|
21
90
  # Run specs in random order to surface order dependencies. If you find an
22
91
  # order dependency and want to debug it, you can fix the order by providing
@@ -0,0 +1,65 @@
1
+ describe Elastic::AppSearch::Client::Synonyms do
2
+ include_context 'App Search Credentials'
3
+ include_context 'Test Engine'
4
+
5
+ let(:client) { Elastic::AppSearch::Client.new(client_options) }
6
+
7
+ context '#create_synonym_set' do
8
+ let(:synonyms) { ['park', 'trail'] }
9
+ subject { client.create_synonym_set(engine_name, :synonyms => synonyms) }
10
+
11
+ it 'will create a synonym' do
12
+ expect(subject['id']).not_to(be_empty)
13
+ expect(subject['synonyms']).to(eq(synonyms))
14
+ end
15
+ end
16
+
17
+ context '#get_synonym_set' do
18
+ let(:synonyms) { ['park', 'trail'] }
19
+ let(:synonym_set_id) { client.create_synonym_set(engine_name, :synonyms => synonyms)['id'] }
20
+
21
+ subject { client.get_synonym_set(engine_name, synonym_set_id) }
22
+
23
+ it 'will retrieve a synonym set' do
24
+ expect(subject['id']).to(eq(synonym_set_id))
25
+ expect(subject['synonyms']).to(eq(synonyms))
26
+ end
27
+ end
28
+
29
+ context '#update_synonym_set' do
30
+ let(:synonyms) { ['park', 'trail'] }
31
+ let(:updated_synonyms) { %w[park trail system] }
32
+ let(:synonym_set_id) { client.create_synonym_set(engine_name, :synonyms => synonyms)['id'] }
33
+
34
+ subject { client.update_synonym_set(engine_name, synonym_set_id, :synonyms => updated_synonyms) }
35
+
36
+ it 'will update a synonym set' do
37
+ expect(subject['id']).to(eq(synonym_set_id))
38
+ expect(subject['synonyms']).to(eq(updated_synonyms))
39
+ end
40
+ end
41
+
42
+ context '#list_synonym_sets' do
43
+ subject { client.list_synonym_sets(engine_name, :current => 2, :size => 10) }
44
+
45
+ it 'will list synonyms' do
46
+ expect(subject['results']).to(eq([]))
47
+ end
48
+
49
+ it 'support paging params' do
50
+ expect(subject['meta']['page']['current']).to(eq(2))
51
+ expect(subject['meta']['page']['size']).to(eq(10))
52
+ end
53
+ end
54
+
55
+ context '#destroy_synonym_set' do
56
+ let(:synonyms) { ['park', 'trail'] }
57
+ let(:synonym_set_id) { client.create_synonym_set(engine_name, :synonyms => synonyms)['id'] }
58
+
59
+ subject { client.destroy_synonym_set(engine_name, synonym_set_id) }
60
+
61
+ it 'will delete a synonym set' do
62
+ expect(subject['deleted']).to(eq(true))
63
+ end
64
+ end
65
+ end
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.0
4
+ version: 7.4.1
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-01 00:00:00.000000000 Z
11
+ date: 2019-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -107,21 +107,40 @@ files:
107
107
  - lib/elastic-app-search.rb
108
108
  - lib/elastic/app-search.rb
109
109
  - lib/elastic/app-search/client.rb
110
+ - lib/elastic/app-search/client/analytics.rb
111
+ - lib/elastic/app-search/client/click.rb
112
+ - lib/elastic/app-search/client/credentials.rb
113
+ - lib/elastic/app-search/client/curations.rb
110
114
  - lib/elastic/app-search/client/documents.rb
111
115
  - lib/elastic/app-search/client/engines.rb
116
+ - lib/elastic/app-search/client/logs.rb
112
117
  - lib/elastic/app-search/client/query_suggestion.rb
118
+ - lib/elastic/app-search/client/schema.rb
113
119
  - lib/elastic/app-search/client/search.rb
114
120
  - lib/elastic/app-search/client/search_settings.rb
121
+ - lib/elastic/app-search/client/synonyms.rb
115
122
  - lib/elastic/app-search/exceptions.rb
116
123
  - lib/elastic/app-search/request.rb
117
124
  - lib/elastic/app-search/utils.rb
118
125
  - lib/elastic/app-search/version.rb
119
126
  - logo-app-search.png
120
127
  - script/console
128
+ - spec/analytics_spec.rb
129
+ - spec/click_spec.rb
121
130
  - spec/client_spec.rb
122
131
  - spec/config_helper.rb
132
+ - spec/credentials_spec.rb
133
+ - spec/curations_spec.rb
134
+ - spec/documents_spec.rb
135
+ - spec/engines_spec.rb
123
136
  - spec/exceptions_spec.rb
137
+ - spec/logs_spec.rb
138
+ - spec/query_suggestion_spec.rb
139
+ - spec/schema_spec.rb
140
+ - spec/search_settings_spec.rb
141
+ - spec/search_spec.rb
124
142
  - spec/spec_helper.rb
143
+ - spec/synonyms_spec.rb
125
144
  homepage: https://github.com/elastic/app-search-ruby
126
145
  licenses:
127
146
  - Apache-2.0
@@ -147,7 +166,19 @@ signing_key:
147
166
  specification_version: 4
148
167
  summary: Official gem for accessing the Elastic App Search API
149
168
  test_files:
169
+ - spec/analytics_spec.rb
170
+ - spec/click_spec.rb
150
171
  - spec/client_spec.rb
151
172
  - spec/config_helper.rb
173
+ - spec/credentials_spec.rb
174
+ - spec/curations_spec.rb
175
+ - spec/documents_spec.rb
176
+ - spec/engines_spec.rb
152
177
  - spec/exceptions_spec.rb
178
+ - spec/logs_spec.rb
179
+ - spec/query_suggestion_spec.rb
180
+ - spec/schema_spec.rb
181
+ - spec/search_settings_spec.rb
182
+ - spec/search_spec.rb
153
183
  - spec/spec_helper.rb
184
+ - spec/synonyms_spec.rb