esearch 0.2.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.
Files changed (101) hide show
  1. data/.gitignore +5 -0
  2. data/.rspec +6 -0
  3. data/.travis.yml +19 -0
  4. data/Changelog.md +27 -0
  5. data/Gemfile +6 -0
  6. data/Gemfile.devtools +60 -0
  7. data/Guardfile +18 -0
  8. data/LICENSE +20 -0
  9. data/README.md +93 -0
  10. data/Rakefile +2 -0
  11. data/TODO +3 -0
  12. data/config/devtools.yml +2 -0
  13. data/config/flay.yml +3 -0
  14. data/config/flog.yml +3 -0
  15. data/config/mutant.yml +3 -0
  16. data/config/reek.yml +103 -0
  17. data/config/yardstick.yml +2 -0
  18. data/esearch.gemspec +26 -0
  19. data/lib/esearch.rb +43 -0
  20. data/lib/esearch/cluster.rb +85 -0
  21. data/lib/esearch/command.rb +158 -0
  22. data/lib/esearch/command/cluster.rb +28 -0
  23. data/lib/esearch/command/document.rb +111 -0
  24. data/lib/esearch/command/exist.rb +37 -0
  25. data/lib/esearch/command/index.rb +66 -0
  26. data/lib/esearch/command/search.rb +24 -0
  27. data/lib/esearch/command/status.rb +24 -0
  28. data/lib/esearch/connection.rb +36 -0
  29. data/lib/esearch/document.rb +53 -0
  30. data/lib/esearch/index.rb +61 -0
  31. data/lib/esearch/indices.rb +52 -0
  32. data/lib/esearch/mixin.rb +111 -0
  33. data/lib/esearch/presenter.rb +43 -0
  34. data/lib/esearch/presenter/aspect.rb +17 -0
  35. data/lib/esearch/presenter/aspect/range.rb +63 -0
  36. data/lib/esearch/presenter/aspect/term.rb +19 -0
  37. data/lib/esearch/presenter/cluster.rb +84 -0
  38. data/lib/esearch/presenter/document.rb +102 -0
  39. data/lib/esearch/presenter/facet.rb +72 -0
  40. data/lib/esearch/presenter/hit.rb +70 -0
  41. data/lib/esearch/presenter/hits.rb +60 -0
  42. data/lib/esearch/presenter/index.rb +23 -0
  43. data/lib/esearch/presenter/search.rb +32 -0
  44. data/lib/esearch/presenter/status.rb +18 -0
  45. data/lib/esearch/request.rb +90 -0
  46. data/lib/esearch/type.rb +40 -0
  47. data/spec/integration/esearch/spike_spec.rb +50 -0
  48. data/spec/spec_helper.rb +65 -0
  49. data/spec/support/example_group_methods.rb +7 -0
  50. data/spec/support/ice_nine_config.rb +6 -0
  51. data/spec/unit/esearch/cluster/class_methods/connect_spec.rb +16 -0
  52. data/spec/unit/esearch/cluster/health_spec.rb +10 -0
  53. data/spec/unit/esearch/cluster/index_spec.rb +11 -0
  54. data/spec/unit/esearch/cluster/indices_spec.rb +11 -0
  55. data/spec/unit/esearch/cluster/path_spec.rb +11 -0
  56. data/spec/unit/esearch/command/class_methods/run_spec.rb +16 -0
  57. data/spec/unit/esearch/command/cluster/health/run_spec.rb +14 -0
  58. data/spec/unit/esearch/command/document/delete/run_spec.rb +13 -0
  59. data/spec/unit/esearch/command/document/get/result_spec.rb +27 -0
  60. data/spec/unit/esearch/command/document/index/create/run_spec.rb +17 -0
  61. data/spec/unit/esearch/command/document/index/run_create_spec.rb +17 -0
  62. data/spec/unit/esearch/command/document/index/run_spec.rb +15 -0
  63. data/spec/unit/esearch/command/document/index/run_update_spec.rb +15 -0
  64. data/spec/unit/esearch/command/document/index/update/run_spec.rb +15 -0
  65. data/spec/unit/esearch/command/exist/result_spec.rb +39 -0
  66. data/spec/unit/esearch/command/index/create/run_spec.rb +14 -0
  67. data/spec/unit/esearch/command/index/delete/run_spec.rb +13 -0
  68. data/spec/unit/esearch/command/index/refresh/run_spec.rb +13 -0
  69. data/spec/unit/esearch/command/result_spec.rb +68 -0
  70. data/spec/unit/esearch/command/search/run_spec.rb +14 -0
  71. data/spec/unit/esearch/command/status/run_spec.rb +13 -0
  72. data/spec/unit/esearch/connection/class_methods/build_spec.rb +29 -0
  73. data/spec/unit/esearch/connection/run_spec.rb +36 -0
  74. data/spec/unit/esearch/document/connection_spec.rb +12 -0
  75. data/spec/unit/esearch/document/delete_spec.rb +12 -0
  76. data/spec/unit/esearch/document/get_spec.rb +12 -0
  77. data/spec/unit/esearch/index/create_spec.rb +12 -0
  78. data/spec/unit/esearch/index/delete_spec.rb +11 -0
  79. data/spec/unit/esearch/index/type_spec.rb +12 -0
  80. data/spec/unit/esearch/indices/all/path_spec.rb +12 -0
  81. data/spec/unit/esearch/mixin/document/index_create_spec.rb +31 -0
  82. data/spec/unit/esearch/mixin/document/index_spec.rb +31 -0
  83. data/spec/unit/esearch/mixin/document/index_update_spec.rb +31 -0
  84. data/spec/unit/esearch/mixin/exist/exist_predicate_spec.rb +16 -0
  85. data/spec/unit/esearch/mixin/index/refresh_spec.rb +16 -0
  86. data/spec/unit/esearch/mixin/index/status_spec.rb +16 -0
  87. data/spec/unit/esearch/mixin/search/search_spec.rb +18 -0
  88. data/spec/unit/esearch/presenter/aspect/range/from_spec.rb +24 -0
  89. data/spec/unit/esearch/presenter/aspect/range/to_spec.rb +24 -0
  90. data/spec/unit/esearch/presenter/class_methods/new_spec.rb +37 -0
  91. data/spec/unit/esearch/presenter/facet/build_spec.rb +26 -0
  92. data/spec/unit/esearch/presenter/facet/class_methods/build_spec.rb +26 -0
  93. data/spec/unit/esearch/presenter/hit/fields_spec.rb +24 -0
  94. data/spec/unit/esearch/presenter/hit/source_spec.rb +24 -0
  95. data/spec/unit/esearch/presenter/hits/each_spec.rb +15 -0
  96. data/spec/unit/esearch/presenter/hits/size_spec.rb +13 -0
  97. data/spec/unit/esearch/request/initialize_spec.rb +39 -0
  98. data/spec/unit/esearch/request/run_spec.rb +39 -0
  99. data/spec/unit/esearch/type/connection_spec.rb +15 -0
  100. data/spec/unit/esearch/type/document_spec.rb +12 -0
  101. metadata +330 -0
