elastic_adapter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +41 -0
  7. data/Rakefile +24 -0
  8. data/elastic_adapter.gemspec +30 -0
  9. data/example.env +4 -0
  10. data/lib/elastic_adapter/decoration/count_response.rb +18 -0
  11. data/lib/elastic_adapter/decoration/decorator.rb +39 -0
  12. data/lib/elastic_adapter/decoration/hit_decorator.rb +25 -0
  13. data/lib/elastic_adapter/decoration/response_decorator_factory.rb +51 -0
  14. data/lib/elastic_adapter/decoration/search_response.rb +29 -0
  15. data/lib/elastic_adapter/decoration/suggestion_response.rb +25 -0
  16. data/lib/elastic_adapter/decoration/validation_response.rb +16 -0
  17. data/lib/elastic_adapter/document_type.rb +21 -0
  18. data/lib/elastic_adapter/index.rb +108 -0
  19. data/lib/elastic_adapter/response.rb +57 -0
  20. data/lib/elastic_adapter/version.rb +3 -0
  21. data/lib/elastic_adapter.rb +21 -0
  22. data/spec/cassettes/ElasticAdapter_Index/_count/empty_index/is_a_response.yml +30 -0
  23. data/spec/cassettes/ElasticAdapter_Index/_count/empty_index/returs_the_amount_of_all_documents.yml +30 -0
  24. data/spec/cassettes/ElasticAdapter_Index/_count/not_empty_index/is_a_response.yml +30 -0
  25. data/spec/cassettes/ElasticAdapter_Index/_count/not_empty_index/returns_1.yml +30 -0
  26. data/spec/cassettes/ElasticAdapter_Index/_create_index/index_is_present/response/has_an_exception.yml +30 -0
  27. data/spec/cassettes/ElasticAdapter_Index/_create_index/index_is_present/response/is_a_Response.yml +30 -0
  28. data/spec/cassettes/ElasticAdapter_Index/_create_index/index_not_present/response/has_no_exception.yml +57 -0
  29. data/spec/cassettes/ElasticAdapter_Index/_create_index/index_not_present/response/is_a_Response.yml +57 -0
  30. data/spec/cassettes/ElasticAdapter_Index/_delete_index/index_not_present/repsonse/has_an_exception.yml +30 -0
  31. data/spec/cassettes/ElasticAdapter_Index/_delete_index/index_not_present/repsonse/is_a_Response.yml +30 -0
  32. data/spec/cassettes/ElasticAdapter_Index/_delete_index/index_present/repsonse/has_no_exception.yml +57 -0
  33. data/spec/cassettes/ElasticAdapter_Index/_delete_index/index_present/repsonse/is_a_Response.yml +57 -0
  34. data/spec/cassettes/ElasticAdapter_Index/_get/document_exists/response/contains_the_document.yml +30 -0
  35. data/spec/cassettes/ElasticAdapter_Index/_index/existing_document/doesn_t_change_the_document_count.yml +84 -0
  36. data/spec/cassettes/ElasticAdapter_Index/_index/existing_document/invokes_to_hash_on_the_document.yml +30 -0
  37. data/spec/cassettes/ElasticAdapter_Index/_index/existing_document/updates_the_document.yml +30 -0
  38. data/spec/cassettes/ElasticAdapter_Index/_index/new_document/indexes_a_document.yml +57 -0
  39. data/spec/cassettes/ElasticAdapter_Index/_index/new_document/invokes_to_hash_on_the_document.yml +30 -0
  40. data/spec/cassettes/ElasticAdapter_Index/_search/match_all/returns_all_documents.yml +30 -0
  41. data/spec/cassettes/ElasticAdapter_Index/_search/zoo/returns_one_document.yml +30 -0
  42. data/spec/cassettes/ElasticAdapter_Index/_search/zoo/returns_the_wanted_document.yml +30 -0
  43. data/spec/cassettes/ElasticAdapter_Index/_suggest/query_ba_/returns_bar.yml +30 -0
  44. data/spec/cassettes/ElasticAdapter_Index/_suggest/query_ba_/returns_one_result.yml +30 -0
  45. data/spec/cassettes/ElasticAdapter_Index/_validate/invalid_query/is_a_response.yml +30 -0
  46. data/spec/cassettes/ElasticAdapter_Index/_validate/invalid_query/is_false.yml +31 -0
  47. data/spec/cassettes/ElasticAdapter_Index/_validate/valid_query/is_a_response.yml +30 -0
  48. data/spec/cassettes/ElasticAdapter_Index/_validate/valid_query/is_true.yml +30 -0
  49. data/spec/decoration/response_decorator_factory_spec.rb +75 -0
  50. data/spec/document_type_spec.rb +42 -0
  51. data/spec/elastic_adapter_spec.rb +4 -0
  52. data/spec/index_spec.rb +458 -0
  53. data/spec/response_spec.rb +80 -0
  54. data/spec/spec_helper.rb +102 -0
  55. metadata +243 -0
