esearch 0.2.1 → 0.2.2

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.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -0
  3. data/.travis.yml +2 -5
  4. data/Changelog.md +5 -0
  5. data/Gemfile +1 -1
  6. data/Gemfile.devtools +22 -18
  7. data/config/flay.yml +2 -2
  8. data/config/reek.yml +5 -4
  9. data/config/rubocop.yml +81 -0
  10. data/esearch.gemspec +7 -7
  11. data/lib/esearch.rb +3 -1
  12. data/lib/esearch/cluster.rb +6 -5
  13. data/lib/esearch/command.rb +15 -7
  14. data/lib/esearch/command/cluster.rb +6 -4
  15. data/lib/esearch/command/document.rb +13 -13
  16. data/lib/esearch/command/exist.rb +6 -4
  17. data/lib/esearch/command/index.rb +7 -5
  18. data/lib/esearch/command/search.rb +5 -4
  19. data/lib/esearch/command/status.rb +5 -3
  20. data/lib/esearch/connection.rb +4 -3
  21. data/lib/esearch/document.rb +4 -2
  22. data/lib/esearch/index.rb +4 -2
  23. data/lib/esearch/indices.rb +8 -6
  24. data/lib/esearch/mixin.rb +8 -6
  25. data/lib/esearch/presenter.rb +5 -3
  26. data/lib/esearch/presenter/aspect.rb +5 -3
  27. data/lib/esearch/presenter/aspect/range.rb +11 -9
  28. data/lib/esearch/presenter/aspect/term.rb +6 -4
  29. data/lib/esearch/presenter/cluster.rb +6 -4
  30. data/lib/esearch/presenter/document.rb +12 -10
  31. data/lib/esearch/presenter/facet.rb +9 -9
  32. data/lib/esearch/presenter/hit.rb +9 -8
  33. data/lib/esearch/presenter/hits.rb +8 -7
  34. data/lib/esearch/presenter/index.rb +9 -7
  35. data/lib/esearch/presenter/search.rb +7 -5
  36. data/lib/esearch/presenter/status.rb +6 -4
  37. data/lib/esearch/request.rb +5 -3
  38. data/lib/esearch/type.rb +5 -2
  39. data/spec/integration/esearch/spike_spec.rb +15 -10
  40. data/spec/spec_helper.rb +6 -5
  41. data/spec/support/example_group_methods.rb +2 -0
  42. data/spec/support/ice_nine_config.rb +2 -0
  43. data/spec/unit/esearch/cluster_spec.rb +59 -0
  44. data/spec/unit/esearch/command/class_methods/run_spec.rb +3 -1
  45. data/spec/unit/esearch/command/cluster/health/run_spec.rb +2 -0
  46. data/spec/unit/esearch/command/document/delete/run_spec.rb +3 -1
  47. data/spec/unit/esearch/command/document/get/result_spec.rb +5 -3
  48. data/spec/unit/esearch/command/document/index/create/run_spec.rb +6 -2
  49. data/spec/unit/esearch/command/document/index/run_create_spec.rb +6 -2
  50. data/spec/unit/esearch/command/document/index/run_spec.rb +3 -1
  51. data/spec/unit/esearch/command/document/index/run_update_spec.rb +6 -2
  52. data/spec/unit/esearch/command/document/index/update/run_spec.rb +6 -2
  53. data/spec/unit/esearch/command/exist/result_spec.rb +5 -3
  54. data/spec/unit/esearch/command/index/create/run_spec.rb +2 -0
  55. data/spec/unit/esearch/command/index/delete/run_spec.rb +3 -1
  56. data/spec/unit/esearch/command/index/refresh/run_spec.rb +3 -1
  57. data/spec/unit/esearch/command/result_spec.rb +17 -7
  58. data/spec/unit/esearch/command/search/run_spec.rb +2 -0
  59. data/spec/unit/esearch/command/status/run_spec.rb +3 -1
  60. data/spec/unit/esearch/connection/class_methods/build_spec.rb +2 -0
  61. data/spec/unit/esearch/connection/run_spec.rb +6 -4
  62. data/spec/unit/esearch/document_spec.rb +44 -0
  63. data/spec/unit/esearch/index_spec.rb +42 -0
  64. data/spec/unit/esearch/indices/all_spec.rb +16 -0
  65. data/spec/unit/esearch/indices_spec.rb +18 -0
  66. data/spec/unit/esearch/mixin/document/index_create_spec.rb +2 -0
  67. data/spec/unit/esearch/mixin/document/index_spec.rb +2 -0
  68. data/spec/unit/esearch/mixin/document/index_update_spec.rb +2 -0
  69. data/spec/unit/esearch/mixin/exist/exist_predicate_spec.rb +2 -0
  70. data/spec/unit/esearch/mixin/index/refresh_spec.rb +2 -0
  71. data/spec/unit/esearch/mixin/index/status_spec.rb +2 -0
  72. data/spec/unit/esearch/mixin/search/search_spec.rb +2 -0
  73. data/spec/unit/esearch/presenter/aspect/range/from_spec.rb +2 -0
  74. data/spec/unit/esearch/presenter/aspect/range/to_spec.rb +2 -0
  75. data/spec/unit/esearch/presenter/class_methods/new_spec.rb +2 -0
  76. data/spec/unit/esearch/presenter/facet_spec.rb +60 -0
  77. data/spec/unit/esearch/presenter/hit/fields_spec.rb +2 -0
  78. data/spec/unit/esearch/presenter/hit/source_spec.rb +2 -0
  79. data/spec/unit/esearch/presenter/hits/each_spec.rb +7 -5
  80. data/spec/unit/esearch/presenter/hits/size_spec.rb +5 -3
  81. data/spec/unit/esearch/presenter/search_spec.rb +50 -0
  82. data/spec/unit/esearch/request_spec.rb +96 -0
  83. data/spec/unit/esearch/type_spec.rb +37 -0
  84. metadata +34 -50
  85. data/spec/unit/esearch/cluster/class_methods/connect_spec.rb +0 -16
  86. data/spec/unit/esearch/cluster/health_spec.rb +0 -10
  87. data/spec/unit/esearch/cluster/index_spec.rb +0 -11
  88. data/spec/unit/esearch/cluster/indices_spec.rb +0 -11
  89. data/spec/unit/esearch/cluster/path_spec.rb +0 -11
  90. data/spec/unit/esearch/document/connection_spec.rb +0 -12
  91. data/spec/unit/esearch/document/delete_spec.rb +0 -12
  92. data/spec/unit/esearch/document/get_spec.rb +0 -12
  93. data/spec/unit/esearch/index/create_spec.rb +0 -12
  94. data/spec/unit/esearch/index/delete_spec.rb +0 -11
  95. data/spec/unit/esearch/index/type_spec.rb +0 -12
  96. data/spec/unit/esearch/indices/all/path_spec.rb +0 -12
  97. data/spec/unit/esearch/presenter/facet/build_spec.rb +0 -26
  98. data/spec/unit/esearch/presenter/facet/class_methods/build_spec.rb +0 -26
  99. data/spec/unit/esearch/request/initialize_spec.rb +0 -39
  100. data/spec/unit/esearch/request/run_spec.rb +0 -39
  101. data/spec/unit/esearch/type/connection_spec.rb +0 -15
  102. data/spec/unit/esearch/type/document_spec.rb +0 -12
