elastic_adapter 0.0.8 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +8 -0
  3. data/lib/elastic_adapter/index.rb +16 -15
  4. data/lib/elastic_adapter/response.rb +25 -0
  5. data/lib/elastic_adapter/responses/with_aggregations.rb +9 -0
  6. data/lib/elastic_adapter/responses/with_count.rb +9 -0
  7. data/lib/elastic_adapter/responses/with_exception.rb +9 -0
  8. data/lib/elastic_adapter/responses/with_hit.rb +24 -0
  9. data/lib/elastic_adapter/responses/with_hits.rb +18 -0
  10. data/lib/elastic_adapter/responses/with_suggestions.rb +9 -0
  11. data/lib/elastic_adapter/responses/with_validations.rb +13 -0
  12. data/lib/elastic_adapter/version.rb +1 -1
  13. data/lib/elastic_adapter.rb +8 -9
  14. data/spec/cassettes/ElasticAdapter_Index/_aggregate/response/{is_a_AggregationResponse.yml → has_a_aggregation.yml} +3 -3
  15. data/spec/cassettes/ElasticAdapter_Index/_aggregate/response/is_a_WithAggregation.yml +30 -0
  16. data/spec/cassettes/ElasticAdapter_Index/_aggregate.yml +8 -8
  17. data/spec/cassettes/ElasticAdapter_Index/_count/empty_index/is_a_fixnum.yml +5 -5
  18. data/spec/cassettes/ElasticAdapter_Index/_count/empty_index/returns_the_amount_of_all_documents.yml +1 -1
  19. data/spec/cassettes/ElasticAdapter_Index/_count/empty_index.yml +2 -2
  20. data/spec/cassettes/ElasticAdapter_Index/_count/not_empty_index/is_a_fixnum.yml +5 -5
  21. data/spec/cassettes/ElasticAdapter_Index/_count/not_empty_index/returns_1.yml +1 -1
  22. data/spec/cassettes/ElasticAdapter_Index/_count/not_empty_index.yml +4 -4
  23. data/spec/cassettes/ElasticAdapter_Index/_create_index/index_is_present/response/has_an_exception.yml +1 -1
  24. data/spec/cassettes/ElasticAdapter_Index/_create_index/index_is_present/response/is_a_Response.yml +1 -1
  25. data/spec/cassettes/ElasticAdapter_Index/_create_index/index_is_present.yml +2 -2
  26. data/spec/cassettes/ElasticAdapter_Index/_create_index/index_not_present/response/has_no_exception.yml +1 -1
  27. data/spec/cassettes/ElasticAdapter_Index/_create_index/index_not_present/response/is_a_Response.yml +1 -1
  28. data/spec/cassettes/ElasticAdapter_Index/_create_index/index_not_present/response.yml +1 -1
  29. data/spec/cassettes/ElasticAdapter_Index/_delete_index/index_not_present/repsonse/has_an_exception.yml +1 -1
  30. data/spec/cassettes/ElasticAdapter_Index/_delete_index/index_not_present/repsonse/is_a_Response.yml +1 -1
  31. data/spec/cassettes/ElasticAdapter_Index/_delete_index/index_present/repsonse/has_no_exception.yml +1 -1
  32. data/spec/cassettes/ElasticAdapter_Index/_delete_index/index_present/repsonse/has_no_exceptionElasticAdapter_Index/_delete_index/index_present/repsonse.yml +1 -1
  33. data/spec/cassettes/ElasticAdapter_Index/_delete_index/index_present/repsonse/is_a_Response.yml +1 -1
  34. data/spec/cassettes/ElasticAdapter_Index/_delete_index/index_present/repsonse/is_a_ResponseElasticAdapter_Index/_delete_index/index_present/repsonse.yml +1 -1
  35. data/spec/cassettes/ElasticAdapter_Index/_get/document_exists/response/document/returns_the_document.yml +1 -1
  36. data/spec/cassettes/ElasticAdapter_Index/_get/document_exists.yml +3 -3
  37. data/spec/cassettes/ElasticAdapter_Index/_index/existing_document/doesn_t_change_the_document_count.yml +1 -55
  38. data/spec/cassettes/ElasticAdapter_Index/_index/existing_document/invokes_to_hash_on_the_document.yml +2 -2
  39. data/spec/cassettes/ElasticAdapter_Index/_index/existing_document/updates_the_document.yml +2 -2
  40. data/spec/cassettes/ElasticAdapter_Index/_index/existing_document.yml +3 -3
  41. data/spec/cassettes/ElasticAdapter_Index/_index/new_document/indexes_a_document.yml +3 -3
  42. data/spec/cassettes/ElasticAdapter_Index/_index/new_document/invokes_to_hash_on_the_document.yml +2 -2
  43. data/spec/cassettes/ElasticAdapter_Index/_index/new_document.yml +2 -2
  44. data/spec/cassettes/ElasticAdapter_Index/_search/match_all/returns_all_documents.yml +2 -2
  45. data/spec/cassettes/ElasticAdapter_Index/_search/zoo/returns_one_document.yml +3 -3
  46. data/spec/cassettes/ElasticAdapter_Index/_search/zoo/returns_the_wanted_document.yml +2 -2
  47. data/spec/cassettes/ElasticAdapter_Index/_search.yml +16 -16
  48. data/spec/cassettes/ElasticAdapter_Index/_suggest/query_ba_/returns_bar.yml +1 -1
  49. data/spec/cassettes/ElasticAdapter_Index/_suggest/query_ba_/returns_one_result.yml +1 -1
  50. data/spec/cassettes/ElasticAdapter_Index/_suggest.yml +4 -4
  51. data/spec/cassettes/ElasticAdapter_Index/_validate/invalid_query/is_a_response.yml +1 -1
  52. data/spec/cassettes/ElasticAdapter_Index/_validate/invalid_query/valid_/is_false.yml +1 -1
  53. data/spec/cassettes/ElasticAdapter_Index/_validate/valid_query/is_a_response.yml +1 -1
  54. data/spec/cassettes/ElasticAdapter_Index/_validate/valid_query/is_true.yml +1 -1
  55. data/spec/cassettes/ElasticAdapter_Index/_validate.yml +2 -2
  56. data/spec/{index → integration/index}/aggregation_spec.rb +10 -2
  57. data/spec/{index → integration/index}/count_spec.rb +5 -10
  58. data/spec/{index → integration/index}/create_index_spec.rb +0 -0
  59. data/spec/{index → integration/index}/delete_index_spec.rb +0 -0
  60. data/spec/{index → integration/index}/get_spec.rb +8 -1
  61. data/spec/integration/index/index_spec.rb +28 -0
  62. data/spec/{index → integration/index}/search_spec.rb +2 -2
  63. data/spec/{index → integration/index}/shared_context.rb +0 -0
  64. data/spec/{index → integration/index}/shared_examples.rb +2 -2
  65. data/spec/{index → integration/index}/suggest_spec.rb +2 -6
  66. data/spec/{index → integration/index}/unit_spec.rb +0 -0
  67. data/spec/{index → integration/index}/validate_spec.rb +1 -16
  68. data/spec/{document_type_spec.rb → unit/document_type_spec.rb} +0 -0
  69. data/spec/{elastic_adapter_spec.rb → unit/elastic_adapter_spec.rb} +0 -0
  70. data/spec/unit/index_spec.rb +218 -0
  71. data/spec/unit/response_spec.rb +28 -0
  72. data/spec/unit/responses/with_aggregations_spec.rb +30 -0
  73. data/spec/unit/responses/with_count_spec.rb +22 -0
  74. data/spec/unit/responses/with_exception_spec.rb +17 -0
  75. data/spec/unit/responses/with_hit_spec.rb +49 -0
  76. data/spec/unit/responses/with_hits_spec.rb +79 -0
  77. data/spec/unit/responses/with_suggestions_spec.rb +33 -0
  78. data/spec/unit/responses/with_validations_spec.rb +34 -0
  79. metadata +61 -65
  80. data/lib/elastic_adapter/responses/aggregation_response.rb +0 -28
  81. data/lib/elastic_adapter/responses/base_response.rb +0 -28
  82. data/lib/elastic_adapter/responses/count_response.rb +0 -13
  83. data/lib/elastic_adapter/responses/get_response.rb +0 -13
  84. data/lib/elastic_adapter/responses/response_decorator_factory.rb +0 -28
  85. data/lib/elastic_adapter/responses/sanitized_response.rb +0 -46
  86. data/lib/elastic_adapter/responses/search_response.rb +0 -33
  87. data/lib/elastic_adapter/responses/suggestion_response.rb +0 -46
  88. data/lib/elastic_adapter/responses/validation_response.rb +0 -18
  89. data/spec/cassettes/ElasticAdapter_Index/_count/empty_index/is_a_response.yml +0 -30
  90. data/spec/cassettes/ElasticAdapter_Index/_count/empty_index/number.yml +0 -57
  91. data/spec/cassettes/ElasticAdapter_Index/_count/not_empty_index/is_a_response.yml +0 -30
  92. data/spec/index/index_spec.rb +0 -60
  93. data/spec/responses/aggregation_response_spec.rb +0 -57
  94. data/spec/responses/base_response_spec.rb +0 -19
  95. data/spec/responses/count_response_spec.rb +0 -24
  96. data/spec/responses/get_response_spec.rb +0 -29
  97. data/spec/responses/response_decorator_factory_spec.rb +0 -126
  98. data/spec/responses/sanitized_response_spec.rb +0 -36
  99. data/spec/responses/search_response_spec.rb +0 -122
  100. data/spec/responses/suggestion_response_spec.rb +0 -63
  101. data/spec/responses/validation_response_spec.rb +0 -45
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elastic_adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kristopher Bredemeier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-11 00:00:00.000000000 Z
11
+ date: 2015-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: elasticsearch
@@ -143,6 +143,7 @@ executables: []
143
143
  extensions: []