@@ -0,0 +1,30 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://localhost:9200/test_index/_search
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"query":{"match":{"foo":"zoo"}}}'
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
+ - '224'
25
+ body:
26
+ encoding: UTF-8
27
+ string: '{"took":4,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":0.30685282,"hits":[{"_index":"test_index","_type":"test_doc","_id":"2","_score":0.30685282,"_source":{"foo":"zoo"}}]}}'
28
+ http_version:
29
+ recorded_at: Thu, 05 Feb 2015 19:30:08 GMT
30
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,30 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://localhost:9200/test_index/_search
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"query":{"match":{"foo":"zoo"}}}'
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
+ - '224'
25
+ body:
26
+ encoding: UTF-8
27
+ string: '{"took":3,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":0.30685282,"hits":[{"_index":"test_index","_type":"test_doc","_id":"2","_score":0.30685282,"_source":{"foo":"zoo"}}]}}'
28
+ http_version:
29
+ recorded_at: Thu, 05 Feb 2015 19:30:08 GMT
30
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,30 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://localhost:9200/test_index/_suggest
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"foo_suggest":{"text":"ba","completion":{"field":"foo"}}}'
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
+ - '140'
25
+ body:
26
+ encoding: UTF-8
27
+ string: '{"_shards":{"total":5,"successful":5,"failed":0},"foo_suggest":[{"text":"ba","offset":0,"length":2,"options":[{"text":"bar","score":1.0}]}]}'
28
+ http_version:
29
+ recorded_at: Thu, 05 Feb 2015 19:30:07 GMT
30
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,30 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://localhost:9200/test_index/_suggest
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"foo_suggest":{"text":"ba","completion":{"field":"foo"}}}'
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
+ - '140'
25
+ body:
26
+ encoding: UTF-8
27
+ string: '{"_shards":{"total":5,"successful":5,"failed":0},"foo_suggest":[{"text":"ba","offset":0,"length":2,"options":[{"text":"bar","score":1.0}]}]}'
28
+ http_version:
29
+ recorded_at: Thu, 05 Feb 2015 19:30:07 GMT
30
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,30 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://localhost:9200/test_index/_validate/query?explain=true
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"asd":"[[[ BOOM! ]]]"}'
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
+ - '62'
25
+ body:
26
+ encoding: UTF-8
27
+ string: '{"valid":true,"_shards":{"total":1,"successful":0,"failed":0}}'
28
+ http_version:
29
+ recorded_at: Thu, 05 Feb 2015 21:00:43 GMT
30
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,31 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://localhost:9200/test_index/_validate/query?explain=true
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"asd":"[[[ BOOM! ]]]"}'
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
+ - '224'
25
+ body:
26
+ encoding: UTF-8
27
+ string: '{"valid":false,"_shards":{"total":1,"successful":1,"failed":0},"explanations":[{"index":"test_index","valid":false,"error":"org.elasticsearch.index.query.QueryParsingException:
28
+ [test_index] request does not support [asd]"}]}'
29
+ http_version:
30
+ recorded_at: Thu, 05 Feb 2015 19:30:06 GMT
31
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,30 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://localhost:9200/test_index/_validate/query?explain=true
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
+ - '62'
25
+ body:
26
+ encoding: UTF-8
27
+ string: '{"valid":true,"_shards":{"total":1,"successful":0,"failed":0}}'
28
+ http_version:
29
+ recorded_at: Thu, 05 Feb 2015 21:04:08 GMT
30
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,30 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://localhost:9200/test_index/_validate/query?explain=true
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
+ - '150'
25
+ body:
26
+ encoding: UTF-8
27
+ string: '{"valid":true,"_shards":{"total":1,"successful":1,"failed":0},"explanations":[{"index":"test_index","valid":true,"explanation":"ConstantScore(*:*)"}]}'
28
+ http_version:
29
+ recorded_at: Thu, 05 Feb 2015 19:30:06 GMT
30
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,75 @@
1
+ require "spec_helper"
2
+
3
+ module ElasticAdapter
4
+ module Decoration
5
+ describe ResponseDecoratorFactory do
6
+ describe "class methods" do
7
+ describe "#decorate" do
8
+ context "response with exception" do
9
+ let(:response) {{ exception: ArgumentError.new }}
10
+ let(:subject) { ResponseDecoratorFactory.decorate(response)}
11
+
12
+ it "returns the unmodified response" do
13
+ expect(subject).to be response
14
+ end
15
+ end
16
+
17
+ context "response with acknowledged" do
18
+ let(:response) {{ acknowledged: true }}
19
+ let(:subject) { ResponseDecoratorFactory.decorate(response)}
20
+
21
+ it "returns the unmodified response" do
22
+ expect(subject).to be response
23
+ end
24
+ end
25
+
26
+ context "response with source" do
27
+ let(:response) {{ source: {} }}
28
+ let(:subject) { ResponseDecoratorFactory.decorate(response)}
29
+
30
+ it "returns a HitDecorator" do
31
+ expect(subject).to be_a HitDecorator
32
+ end
33
+ end
34
+
35
+ context "response with hits" do
36
+ let(:response) {{ hits: {hits: []} }}
37
+ let(:subject) { ResponseDecoratorFactory.decorate(response)}
38
+
39
+ it "returns a SearchResponse" do
40
+ expect(subject).to be_a SearchResponse
41
+ end
42
+ end
43
+
44
+ context "response with count" do
45
+ let(:response) {{ count: {count: 1} }}
46
+ let(:subject) { ResponseDecoratorFactory.decorate(response)}
47
+
48
+ it "returns a CountResponse" do
49
+ expect(subject).to be_a CountResponse
50
+ end
51
+ end
52
+
53
+ context "response with options" do
54
+ let(:response) {{ foo: "bar", foo_suggestion: [{options: []}] }}
55
+ let(:subject) { ResponseDecoratorFactory.decorate(response)}
56
+
57
+ it "returns a SuggestionResponse" do
58
+ expect(subject).to be_a SuggestionResponse
59
+ end
60
+ end
61
+
62
+ context "response with everything_else" do
63
+ let(:response) {{ everything_else: {} }}
64
+ let(:subject) { ResponseDecoratorFactory.decorate(response)}
65
+
66
+ it "returns a Response" do
67
+ expect(subject).to be_a Hash
68
+ end
69
+ end
70
+
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,42 @@
1
+ require "spec_helper"
2
+
3
+ module ElasticAdapter
4
+ describe DocumentType do
5
+ let(:mappings) do
6
+ {
7
+ name: {
8
+ type: "string",
9
+ index_analyzer: "shingle_analyzer"
10
+ }
11
+ }
12
+ end
13
+
14
+ let(:name) { "test_index" }
15
+
16
+ let(:subject) { DocumentType.new(name, mappings) }
17
+
18
+ describe "#initialize" do
19
+ it "assigns the mappings" do
20
+ expect(subject.instance_variable_get('@mappings')).to be mappings
21
+ end
22
+
23
+ it "assigns the name" do
24
+ expect(subject.instance_variable_get('@name')).to be name
25
+ end
26
+ end
27
+
28
+ describe "getter" do
29
+ describe "name" do
30
+ it "returns the name" do
31
+ expect(subject.name).to eq name
32
+ end
33
+ end
34
+
35
+ describe "mappings" do
36
+ it "returns the mappings" do
37
+ expect(subject.mappings).to eq mappings
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,4 @@
1
+ require "spec_helper"
2
+
3
+ module ElasticAdapter
4
+ end