@@ -1,9 +1,11 @@
1
+ # encoding: UTF-8
2
+
1
3
  module Esearch
2
4
  class Command
3
5
  # Command to check existance of objects
4
6
  class Exist < self
5
7
 
6
- EXPECTED_STATI = [ 200, 404 ].freeze
8
+ EXPECTED_STATI = [200, 404].freeze
7
9
 
8
10
  # Return result
9
11
  #
@@ -32,6 +34,6 @@ module Esearch
32
34
  Request.head(context_path)
33
35
  end
34
36
 
35
- end
36
- end
37
- end
37
+ end # Exists
38
+ end # Command
39
+ end # Esearch
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module Esearch
2
4
  class Command
3
5
  # Base class for commands on index
@@ -7,7 +9,7 @@ module Esearch
7
9
  class Create < self
8
10
  include Concord.new(:context, :settings)
9
11
 
10
- EXPECT_STATUS = [ 201 ].freeze
12
+ EXPECT_STATUS = [201].freeze
11
13
  PRESENTER = Presenter::Index::Create
12
14
 
13
15
  private
@@ -60,7 +62,7 @@ module Esearch
60
62
  Request.post(context_path.join('_refresh'))
61
63
  end
62
64
 
63
- end
64
- end
65
- end
66
- end
65
+ end # Delete
66
+ end # Index
67
+ end # Command
68
+ end # Esearch
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module Esearch
2
4
  class Command