144
144
  extra_rdoc_files: []
145
145
  files:
146
+ - ".codeclimate.yml"
146
147
  - ".gitignore"
147
148
  - ".hound.yml"
148
149
  - ".rspec"
@@ -158,26 +159,23 @@ files:
158
159
  - lib/elastic_adapter.rb
159
160
  - lib/elastic_adapter/document_type.rb
160
161
  - lib/elastic_adapter/index.rb
161
- - lib/elastic_adapter/responses/aggregation_response.rb
162
- - lib/elastic_adapter/responses/base_response.rb
163
- - lib/elastic_adapter/responses/count_response.rb
164
- - lib/elastic_adapter/responses/get_response.rb
165
- - lib/elastic_adapter/responses/response_decorator_factory.rb
166
- - lib/elastic_adapter/responses/sanitized_response.rb
167
- - lib/elastic_adapter/responses/search_response.rb
168
- - lib/elastic_adapter/responses/suggestion_response.rb
169
- - lib/elastic_adapter/responses/validation_response.rb
162
+ - lib/elastic_adapter/response.rb
163
+ - lib/elastic_adapter/responses/with_aggregations.rb
164
+ - lib/elastic_adapter/responses/with_count.rb
165
+ - lib/elastic_adapter/responses/with_exception.rb
166
+ - lib/elastic_adapter/responses/with_hit.rb
167
+ - lib/elastic_adapter/responses/with_hits.rb
168
+ - lib/elastic_adapter/responses/with_suggestions.rb
169
+ - lib/elastic_adapter/responses/with_validations.rb
170
170
  - lib/elastic_adapter/version.rb
