forked from elastic/elasticsearch-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearching.rb
32 lines (24 loc) · 952 Bytes
/
searching.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
module Elasticsearch
module Model
module Searching
module ClassMethods
def search(query_or_payload, options={})
__index_name = options[:index] || index_name
__document_type = options[:type] || document_type
case
# search query: ...
when query_or_payload.respond_to?(:to_hash)
response = client.search index: __index_name, type: __document_type, body: query_or_payload.to_hash
# search '{ "query" : ... }'
when query_or_payload.is_a?(String) && query_or_payload =~ /^\s*{/
response = client.search index: __index_name, type: __document_type, body: query_or_payload
# search '...'
else
response = client.search index: __index_name, type: __document_type, q: query_or_payload
end
Response::Response.new(self, response)
end
end
end
end
end