3
5
  # Search command
@@ -18,7 +20,6 @@ module Esearch
18
20
  Request.get(context_path.join('_search'), query)
19
21
  end
20
22
 
21
- end
22
- end
23
- end
24
-
23
+ end # Search
24
+ end # Command
25
+ end # Esearch
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module Esearch
2
4
  class Command
3
5
 
@@ -19,6 +21,6 @@ module Esearch
19
21
  Request.get(context_path.join('_status'))
20
22
  end
21
23
 
22
- end
23
- end
24
- end
24
+ end # Status
25
+ end # Command
26
+ end # Esearch
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module Esearch
2
4
  # Connection to an elasticsearch cluster
3
5
  class Connection
@@ -15,7 +17,6 @@ module Esearch
15
17
  new(Faraday.new(uri), logger)
16
18
  end
17
19
 
18
-
19
20
  # Run request
20
21
  #
21
22
  # @param [Command::Request] request
@@ -32,5 +33,5 @@ module Esearch
32
33
  response
33
34
  end
34
35
 
35
- end
36
- end
36
+ end # Connection
37
+ end # Esearch
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module Esearch
2
4
  # Handler for document
3
5
  class Document
@@ -49,5 +51,5 @@ module Esearch
49
51
  type.connection
50
52
  end
51
53
 
52
- end
53
- end
54
+ end # Document
55
+ end # Esearch
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module Esearch
2
4
  # Driver for specific index
3
5
  class Index
@@ -57,5 +59,5 @@ module Esearch
57
59
  end
58
60
  memoize :path
59
61
 
60
- end
61
- end
62
+ end # Index
63
+ end # Esearch
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module Esearch
2
4
  # Handler for set of indices
3
5
  class Indices
@@ -27,6 +29,8 @@ module Esearch
27
29
  class All < self
28
30
  include Concord.new(:connection)
29
31
 
32
+ PATH = Pathname.new('/_all').freeze
33
+
30
34
  # Return connection
31
35
  #
32
36
  # @return [Connection]
@@ -42,11 +46,9 @@ module Esearch
42
46
  # @api private
43
47
  #
44
48
  def path
45
- self.class::PATH
49
+ PATH
46
50
  end
47
51
 
48
- PATH = Pathname.new('/_all').freeze
49
-
50
- end
51
- end
52
- end
52
+ end # All
53
+ end # Indices
54
+ end # Esearch
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module Esearch
2
4
  # Namespace for handler mixins
3
5
  module Mixin
@@ -19,7 +21,7 @@ module Esearch
19
21
  Command::Exist.run(self)
20
22
  end
21
23
 
22
- end
24
+ end # Exist
23
25
 
24
26
  # Mixin that adds document operations
25
27
  module Document
@@ -63,7 +65,7 @@ module Esearch
63
65
  Command::Document::Index::Update.run(self, document, options)
64
66
  end
65
67
 