171
171
  - spec/cassettes/ElasticAdapter_Index/_aggregate.yml
172
- - spec/cassettes/ElasticAdapter_Index/_aggregate/response/is_a_AggregationResponse.yml
172
+ - spec/cassettes/ElasticAdapter_Index/_aggregate/response/has_a_aggregation.yml
173
+ - spec/cassettes/ElasticAdapter_Index/_aggregate/response/is_a_WithAggregation.yml
173
174
  - spec/cassettes/ElasticAdapter_Index/_count/empty_index.yml
174
175
  - spec/cassettes/ElasticAdapter_Index/_count/empty_index/is_a_fixnum.yml
175
- - spec/cassettes/ElasticAdapter_Index/_count/empty_index/is_a_response.yml
176
- - spec/cassettes/ElasticAdapter_Index/_count/empty_index/number.yml
177
176
  - spec/cassettes/ElasticAdapter_Index/_count/empty_index/returns_the_amount_of_all_documents.yml
178
177
  - spec/cassettes/ElasticAdapter_Index/_count/not_empty_index.yml
179
178
  - spec/cassettes/ElasticAdapter_Index/_count/not_empty_index/is_a_fixnum.yml
180
- - spec/cassettes/ElasticAdapter_Index/_count/not_empty_index/is_a_response.yml
181
179
  - spec/cassettes/ElasticAdapter_Index/_count/not_empty_index/returns_1.yml
