Module: Slingshot::DSL

Included in:
Slingshot
Defined in:
lib/slingshot/dsl.rb

Instance Method Summary collapse

Instance Method Details

#configure(&block) ⇒ Object



4
5
6
# File 'lib/slingshot/dsl.rb', line 4

def configure(&block)
  Configuration.class_eval(&block)
end

#index(name, &block) ⇒ Object



28
29
30
# File 'lib/slingshot/dsl.rb', line 28

def index(name, &block)
  Index.new(name, &block)
end

#search(indices, options = {}, &block) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/slingshot/dsl.rb', line 8

def search(indices, options={}, &block)
  if block_given?
    Search::Search.new(indices, options, &block).perform
  else
    payload = case options
      when Hash    then options.to_json
      when String  then options
      else raise ArgumentError, "Please pass a Ruby Hash or String with JSON"
    end

    response = Configuration.client.post( "#{Configuration.url}/#{indices}/_search", payload)
    json     = Yajl::Parser.parse(response.body)
    results  = Results::Collection.new(json, options)
  end
rescue Exception => error
  STDERR.puts "[REQUEST FAILED] #{error.class} #{error.http_body rescue nil}\n"
  raise
ensure
end