Skip to content
Browse files

Update index

Index.add:
- it checks if the index exists before send the request.
- it doesn't send body by default

Index.update added
  • Loading branch information...
1 parent 1f7f342 commit 5838c33bc53127eb677d37225cbd08f14bebb4bf Leandro Oniszczuk committed Jun 23, 2011
Showing with 25 additions and 6 deletions.
  1. +25 −6 lib/indextank/index.rb
View
31 lib/indextank/index.rb
@@ -12,24 +12,44 @@ def initialize(index_url, metadata = nil)
end
def add( options = {} )
- options = {:public_search => false}.merge(options)
-
+
+ if self.exists?
+ raise IndexAlreadyExists
+ end
+
response = @conn.put do |req|
req.url ""
- req.body = options.to_json
+ req.body = options.to_json unless options.length == 0
end
case response.status
when 201
true
- when 204
- raise IndexAlreadyExists
when 409
raise TooManyIndexes
when 401
raise InvalidApiKey
end
end
+ def update( options )
+
+ if not self.exists?
+ raise NonExistentIndex
+ end
+
+ response = @conn.put do |req|
+ req.url ""
+ req.body = options.to_json
+ end
+ case response.status
+ when 204
+ true
+ when 401
+ raise InvalidApiKey
+ end
+ end
+
+
def refresh
response = @conn.get('')
if response.status == 200
@@ -66,7 +86,6 @@ def public_search_enabled?
@metadata['public_search']
end
-
def batch_insert(documents)
resp = @conn.put do |req|
req.url "docs"

0 comments on commit 5838c33

Please sign in to comment.
Something went wrong with that request. Please try again.