182
180
  - spec/cassettes/ElasticAdapter_Index/_create_index/index_is_present.yml
183
181
  - spec/cassettes/ElasticAdapter_Index/_create_index/index_is_present/response/has_an_exception.yml
@@ -212,31 +210,31 @@ files:
212
210
  - spec/cassettes/ElasticAdapter_Index/_validate/invalid_query/valid_/is_false.yml
213
211
  - spec/cassettes/ElasticAdapter_Index/_validate/valid_query/is_a_response.yml
214
212
  - spec/cassettes/ElasticAdapter_Index/_validate/valid_query/is_true.yml
215
- - spec/document_type_spec.rb
216
- - spec/elastic_adapter_spec.rb
217
- - spec/index/aggregation_spec.rb
218
- - spec/index/count_spec.rb
219
- - spec/index/create_index_spec.rb
220
- - spec/index/delete_index_spec.rb
221
- - spec/index/get_spec.rb
222
- - spec/index/index_spec.rb
223
- - spec/index/search_spec.rb
224
- - spec/index/shared_context.rb
225
- - spec/index/shared_examples.rb
226
- - spec/index/suggest_spec.rb
227
- - spec/index/unit_spec.rb
228
- - spec/index/validate_spec.rb
229
- - spec/responses/aggregation_response_spec.rb
230
- - spec/responses/base_response_spec.rb
231
- - spec/responses/count_response_spec.rb
232
- - spec/responses/get_response_spec.rb
233
- - spec/responses/response_decorator_factory_spec.rb
234
- - spec/responses/sanitized_response_spec.rb
235
- - spec/responses/search_response_spec.rb
236
- - spec/responses/suggestion_response_spec.rb
237
- - spec/responses/validation_response_spec.rb
213
+ - spec/integration/index/aggregation_spec.rb
214
+ - spec/integration/index/count_spec.rb
215
+ - spec/integration/index/create_index_spec.rb
216
+ - spec/integration/index/delete_index_spec.rb
217
+ - spec/integration/index/get_spec.rb
218
+ - spec/integration/index/index_spec.rb
219
+ - spec/integration/index/search_spec.rb
220
+ - spec/integration/index/shared_context.rb
221
+ - spec/integration/index/shared_examples.rb
222
+ - spec/integration/index/suggest_spec.rb
223
+ - spec/integration/index/unit_spec.rb
224
+ - spec/integration/index/validate_spec.rb
238
225
  - spec/spec_helper.rb
239
226
  - spec/support/index_helper.rb
227
+ - spec/unit/document_type_spec.rb
228
+ - spec/unit/elastic_adapter_spec.rb
229
+ - spec/unit/index_spec.rb
230
+ - spec/unit/response_spec.rb
231
+ - spec/unit/responses/with_aggregations_spec.rb
232
+ - spec/unit/responses/with_count_spec.rb
233
+ - spec/unit/responses/with_exception_spec.rb
234
+ - spec/unit/responses/with_hit_spec.rb
235
+ - spec/unit/responses/with_hits_spec.rb
236
+ - spec/unit/responses/with_suggestions_spec.rb
237
+ - spec/unit/responses/with_validations_spec.rb
240
238
  homepage: https://github.com/kbredemeier/elastic_adapter
241
239
  licenses:
242
240
  - MIT
@@ -263,15 +261,13 @@ specification_version: 4
263
261
  summary: Repository like access to elasticseach indices
264
262
  test_files:
265
263
  - spec/cassettes/ElasticAdapter_Index/_aggregate.yml