@@ -0,0 +1,5 @@
1
+ /Gemfile.lock
2
+ /tmp
3
+ /.bundle
4
+ /vendor
5
+ /.rbx
data/.rspec ADDED
@@ -0,0 +1,6 @@
1
+ --color
2
+ --format progress
3
+ --profile
4
+ --order random
5
+ --fail-fast
6
+ --backtrace
@@ -0,0 +1,19 @@
1
+ language: ruby
2
+ script: 'bundle exec rake ci'
3
+ services:
4
+ - elasticsearch
5
+ rvm:
6
+ - 1.9.2
7
+ - 1.9.3
8
+ - 2.0.0
9
+ - ruby-head
10
+ - jruby-19mode
11
+ - jruby-head
12
+ - rbx-19mode
13
+ matrix:
14
+ allow_failures:
15
+ - rvm: rbx-18mode # Json lib is defunct
16
+ notifications:
17
+ irc: "irc.freenode.org#datamapper"
18
+ email:
19
+ - mbj@seonic.net
@@ -0,0 +1,27 @@
1
+ # v0.2.0 2013-05-19
2
+
3
+ * Rename lib to esearch
4
+
5
+ # v0.1.5 2013-04-24
6
+
7
+ * Fix op_type query param for updates
8
+
9
+ # v0.1.4 2013-04-23
10
+
11
+ * Correctly pass query params to db.
12
+
13
+ # v0.1.3 2013-04-23
14
+
15
+ * Return nil on Document#get when document does not exist
16
+
17
+ # v0.1.2 2013-04-14
18
+
19
+ * Do not deep freeze presenters, fixes performance problems.
20
+
21
+ # v0.1.1 2013-03-09
22
+
23
+ * Add Presenter::Hit#fields
24
+
25
+ # v0.1.0 2013-03-09
26
+
27
+ * First public release!
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'devtools', :git => 'https://github.com/datamapper/devtools.git'
6
+ eval File.read('Gemfile.devtools')
@@ -0,0 +1,60 @@
1
+ # encoding: utf-8
2
+
3
+ group :development do
4
+ gem 'rake', '~> 10.0.4'
5
+ gem 'rspec', '~> 2.13.0'
6
+ gem 'yard', '~> 0.8.6.1'
7
+ end
8
+
9
+ group :yard do
10
+ gem 'kramdown', '~> 1.0.1'
11
+ end
12
+
13
+ group :guard do
14
+ gem 'guard', '~> 1.8.0'
15
+ gem 'guard-bundler', '~> 1.0.0'
16
+ gem 'guard-rspec', '~> 2.5.4'
17
+
18
+ # file system change event handling
19
+ gem 'listen', '~> 1.0.2'
20
+ gem 'rb-fchange', '~> 0.0.6', :require => false
21
+ gem 'rb-fsevent', '~> 0.9.3', :require => false
22
+ gem 'rb-inotify', '~> 0.9.0', :require => false
23
+
24
+ # notification handling
25
+ gem 'libnotify', '~> 0.8.0', :require => false
26
+ gem 'rb-notifu', '~> 0.0.4', :require => false
27
+ gem 'terminal-notifier-guard', '~> 1.5.3', :require => false
28
+ end
29
+
30
+ group :metrics do
31
+ gem 'backports', '~> 3.3', '>= 3.3.0'
32
+ gem 'coveralls', '~> 0.6.6'
33
+ gem 'flay', '~> 2.2.0'
34
+ gem 'flog', '~> 4.0.0'
35
+ gem 'reek', '~> 1.3.1', :git => 'https://github.com/troessner/reek.git'
36
+ gem 'simplecov', '~> 0.7.1'
37
+ gem 'yardstick', '~> 0.9.6'
38
+
39
+ platforms :ruby_19 do
40
+ gem 'yard-spellcheck', '~> 0.1.5'
41
+ end
42
+
43
+ platforms :mri_19, :rbx do
44
+ gem 'mutant', '~> 0.2.20'
45
+ end
46
+
47
+ platforms :rbx do
48
+ gem 'pelusa', '~> 0.2.2'
49
+ end
50
+ end
51
+
52
+ group :benchmarks do
53
+ gem 'rbench', '~> 0.2.3'
54
+ end
55
+
56
+ platform :jruby do
57
+ group :jruby do
58
+ gem 'jruby-openssl', '~> 0.8.5'
59
+ end
60
+ end
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+
3
+ guard :bundler do
4
+ watch('Gemfile')
5
+ end
6
+
7
+ guard :rspec, :version => 2 do
8
+ # run all specs if the spec_helper or supporting files files are modified
9
+ watch('spec/spec_helper.rb') { 'spec/unit' }
10
+ watch(%r{\Aspec/(?:lib|support|shared)/.+\.rb\z}) { 'spec/unit' }
11
+
12
+ # run unit specs if associated lib code is modified
13
+ watch(%r{\Alib/(.+)\.rb\z}) { |m| Dir["spec/unit/#{m[1]}"] }
14
+ watch("lib/#{File.basename(File.expand_path('../', __FILE__))}.rb") { 'spec/unit' }
15
+
16
+ # run a spec if it is modified
17
+ watch(%r{\Aspec/(?:unit|integration)/.+_spec\.rb\z})
18
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Markus Schirp
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,93 @@
1
+ esearch
2
+ =======
3
+
4
+ [![Build Status](https://secure.travis-ci.org/mbj/esearch.png?branch=master)](http://travis-ci.org/mbj/esearch)
5
+ [![Dependency Status](https://gemnasium.com/mbj/esearch.png)](https://gemnasium.com/mbj/esearch)
6
+ [![Code Climate](https://codeclimate.com/github/mbj/esearch.png)](https://codeclimate.com/github/mbj/esearch)
7
+
8
+ Terminate the [esearch API](http://www.esearch.org/guide/reference/api/) in a friendly ruby PORO api.
9
+
10
+ Installation
11
+ ------------
12
+
13
+ Install the gem `esearch` via your preferred method.
14
+
15
+ Examples
16
+ --------
17
+
18
+ ```ruby
19
+ # Settings suitable for operation on single node
20
+ settings = {
21
+ :settings => {
22
+ :number_of_shards => 1,
23
+ :number_of_replicas => 0
24
+ }
25
+ )
26
+
27
+ # Connect to a cluster
28
+ cluster = Esearch::Cluster.connect(uri, Logger.new($stderr, :debug)) }
29
+
30
+ # Create index
31
+ index_a = cluster.index('test-a')
32
+ index_a.exist? # => false, does not exist jet
33
+ index_a.create(settings)
34
+ index_a.exist? # => true
35
+
36
+ # Create another index
37
+ index_b = cluster.index('test-b')
38
+ index_b.create(SINGLE_NODE_SETTINGS)
39
+
40
+ # Wait for cluster initialization
41
+ cluster.health(:wait_for_status => :green, :timeout => '10s')
42
+
43
+ # Access many indexes at once
44
+ indices = cluster.indices(%w(test-a test-b))
45
+
46
+ # Index some data
47
+ result_a = index_a.type('type-a').index({'foo' => 'bar'})
48
+ result_b = index_b.type('type-b').index({'foo' => 'baz'})
49
+
50
+ # Refresh indices
51
+ indices.refresh
52
+
53
+ # Query all documents in index a
54
+ result = index_a.search({:query => { :match_all => {}}})
55
+ result.hits.map(&:source) # => [{'foo' => 'bar'}]
56
+
57
+ # Query all documents across two indexes
58
+ result = indices.search({:query => { :match_all => {}}})
59
+ result.hits.map(&:source) # => [{'foo' => 'bar'}, {'foo' => 'baz'}]
60
+
61
+ # Delete a document
62
+ index_a.type('type-a').document(result_a.id).delete
63
+
64
+ # Query a document by id
65
+ document = index_b.type('type-b').document(result_b.id).get
66
+ document.source # => {'foo' => 'baz'}
67
+ ```
68
+
69
+ Compatibility
70
+ -------------
71
+
72
+ Tested under {mri,jruby,rbx} > 1.8.
73
+
74
+ Credits
75
+ -------
76
+
77
+ * [Markus Schirp (mbj)](https://github.com/mbj) Author
78
+
79
+ Contributing
80
+ -------------
81
+
82
+ * Fork the project.
83
+ * Make your feature addition or bug fix.
84
+ * Add tests for it. This is important so I don't break it in a
85
+ future version unintentionally.
86
+ * Commit, do not mess with Rakefile or version
87
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
88
+ * Send me a pull request. Bonus points for topic branches.
89
+
90
+ License
91
+ -------
92
+
93
+ This gem is published under the MIT license. See LICENSE file.
@@ -0,0 +1,2 @@
1
+ require 'devtools'
2
+ Devtools.init_rake_tasks
data/TODO ADDED
@@ -0,0 +1,3 @@
1
+ * Investigate into other transport protocols than HTTP
2
+ * Provide Esearch::Document::Version for version scoped operations
3
+ * Add bulk operations
@@ -0,0 +1,2 @@
1
+ ---
2
+ unit_test_timeout: 1.0
@@ -0,0 +1,3 @@
1
+ ---
2
+ threshold: 12
3
+ total_score: 189
@@ -0,0 +1,3 @@
1
+ ---
2
+ threshold: 12.7
3
+ total_score: 109.0
@@ -0,0 +1,3 @@
1
+ ---
2
+ lib: esearch
3
+ namespace: Esearch
@@ -0,0 +1,103 @@
1
+ ---
2
+ UncommunicativeParameterName:
3
+ accept: []
4
+ exclude: []
5
+ enabled: true
6
+ reject:
7
+ - !ruby/regexp /^.$/
8
+ - !ruby/regexp /[0-9]$/
9
+ - !ruby/regexp /[A-Z]/
10
+ TooManyMethods:
11
+ max_methods: 10
12
+ exclude:
13
+ - Esearch::Command # 12 methods, TODO: Bring down to 10. Extraction of Response class!
14
+ - Esearch::Request # 4 instance variables. Acceptable as this is a DTO
15
+ enabled: true
16
+ max_instance_variables: 3
17
+ UncommunicativeMethodName:
18
+ accept: []
19
+ exclude: []
20
+ enabled: true
21
+ reject:
22
+ - !ruby/regexp /^[a-z]$/
23
+ - !ruby/regexp /[0-9]$/
24
+ - !ruby/regexp /[A-Z]/
25
+ LongParameterList:
26
+ max_params: 2
27
+ exclude:
28
+ - Esearch::Request#initialize # 4 parameters, acceptable it is a DTO
29
+ enabled: true
30
+ overrides: {}
31
+ FeatureEnvy:
32
+ exclude: []
33
+ enabled: true
34
+ ClassVariable:
35
+ exclude: []
36
+ enabled: true
37
+ BooleanParameter:
38
+ exclude: []
39
+ enabled: true
40
+ IrresponsibleModule:
41
+ exclude: []
42
+ enabled: true
43
+ UncommunicativeModuleName:
44
+ accept: []
45
+ exclude: []
46
+ enabled: true
47
+ reject:
48
+ - !ruby/regexp /^.$/
49
+ - !ruby/regexp /[0-9]$/
50
+ NestedIterators:
51
+ ignore_iterators: []
52
+ exclude:
53
+ - Esearch::Presenter#self.expose_tagged_collection # 2 levels
54
+ enabled: true
55
+ max_allowed_nesting: 1
56
+ TooManyStatements:
57
+ max_statements: 5
58
+ exclude: []
59
+ enabled: true
60
+ DuplicateMethodCall:
61
+ allow_calls:
62
+ - util.debug
63
+ exclude: []
64
+ enabled: true
65
+ max_calls: 1
66
+ UtilityFunction:
67
+ max_helper_calls: 1
68
+ exclude: []
69
+ enabled: true
70
+ Attribute:
71
+ exclude: []
72
+ enabled: false
73
+ UncommunicativeVariableName:
74
+ accept: []
75
+ exclude: []
76
+ enabled: true
77
+ reject:
78
+ - !ruby/regexp /^.$/
79
+ - !ruby/regexp /[0-9]$/
80
+ - !ruby/regexp /[A-Z]/
81
+ RepeatedConditional:
82
+ exclude: []
83
+ enabled: true
84
+ max_ifs: 2
85
+ DataClump:
86
+ exclude: []
87
+ enabled: true
88
+ max_copies: 1
89
+ min_clump_size: 3
90
+ ControlParameter:
91
+ exclude:
92
+ - Esearch::Index#read
93
+ enabled: true
94
+ LongYieldList:
95
+ max_params: 1
96
+ exclude: []
97
+ enabled: true
98
+ UnusedParameters:
99
+ exclude:
100
+ - Esearch::NullLogger#self.debug
101
+ - Esearch::NullLogger#self.error
102
+ - Esearch::NullLogger#self.info
103
+ - Esearch::NullLogger#self.warn
@@ -0,0 +1,2 @@
1
+ ---
2
+ threshold: 100
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = 'esearch'
5
+ gem.version = '0.2.0'
6
+ gem.authors = [ 'Markus Schirp' ]
7
+ gem.email = [ 'mbj@seonic.net' ]
8
+ gem.description = 'Esearch driver for ruby'
9
+ gem.summary = gem.description
10
+ gem.homepage = 'https://github.com/mbj/elasticsearch'
11
+ gem.license = 'MIT'
12
+
13
+ gem.require_paths = [ 'lib' ]
14
+ gem.files = `git ls-files`.split("\n")
15
+ gem.test_files = `git ls-files -- spec`.split("\n")
16
+ gem.extra_rdoc_files = %w[TODO]
17
+
18
+ gem.add_runtime_dependency('descendants_tracker', '~> 0.0.1')
19
+ gem.add_runtime_dependency('concord', '~> 0.1.0')
20
+ gem.add_runtime_dependency('faraday', '~> 0.8.4')
21
+ gem.add_runtime_dependency('adamantium', '~> 0.0.7')
22
+ gem.add_runtime_dependency('equalizer', '~> 0.0.5')
23
+ gem.add_runtime_dependency('abstract_type', '~> 0.0.5')
24
+ gem.add_runtime_dependency('multi_json', '~> 1.7.2')
25
+ gem.add_runtime_dependency('null_logger', '~> 0.0.1')
26
+ end
@@ -0,0 +1,43 @@
1
+ require 'multi_json'
2
+ require 'faraday'
3
+ require 'adamantium'
4
+ require 'equalizer'
5
+ require 'concord'
6
+ require 'abstract_type'
7
+ require 'null_logger'
8
+
9
+ # Library namespace
10
+ module Esearch
11
+ # Error raised when node signals an exception
12
+ class RemoteError < StandardError; end
13
+ # Error raised when protocol is violated
14
+ class ProtocolError < StandardError; end
15
+ end
16
+
17
+ require 'esearch/request'
18
+ require 'esearch/mixin'
19
+ require 'esearch/connection'
20
+ require 'esearch/cluster'
21
+ require 'esearch/type'
22
+ require 'esearch/document'
23
+ require 'esearch/indices'
24
+ require 'esearch/index'
25
+ require 'esearch/presenter'
26
+ require 'esearch/presenter/search'
27
+ require 'esearch/presenter/index'
28
+ require 'esearch/presenter/document'
29
+ require 'esearch/presenter/status'
30
+ require 'esearch/presenter/cluster'
31
+ require 'esearch/presenter/hit'
32
+ require 'esearch/presenter/hits'
33
+ require 'esearch/presenter/aspect'
34
+ require 'esearch/presenter/aspect/term'
35
+ require 'esearch/presenter/aspect/range'
36
+ require 'esearch/presenter/facet'
37
+ require 'esearch/command'
38
+ require 'esearch/command/search'
39
+ require 'esearch/command/status'
40
+ require 'esearch/command/index'
41
+ require 'esearch/command/document'
42
+ require 'esearch/command/cluster'
43
+ require 'esearch/command/exist'