66
- end
68
+ end # Document
67
69
 
68
70
  # Mixin that adds index commands
69
71
  module Index
@@ -88,7 +90,7 @@ module Esearch
88
90
  Command::Index::Status.run(self)
89
91
  end
90
92
 
91
- end
93
+ end # Index
92
94
 
93
95
  # Mixin for search command
94
96
  module Search
@@ -105,7 +107,7 @@ module Esearch
105
107
  Command::Search.run(self, query)
106
108
  end
107
109
 
108
- end
110
+ end #sEarch
109
111
 
110
- end
111
- end
112
+ end # Mixin
113
+ end # Esearch
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module Esearch
2
4
  # Abstract base class for json response presenters
3
5
  class Presenter
@@ -15,7 +17,7 @@ module Esearch
15
17
  def self.expose_tagged_collection(key, presenter)
16
18
  key = key.to_s # caches string in closure ;)
17
19
  define_method(key) do ||
18
- raw.fetch(key).map do |name, element|
20
+ raw.fetch(key).map do |name, element|
19
21
  presenter.new(element.merge('name' => name))
20
22
  end
21
23
  end
@@ -39,5 +41,5 @@ module Esearch
39
41
  end
40
42
  private_class_method :expose_primitive
41
43
 
42
- end
43
- end
44
+ end # Presenter
45
+ end # Esearch
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module Esearch
2
4
  class Presenter
3
5
 
@@ -12,6 +14,6 @@ module Esearch
12
14
  #
13
15
  expose_primitive(:count)
14
16
 
15
- end
16
- end
17
- end
17
+ end # Aspect
18
+ end # Presenter
19
+ end # Esearch
@@ -1,11 +1,13 @@
1
+ # encoding: UTF-8
2
+
1
3
  module Esearch
2
4
  class Presenter
3
5
  class Aspect
4
6
 
5
7
  # Range aspect
6
8
  class Range < self
7
-
8
- # Return range start
9
+
10
+ # Return range start
9
11
  #
10
12
  # @return [Float]
11
13
  # if present
@@ -19,7 +21,7 @@ module Esearch
19
21
  raw['from']
20
22
  end
21
23
 
22
- # Return range end
24
+ # Return range end
23
25
  #
24
26
  # @return [Float]
25
27
  # if present
@@ -41,7 +43,7 @@ module Esearch
41
43
  #
42
44
  expose_primitive(:total_count)
43
45
 
44
- # Return total
46
+ # Return total
45
47
  #
46
48
  # @return [Float]
47
49
  #
@@ -49,7 +51,7 @@ module Esearch
49
51
  #
50
52
  expose_primitive(:total)
51
53
 
52
- # Return mean
54
+ # Return mean
53
55
  #
54
56
  # @return [Float]
55
57
  #
@@ -57,7 +59,7 @@ module Esearch
57
59
  #
58
60
  expose_primitive(:mean)
59
61
 
60
- end
61
- end
62
- end
63
- end
62
+ end # Range
63
+ end # Aspect
64
+ end # Presenter
65
+ end # Esearch
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module Esearch
2
4
  class Presenter
3
5
  class Aspect
@@ -13,7 +15,7 @@ module Esearch
13
15
  #
14
16
  expose_primitive(:term, :value)
15
17
 
16
- end
17
- end
18
- end
19
- end
18
+ end # Term
19
+ end # Aspect
20
+ end # Presenter
21
+ end # Esearch
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module Esearch
2
4
  class Presenter
3
5
  # Base class for cluster presenters
@@ -78,7 +80,7 @@ module Esearch
78
80
  #
79
81
  expose_primitive('unassigned_shards')
80
82
 
81
- end
82
- end
83
- end
84
- end
83
+ end # Health
84
+ end # Cluster
85
+ end # Presenter
86
+ end # Esearch
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module Esearch
2
4
  class Presenter
3
5
  # Base class result of document command presenters
@@ -52,11 +54,11 @@ module Esearch
52
54
 