266
- - spec/cassettes/ElasticAdapter_Index/_aggregate/response/is_a_AggregationResponse.yml
264
+ - spec/cassettes/ElasticAdapter_Index/_aggregate/response/has_a_aggregation.yml
265
+ - spec/cassettes/ElasticAdapter_Index/_aggregate/response/is_a_WithAggregation.yml
267
266
  - spec/cassettes/ElasticAdapter_Index/_count/empty_index.yml
268
267
  - spec/cassettes/ElasticAdapter_Index/_count/empty_index/is_a_fixnum.yml
269
- - spec/cassettes/ElasticAdapter_Index/_count/empty_index/is_a_response.yml
270
- - spec/cassettes/ElasticAdapter_Index/_count/empty_index/number.yml
271
268
  - spec/cassettes/ElasticAdapter_Index/_count/empty_index/returns_the_amount_of_all_documents.yml
272
269
  - spec/cassettes/ElasticAdapter_Index/_count/not_empty_index.yml
273
270
  - spec/cassettes/ElasticAdapter_Index/_count/not_empty_index/is_a_fixnum.yml
274
- - spec/cassettes/ElasticAdapter_Index/_count/not_empty_index/is_a_response.yml
275
271
  - spec/cassettes/ElasticAdapter_Index/_count/not_empty_index/returns_1.yml
276
272
  - spec/cassettes/ElasticAdapter_Index/_create_index/index_is_present.yml
277
273
  - spec/cassettes/ElasticAdapter_Index/_create_index/index_is_present/response/has_an_exception.yml
@@ -306,29 +302,29 @@ test_files:
306
302
  - spec/cassettes/ElasticAdapter_Index/_validate/invalid_query/valid_/is_false.yml
307
303
  - spec/cassettes/ElasticAdapter_Index/_validate/valid_query/is_a_response.yml
308
304
  - spec/cassettes/ElasticAdapter_Index/_validate/valid_query/is_true.yml
309
- - spec/document_type_spec.rb
310
- - spec/elastic_adapter_spec.rb
311
- - spec/index/aggregation_spec.rb
312
- - spec/index/count_spec.rb
313
- - spec/index/create_index_spec.rb
314
- - spec/index/delete_index_spec.rb
315
- - spec/index/get_spec.rb
316
- - spec/index/index_spec.rb
317
- - spec/index/search_spec.rb
318
- - spec/index/shared_context.rb
319
- - spec/index/shared_examples.rb
320
- - spec/index/suggest_spec.rb
321
- - spec/index/unit_spec.rb
322
- - spec/index/validate_spec.rb
323
- - spec/responses/aggregation_response_spec.rb
324
- - spec/responses/base_response_spec.rb
325
- - spec/responses/count_response_spec.rb
326
- - spec/responses/get_response_spec.rb
327
- - spec/responses/response_decorator_factory_spec.rb
328
- - spec/responses/sanitized_response_spec.rb
329
- - spec/responses/search_response_spec.rb
330
- - spec/responses/suggestion_response_spec.rb
331
- - spec/responses/validation_response_spec.rb
305
+ - spec/integration/index/aggregation_spec.rb
306
+ - spec/integration/index/count_spec.rb
307
+ - spec/integration/index/create_index_spec.rb
308
+ - spec/integration/index/delete_index_spec.rb
309
+ - spec/integration/index/get_spec.rb
310
+ - spec/integration/index/index_spec.rb
311
+ - spec/integration/index/search_spec.rb
312
+ - spec/integration/index/shared_context.rb
313
+ - spec/integration/index/shared_examples.rb
314
+ - spec/integration/index/suggest_spec.rb
315
+ - spec/integration/index/unit_spec.rb
316
+ - spec/integration/index/validate_spec.rb
332
317
  - spec/spec_helper.rb
333
318
  - spec/support/index_helper.rb
319
+ - spec/unit/document_type_spec.rb
320
+ - spec/unit/elastic_adapter_spec.rb
321
+ - spec/unit/index_spec.rb
322
+ - spec/unit/response_spec.rb
323
+ - spec/unit/responses/with_aggregations_spec.rb
324
+ - spec/unit/responses/with_count_spec.rb
325
+ - spec/unit/responses/with_exception_spec.rb
326
+ - spec/unit/responses/with_hit_spec.rb
327
+ - spec/unit/responses/with_hits_spec.rb
328
+ - spec/unit/responses/with_suggestions_spec.rb
329
+ - spec/unit/responses/with_validations_spec.rb
334
330
  has_rdoc:
