elastic-app-search 7.4.0 → 7.8.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.
@@ -0,0 +1,37 @@
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 'QuerySuggest' do
8
+ describe '#query_suggestion' do
9
+ let(:query) { 'cat' }
10
+ let(:options) { { :size => 3, :types => { :documents => { :fields => ['title'] } } } }
11
+
12
+ context 'when options are provided' do
13
+ subject { client.query_suggestion(engine_name, query, options) }
14
+
15
+ it 'should request query suggestions' do
16
+ expected = {
17
+ 'meta' => anything,
18
+ 'results' => anything
19
+ }
20
+ expect(subject).to(match(expected))
21
+ end
22
+ end
23
+
24
+ context 'when options are omitted' do
25
+ subject { client.query_suggestion(engine_name, query) }
26
+
27
+ it 'should request query suggestions' do
28
+ expected = {
29
+ 'meta' => anything,
30
+ 'results' => anything
31
+ }
32
+ expect(subject).to(match(expected))
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -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,72 @@ 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 'Meta Engine Name' do
58
+ let(:meta_engine_name) { "ruby-client-test-#{SecureRandom.hex}" }
59
+ end
60
+
61
+ RSpec.shared_context 'Test Engine' do
62
+ let(:engine_name) { "ruby-client-test-#{SecureRandom.hex}" }
63
+
64
+ before(:each) do
65
+ client.create_engine(engine_name) rescue Elastic::AppSearch::BadRequest
66
+ end
67
+
68
+ after(:each) do
69
+ client.destroy_engine(engine_name) rescue Elastic::AppSearch::NonExistentRecord
70
+ end
71
+ end
72
+
10
73
  RSpec.shared_context 'App Search Credentials' do
11
74
  let(:as_api_key) { ConfigHelper.get_as_api_key }
12
75
  # AS_ACCOUNT_HOST_KEY is deprecated
@@ -17,6 +80,16 @@ RSpec.shared_context 'App Search Credentials' do
17
80
  end
18
81
  end
19
82
 
83
+ RSpec.shared_context 'App Search Admin Credentials' do
84
+ let(:as_api_key) { ConfigHelper.get_as_admin_key }
85
+ # AS_ACCOUNT_HOST_KEY is deprecated
86
+ let(:as_host_identifier) { ConfigHelper.get_as_host_identifier }
87
+ let(:as_api_endpoint) { ConfigHelper.get_as_api_endpoint }
88
+ let(:client_options) do
89
+ ConfigHelper.get_client_options(as_api_key, as_host_identifier, as_api_endpoint)
90
+ end
91
+ end
92
+
20
93
  RSpec.configure do |config|
21
94
  # Run specs in random order to surface order dependencies. If you find an
22
95
  # 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.8.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-01 00:00:00.000000000 Z
11
+ date: 2020-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -107,21 +107,43 @@ 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
117
+ - lib/elastic/app-search/client/meta_engines.rb
112
118
  - lib/elastic/app-search/client/query_suggestion.rb
119
+ - lib/elastic/app-search/client/schema.rb
113
120
  - lib/elastic/app-search/client/search.rb
114
121
  - lib/elastic/app-search/client/search_settings.rb
122
+ - lib/elastic/app-search/client/synonyms.rb
115
123
  - lib/elastic/app-search/exceptions.rb
116
124
  - lib/elastic/app-search/request.rb
117
125
  - lib/elastic/app-search/utils.rb
118
126
  - lib/elastic/app-search/version.rb
119
127
  - logo-app-search.png
120
128
  - script/console
129
+ - spec/analytics_spec.rb
130
+ - spec/click_spec.rb
121
131
  - spec/client_spec.rb
122
132
  - spec/config_helper.rb
133
+ - spec/credentials_spec.rb
134
+ - spec/curations_spec.rb
135
+ - spec/documents_spec.rb
136
+ - spec/engines_spec.rb
123
137
  - spec/exceptions_spec.rb
138
+ - spec/list_documents_spec.rb
139
+ - spec/logs_spec.rb
140
+ - spec/meta_engines_spec.rb
141
+ - spec/query_suggestion_spec.rb
142
+ - spec/schema_spec.rb
143
+ - spec/search_settings_spec.rb
144
+ - spec/search_spec.rb
124
145
  - spec/spec_helper.rb
146
+ - spec/synonyms_spec.rb
125
147
  homepage: https://github.com/elastic/app-search-ruby
126
148
  licenses:
127
149
  - Apache-2.0
@@ -141,13 +163,26 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
163
  - !ruby/object:Gem::Version
142
164
  version: '0'
143
165
  requirements: []
144
- rubyforge_project:
145
- rubygems_version: 2.7.6
166
+ rubygems_version: 3.0.3
146
167
  signing_key:
147
168
  specification_version: 4
148
169
  summary: Official gem for accessing the Elastic App Search API
149
170
  test_files:
171
+ - spec/analytics_spec.rb
172
+ - spec/click_spec.rb
150
173
  - spec/client_spec.rb
151
174
  - spec/config_helper.rb
175
+ - spec/credentials_spec.rb
176
+ - spec/curations_spec.rb
177
+ - spec/documents_spec.rb
178
+ - spec/engines_spec.rb
152
179
  - spec/exceptions_spec.rb
180
+ - spec/list_documents_spec.rb
181
+ - spec/logs_spec.rb
182
+ - spec/meta_engines_spec.rb
183
+ - spec/query_suggestion_spec.rb
184
+ - spec/schema_spec.rb
185
+ - spec/search_settings_spec.rb
186
+ - spec/search_spec.rb
153
187
  - spec/spec_helper.rb
188
+ - spec/synonyms_spec.rb