53
55
  # Index operation
54
56
  class Index < self
55
- end
57
+ end # Index
56
58
 
57
59
  # Update operation
58
60
  class Update < self
59
- end
61
+ end # Update
60
62
 
61
63
  # Delete operation
62
64
  class Delete < self
@@ -73,8 +75,8 @@ module Esearch
73
75
  #
74
76
  expose_primitive(:found, :found?)
75
77
 
76
- end
77
- end
78
+ end # Delete
79
+ end # Operation
78
80
 
79
81
  # Presenter for document get result
80
82
  class Get < self
@@ -82,7 +84,7 @@ module Esearch
82
84
  # Return source document
83
85
  #
84
86
  # @return [Hash]
85
- #
87
+ #
86
88
  # @api private
87
89
  #
88
90
  expose_primitive(:_source, :source)
@@ -90,13 +92,13 @@ module Esearch
90
92
  # Return requested fields
91
93
  #
92
94
  # @return [Hash]
93
- #
95
+ #
94
96
  # @api private
95
97
  #
96
98
  expose_primitive(:fields)
97
99
 
98
- end
100
+ end # Get
99
101
 
100
- end
101
- end
102
- end
102
+ end # Document
103
+ end # Presenter
104
+ end # Esearch
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module Esearch
2
4
  class Presenter
3
5
 
@@ -29,7 +31,7 @@ module Esearch
29
31
  #
30
32
  def self.get(type)
31
33
  REGISTRY.fetch(type) do
32
- raise "Facet with type #{type.inspect} is not known"
34
+ fail "Facet with type #{type.inspect} is not known"
33
35
  end
34
36
  end
35
37
  private_class_method :get
@@ -42,9 +44,7 @@ module Esearch
42
44
  #
43
45
  def aspects
44
46
  util = self.class
45
- raw.fetch(util::FACET_KEY).map do |item|
46
- util::ASPECT_CLASS.new(item)
47
- end
47
+ raw.fetch(util::FACET_KEY).map(&util::ASPECT_CLASS.method(:new))
48
48
  end
49
49
  memoize :aspects
50
50
 
@@ -54,19 +54,19 @@ module Esearch
54
54
  class Range < self
55
55
  ASPECT_CLASS = Aspect::Range
56
56
  FACET_KEY = 'ranges'.freeze
57
- end
57
+ end # Range
58
58
 
59
59
  # Facet that returns term counts
60
60
  class Terms < self
61
61
  ASPECT_CLASS = Aspect::Term
62
62
  FACET_KEY = 'terms'.freeze
63
- end
63
+ end # Terms
64
64
 
65
65
  REGISTRY = {
66
66
  'range' => Range,
67
67
  'terms' => Terms
68
68
  }.freeze
69
69
 
70
- end
71
- end
72
- end
70
+ end # Facet
71
+ end # Presenter
72
+ end # Esearch
@@ -1,12 +1,14 @@
1
+ # encoding: UTF-8
2
+
1
3
  module Esearch
2
4
  class Presenter
3
5
 
4
6
  # Presenter for an hit
5
7
  class Hit < self
6
-
8
+
7
9
  # Return source field if present
8
10
  #
9
- # @return [Hash]
11
+ # @return [Hash]
10
12
  # if present
11
13
  #
12
14
  # @return [nil]
@@ -17,10 +19,10 @@ module Esearch
17
19
  def source
18
20
  raw['_source']
19
21
  end
20
-
22
+
21
23
  # Return fields if present
22
24
  #
23
- # @return [Hash]
25
+ # @return [Hash]
24
26
  # if present
25
27
  #
26
28
  # @return [nil]
@@ -64,7 +66,6 @@ module Esearch
64
66
  #
65
67
  expose_primitive(:_score, :score)
66
68
 
67
- end
68
- end
69
- end
70
-
69
+ end # Hit
70
+ end # Presenter
71
+ end # Esearch