Class: Ridley::Search
- Inherits:
-
Object
- Object
- Ridley::Search
- Defined in:
- lib/ridley/resources/search.rb
Instance Attribute Summary collapse
- #client ⇒ Ridley::Client readonly
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#rows ⇒ Object
Returns the value of attribute rows.
-
#sort ⇒ Object
Returns the value of attribute sort.
-
#start ⇒ Object
Returns the value of attribute start.
Class Method Summary collapse
-
.indexes(client) ⇒ Array<String, Symbol>
Returns an array of possible search indexes to be search on.
Instance Method Summary collapse
-
#initialize(client, index, query, options = {}) ⇒ Search
constructor
A new instance of Search.
-
#run ⇒ Hash
Executes the built up query on the search’s client.
Constructor Details
#initialize(client, index, query, options = {}) ⇒ Search
Returns a new instance of Search.
37 38 39 40 41 42 43 44 |
# File 'lib/ridley/resources/search.rb', line 37 def initialize(client, index, query, = {}) @client = client @index = index.to_sym @query = query @sort = [:sort] @rows = [:rows] @start = [:start] end |
Instance Attribute Details
#client ⇒ Ridley::Client (readonly)
19 20 21 |
# File 'lib/ridley/resources/search.rb', line 19 def client @client end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
20 21 22 |
# File 'lib/ridley/resources/search.rb', line 20 def index @index end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
21 22 23 |
# File 'lib/ridley/resources/search.rb', line 21 def query @query end |
#rows ⇒ Object
Returns the value of attribute rows.
24 25 26 |
# File 'lib/ridley/resources/search.rb', line 24 def rows @rows end |
#sort ⇒ Object
Returns the value of attribute sort.
23 24 25 |
# File 'lib/ridley/resources/search.rb', line 23 def sort @sort end |
#start ⇒ Object
Returns the value of attribute start.
25 26 27 |
# File 'lib/ridley/resources/search.rb', line 25 def start @start end |
Class Method Details
.indexes(client) ⇒ Array<String, Symbol>
Returns an array of possible search indexes to be search on
13 14 15 |
# File 'lib/ridley/resources/search.rb', line 13 def indexes(client) client.connection.get("search").body.collect { |name, _| name } end |
Instance Method Details
#run ⇒ Hash
Executes the built up query on the search’s client
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/ridley/resources/search.rb', line 69 def run response = client.connection.get(query_uri, ).body case index when :node response[:rows].collect { |row| Ridley::NodeResource.new(client, row) } when :role response[:rows].collect { |row| Ridley::RoleResource.new(client, row) } when :client response[:rows].collect { |row| Ridley::ClientResource.new(client, row) } when :environment response[:rows].collect { |row| Ridley::EnvironmentResource.new(client, row) } else response[:rows] end end |