rubberband 0.9.7 → 0.9.8

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.
@@ -4,6 +4,16 @@ module ElasticSearch
4
4
  module Index
5
5
  PSEUDO_INDICES = [:all]
6
6
 
7
+ def index_exists?(index)
8
+ !!index_status(index)
9
+ rescue RequestError => e
10
+ if e.status == 404
11
+ false
12
+ else
13
+ raise e
14
+ end
15
+ end
16
+
7
17
  def index_status(*args)
8
18
  indices, options = extract_indices_and_options(args)
9
19
  execute(:index_status, indices, options)
@@ -53,8 +53,8 @@ module ElasticSearch
53
53
  end
54
54
 
55
55
  def delete_by_query(query, options = {})
56
- index, type, options = extract_required_scope(options)
57
- execute(:delete_by_query, index, type, query, options)
56
+ index, type, options = extract_scope(options)
57
+ execute(:delete_by_query, index || '_all', type, query, options)
58
58
  end
59
59
 
60
60
  #df The default field to use when no field prefix is defined within the query.
@@ -5,7 +5,14 @@ module ElasticSearch
5
5
  class ConnectionFailed < FatalError; end
6
6
  class HostResolutionError < RetryableError; end
7
7
  class TimeoutError < RetryableError; end
8
- class RequestError < FatalError; end
8
+
9
+ class RequestError < FatalError
10
+ attr_accessor :status
11
+
12
+ def initialize(status)
13
+ @status = status
14
+ end
15
+ end
9
16
 
10
17
  module Transport
11
18
  autoload :HTTP, 'transport/http'
@@ -218,7 +218,7 @@ module ElasticSearch
218
218
  end
219
219
 
220
220
  def handle_error(response)
221
- raise RequestError, "(#{response.status}) #{response.body}"
221
+ raise RequestError.new(response.status), "(#{response.status}) #{response.body}"
222
222
  end
223
223
 
224
224
  # :index - one or many index names
@@ -1,3 +1,3 @@
1
1
  module ElasticSearch
2
- VERSION = "0.9.7"
2
+ VERSION = "0.9.8"
3
3
  end
@@ -48,4 +48,9 @@ describe "basic ops" do
48
48
  result = @client.get_aliases(second_index)
49
49
  result[second_index]["aliases"].keys.should include("#{second_index}-alias")
50
50
  end
51
+
52
+ it 'should provide a shortcut for index existence' do
53
+ @client.index_exists?(@first_index).should be_true
54
+ @client.index_exists?(@first_index + "abc").should_not be_true
55
+ end
51
56
  end
@@ -3,11 +3,13 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
3
  describe "index ops" do
4
4
  before(:all) do
5
5
  @first_index = 'first-' + Time.now.to_i.to_s
6
+ @second_index = 'second-' + Time.now.to_i.to_s
6
7
  @client = ElasticSearch.new('http://127.0.0.1:9200', :index => @first_index, :type => "tweet")
7
8
  end
8
9
 
9
10
  after(:all) do
10
11
  @client.delete_index(@first_index)
12
+ @client.delete_index(@second_index)
11
13
  sleep(1)
12
14
  end
13
15
 
@@ -46,14 +48,37 @@ describe "index ops" do
46
48
  it 'should delete by query' do
47
49
  @client.index({:deleted => "bar"}, :id => "d1")
48
50
  @client.index({:deleted => "bar"}, :id => "d2")
49
- @client.refresh
51
+
52
+ @client.index({:deleted => "bar"}, :id => "d3", :index => @second_index)
53
+ @client.refresh(:all)
50
54
 
51
55
  @client.count(:term => { :deleted => 'bar'}).should == 2
56
+ @client.count({:term => { :deleted => 'bar'}}, :index => @second_index).should == 1
52
57
  @client.delete_by_query(:term => { :deleted => 'bar' })
53
- @client.refresh
58
+ @client.refresh(:all)
54
59
  @client.count(:term => { :deleted => 'bar'}).should == 0
60
+ @client.count({:term => { :deleted => 'bar'}}, :index => @second_index).should == 1
61
+ end
62
+
63
+ it 'should delete by query across indices and types' do
64
+ @client.index({:deleted => "baz"}, :id => "d1")
65
+ @client.index({:deleted => "baz"}, :id => "d2")
66
+
67
+ @client.index({:deleted => "baz"}, :id => "d3", :index => @second_index)
68
+ @client.refresh(:all)
69
+
70
+ @client.count(:term => { :deleted => 'baz'}).should == 2
71
+ @client.count({:term => { :deleted => 'baz'}}, :index => @second_index).should == 1
72
+
73
+ # create a non-scoped client
74
+ @client2 = ElasticSearch.new('http://127.0.0.1:9200')
75
+ @client2.delete_by_query(:term => { :deleted => 'baz' })
76
+
77
+ @client.refresh(:all)
78
+ @client.count(:term => { :deleted => 'baz'}).should == 0
79
+ @client.count({:term => { :deleted => 'baz'}}, :index => @second_index).should == 0
55
80
  end
56
-
81
+
57
82
  it 'should perform a successful multi get with an array' do
58
83
  @client.index({:foo => "bar"}, :id => "1")
59
84
  @client.index({:foo => "baz"}, :id => "2")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubberband
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.7
4
+ version: 0.9.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-09 00:00:00.000000000 Z
12
+ date: 2013-02-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -179,12 +179,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
179
179
  - - ! '>='
180
180
  - !ruby/object:Gem::Version
181
181
  version: '0'
182
+ segments:
183
+ - 0
184
+ hash: -3502483329274426315
182
185
  required_rubygems_version: !ruby/object:Gem::Requirement
183
186
  none: false
184
187
  requirements:
185
188
  - - ! '>='
186
189
  - !ruby/object:Gem::Version
187
190
  version: '0'
191
+ segments:
192
+ - 0
193
+ hash: -3502483329274426315
188
194
  requirements: []
189
195
  rubyforge_project: rubberband
190
196
  rubygems_version: 1.8.23