@@ -1,28 +0,0 @@
1
- module ElasticAdapter
2
- module Responses
3
- class AggregationResponse < BaseResponse
4
- attr_reader :aggregations
5
-
6
- private
7
-
8
- def set_instance_variables
9
- new_hash = {}
10
-
11
- new_hash[:aggregations] = {}
12
-
13
- object[:aggregations].each do |key, value|
14
- new_hash[:aggregations][key] = []
15
-
16
- value[:buckets].each do |agg|
17
- new_hash[:aggregations][key] << {
18
- term: agg[:key],
19
- count: agg[:doc_count]
20
- }
21
- end
22
- end
23
-
24
- @aggregations = new_hash[:aggregations]
25
- end
26
- end
27
- end
28
- end
@@ -1,28 +0,0 @@
1
- require "delegate"
2
-
3
- module ElasticAdapter
4
- module Responses
5
- class BaseResponse < SimpleDelegator
6
- def initialize(object)
7
- __setobj__(object)
8
- set_instance_variables
9
- end
10
-
11
- # Returns the underlaying object
12
- #
13
- # @return [Object] The underlaying object
14
- def object
15
- __getobj__
16
- end
17
-
18
- private
19
-
20
- # This method is intended to set instance variables that provide
21
- # access to values from the original object
22
- #
23
- # @param [Object] object
24
- def set_instance_variables
25
- end
26
- end
27
- end
28
- end
@@ -1,13 +0,0 @@
1
- module ElasticAdapter
2
- module Responses
3
- class CountResponse < BaseResponse
4
- attr_reader :count
5
-
6
- private
7
-
8
- def set_instance_variables
9
- @count = object[:count]
10
- end
11
- end
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- module ElasticAdapter
2
- module Responses
3
- class GetResponse < BaseResponse
4
- attr_reader :document
5
-
6
- private
7
-
8
- def set_instance_variables
9
- @document = object[:source].merge(id: object[:id])
10
- end
11
- end
12
- end
13
- end
@@ -1,28 +0,0 @@
1
- module ElasticAdapter
2
- module Responses
3
- # This class is used to decorate responses
4
- #
5
- class ResponseDecoratorFactory
6
- class << self
7
- # Takes a response and multiple symbols and decorates the response.
8
- #
9
- # @param [Hash] response a response returned by elasticsearch
10
- # @param [Array<Symbol>] args the decorators the response should be decorated with.
11
- # Currently valid args are :count, :hit, :search, :validation, :suggestion
12
- # @return [Docorator] a decorated response
13
- def decorate(plain_response, *args)
14
- response = SanitizedResponse.new(plain_response)
15
-
16
- response = CountResponse.new(response) if args.include? :count
17
- response = GetResponse.new(response) if args.include? :get
18
- response = SearchResponse.new(response) if args.include? :search
19
- response = ValidationResponse.new(response) if args.include? :validation
20
- response = SuggestionResponse.new(response) if args.include? :suggestion
21
- response = AggregationResponse.new(response) if args.include? :aggregation
22
-
23
- response
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,46 +0,0 @@
1
- module ElasticAdapter
2
- module Responses
3
- class SanitizedResponse < BaseResponse
4
- def initialize(object)
5
- super(deep_sanitize_object(object))
6
- end
7
-
8
- private
9
-
10
- def deep_sanitize_object(object)
11
- if object.is_a? Hash
12
- return sanitize_hash(object)
13
- elsif object.is_a? Array
14
- return sanitize_array(object)
15
- else
16
- return object
17
- end
18
- end
19
-
20
- def sanitize_hash(hash)
21
- result = {}
22
-
23
- hash.each do |key, value|
24
- new_key = remove_leading_underscore(key).to_sym
25
-
26
- if value.is_a?(Hash)
27
- result[new_key] = sanitize_hash(value)
28
- else
29
- result[new_key] = deep_sanitize_object(value)
30
- end
31
- end
32
-
33
- result
34
- end
35
-
36
- def sanitize_array(array)
37
- array.map { |element| deep_sanitize_object(element) }
38
- end
39
-
40
- def remove_leading_underscore(string)
41
- /^_?(.*)$/.match(string)[1]
42
- end
43
- end
44
- end
45
- end
46
-
@@ -1,33 +0,0 @@
1
- module ElasticAdapter
2
- module Responses
3
- class SearchResponse < BaseResponse
4
- attr_reader :hits, :aggregations, :suggestions
5
-
6
- private
7
-
8
- def set_instance_variables
9
- @hits = collect_hits
10
- @aggregations = collect_aggregations
11
- @suggestions = collect_suggestions
12
- end
13
-
14
- def collect_hits
15
- return [] unless object[:hits]
16
- object[:hits][:hits].map { |hit| { id: hit[:id] }.merge(hit[:source]) }
17
- end
18
-
19
- def collect_aggregations
20
- object.fetch(:aggregations, [])
21
- end
22
-
23
- def collect_suggestions
24
- return [] unless object[:suggest]
25
- object[:suggest].map { |suggestion_name, content|
26
- # In this context key is the named suggestion
27
- # returned by elasticsearch
28
- SuggestionResponse::Suggestion.new(suggestion_name, content)
29
- }
30
- end
31
- end
32
- end
33
- end
@@ -1,46 +0,0 @@
1
- module ElasticAdapter
2
- module Responses
3
- class SuggestionResponse < BaseResponse
4
- # This class represents a search term and it's
5
- # suggested options
6
- class TermSuggestion
7
- attr_reader :text, :options
8
-
9
- def initialize(params)
10
- @text = params[:text]
11
- @options = params[:options]
12
- end
13
- end
14
-
15
- # This class represents a single named suggestion
16
- # returned by elaticsearch
17
- class Suggestion
18
- attr_reader :name, :terms
19
-
20
- def initialize(name, suggestions)
21
- @name = name
22
- @terms = []
23
-
24
- suggestions.each do |suggestion_per_term|
25
- @terms << TermSuggestion.new(suggestion_per_term)
26
- end
27
- end
28
- end
29
-
30
- attr_reader :suggestions
31
-
32
- private
33
-
34
- def set_instance_variables
35
- @suggestions = []
36
-
37
- object_without_shards = object.reject { |key, value| key == :shards}
38
- object_without_shards.each do |key, value|
39
- # In this context key is the named suggestion
40
- # returned by elasticsearch
41
- @suggestions << Suggestion.new(key, value)
42
- end
43
- end
44
- end
45
- end
46
- end
@@ -1,18 +0,0 @@
1
- module ElasticAdapter
2
- module Responses
3
- class ValidationResponse < BaseResponse
4
- attr_reader :explanations, :valid
5
-
6
- def valid?
7
- valid
8
- end
9
-
10
- private
11
-
12
- def set_instance_variables
13
- @valid = object[:valid]
14
- @explanations = object[:explanations]
15
- end
16
- end
17
- end
18
- end
@@ -1,30 +0,0 @@
1
- ---
2
- http_interactions:
3
- - request:
4
- method: get
5
- uri: http://localhost:9200/test_index/_count
6
- body:
7
- encoding: UTF-8
8
- string: '{"query":{"match_all":{}}}'
9
- headers:
10
- User-Agent:
11
- - Faraday v0.9.1
12
- Accept-Encoding:
13
- - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
- Accept:
15
- - "*/*"
16
- response:
17
- status:
18
- code: 200
19
- message: OK
20
- headers:
21
- Content-Type:
22
- - application/json; charset=UTF-8
23
- Content-Length:
24
- - '59'
25
- body:
26
- encoding: UTF-8
27
- string: '{"count":0,"_shards":{"total":5,"successful":5,"failed":0}}'
28
- http_version:
29
- recorded_at: Sat, 07 Feb 2015 19:44:08 GMT
30
- recorded_with: VCR 2.9.3
@@ -1,57 +0,0 @@
1
- ---
2
- http_interactions:
3
- - request:
4
- method: get
5
- uri: http://localhost:9200/test_index/_count
6
- body:
7
- encoding: UTF-8
8
- string: '{"query":{"match_all":{}}}'
9
- headers:
10
- User-Agent:
11
- - Faraday v0.9.1
12
- Accept-Encoding:
13
- - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
- Accept:
15
- - "*/*"
16
- response:
17
- status:
18
- code: 404
19
- message: Not Found
20
- headers:
21
- Content-Type:
22
- - application/json; charset=UTF-8
23
- Content-Length:
24
- - '68'
25
- body:
26
- encoding: UTF-8
27
- string: '{"error":"IndexMissingException[[test_index] missing]","status":404}'
28
- http_version:
29
- recorded_at: Mon, 09 Mar 2015 18:08:00 GMT
30
- - request:
31
- method: get
32
- uri: http://localhost:9200/test_index/_count
33
- body:
34
- encoding: UTF-8
35
- string: '{"query":{"match_all":{}}}'
36
- headers:
37
- User-Agent:
38
- - Faraday v0.9.1
39
- Accept-Encoding:
40
- - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
41
- Accept:
42
- - "*/*"
43
- response:
44
- status:
45
- code: 404
46
- message: Not Found
47
- headers:
48
- Content-Type:
49
- - application/json; charset=UTF-8
50
- Content-Length:
51
- - '68'
52
- body:
53
- encoding: UTF-8
54
- string: '{"error":"IndexMissingException[[test_index] missing]","status":404}'
55
- http_version:
56
- recorded_at: Mon, 09 Mar 2015 18:08:02 GMT
57
- recorded_with: VCR 2.9.3
@@ -1,30 +0,0 @@
1
- ---
2
- http_interactions:
3
- - request:
4
- method: get
5
- uri: http://localhost:9200/test_index/_count
6
- body:
7
- encoding: UTF-8
8
- string: '{"query":{"match_all":{}}}'
9
- headers:
10
- User-Agent:
11
- - Faraday v0.9.1
12
- Accept-Encoding:
13
- - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
- Accept:
15
- - "*/*"
16
- response:
17
- status:
18
- code: 200
19
- message: OK
20
- headers:
21
- Content-Type:
22
- - application/json; charset=UTF-8
23
- Content-Length:
24
- - '59'
25
- body:
26
- encoding: UTF-8
27
- string: '{"count":1,"_shards":{"total":5,"successful":5,"failed":0}}'
28
- http_version:
29
- recorded_at: Sat, 07 Feb 2015 19:44:14 GMT
30
- recorded_with: VCR 2.9.3
@@ -1,60 +0,0 @@
1
- require_relative "./shared_context.rb"
2
-
3
- module ElasticAdapter
4
- describe Index do
5
- include_context "index context"
6
-
7
- describe "#index", :vcr do
8
- context "new document" do
9
- let(:document) { { foo: "bar" } }
10
-
11
- before :all do
12
- create_test_index
13
- end
14
-
15
- after :all do
16
- delete_test_index
17
- end
18
-
19
- it "indexes a document" do
20
- subject.index(document)
21
- wait(1)
22
- expect(subject.count).to eq 1
23
- end
24
-
25
- it "invokes to_hash on the document" do
26
- expect(document).to receive(:to_hash).and_return(document.to_hash)
27
- subject.index(document)
28
- end
29
- end
30
-
31
- context "existing document" do
32
- let(:document) { {foo: "baz", id: 1} }
33
-
34
- before :all do
35
- create_test_index
36
- index_documents foo: "bar", id: 1
37
- end
38
-
39
- after :all do
40
- delete_test_index
41
- end
42
-
43
- it "doesn't change the document count" do
44
- expect(subject.count).to eq 1
45
- subject.index(document)
46
- expect(subject.count).to eq 1
47
- end
48
-
49
- it "invokes to_hash on the document" do
50
- expect(document).to receive(:to_hash).and_return(document.to_hash)
51
- subject.index(document)
52
- end
53
-
54
- it "updates the document" do
55
- expect(subject.get(1).document[:foo]).to eq "baz"
56
- end
57
- end
58
- end
59
- end
60
- end