Class: IndexTank::IndexClient
- Inherits:
-
RestClient
- Object
- RestClient
- IndexTank::IndexClient
- Defined in:
- lib/indextank_client.rb
Instance Method Summary collapse
-
#add_document(docid, fields, options = {}) ⇒ Object
the options argument may contain a :variables key with a Hash from variable numbers to their float values this variables can be used in the scoring functions when sorting a search.
- #add_documents(data_array) ⇒ Object
- #add_function(function_index, definition, options = {}) ⇒ Object
- #code ⇒ Object
- #create_index ⇒ Object
- #creation_time ⇒ Object
- #del_function(function_index, options = {}) ⇒ Object
- #delete_document(docid, options = {}) ⇒ Object
- #delete_index ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(index_url, metadata = nil) ⇒ IndexClient
constructor
A new instance of IndexClient.
- #list_functions(options = {}) ⇒ Object
- #metadata ⇒ Object
- #metadata! ⇒ Object
-
#promote(docid, query, options = {}) ⇒ Object
the options argument may contain an :index_code definition to override this instance’s default index_code.
- #running? ⇒ Boolean
-
#search(query, options = {}) ⇒ Object
the options argument may contain an :index_code definition to override this instance’s default index_code it can also contain any of the following: :start => an int with the number of results to skip :len => an int with the number of results to return :snippet => a comma separated list of field names for which a snippet should be returned.
- #size ⇒ Object
- #update_variables(docid, variables, options = {}) ⇒ Object
Methods inherited from RestClient
Constructor Details
#initialize(index_url, metadata = nil) ⇒ IndexClient
Returns a new instance of IndexClient.
99 100 101 102 |
# File 'lib/indextank_client.rb', line 99 def initialize(index_url, =nil) @uri = URI.parse(index_url) @metadata = end |
Instance Method Details
#add_document(docid, fields, options = {}) ⇒ Object
the options argument may contain a :variables key with a Hash from variable numbers to their float values this variables can be used in the scoring functions when sorting a search
136 137 138 139 140 |
# File 'lib/indextank_client.rb', line 136 def add_document(docid, fields, ={}) .merge!( :docid => docid, :fields => fields ) code, r = PUT "/docs", return r end |
#add_documents(data_array) ⇒ Object
142 143 144 145 |
# File 'lib/indextank_client.rb', line 142 def add_documents(data_array) code, r = PUT "/docs", data_array return r end |
#add_function(function_index, definition, options = {}) ⇒ Object
190 191 192 193 194 |
# File 'lib/indextank_client.rb', line 190 def add_function(function_index, definition, ={}) .merge!( :definition => definition ) code, r = PUT "/functions/#{function_index}", return r end |
#code ⇒ Object
104 105 106 |
# File 'lib/indextank_client.rb', line 104 def code return ['code'] end |
#create_index ⇒ Object
206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/indextank_client.rb', line 206 def create_index() begin code, r = PUT "" raise IndexAlreadyExists if code == "204" return r rescue HttpCodeException if $!.code == "409" puts $!.code raise TooManyIndexes end raise end end |
#creation_time ⇒ Object
112 113 114 |
# File 'lib/indextank_client.rb', line 112 def creation_time return ['creation_time'] end |
#del_function(function_index, options = {}) ⇒ Object
196 197 198 199 |
# File 'lib/indextank_client.rb', line 196 def del_function(function_index, ={}) code, r = DELETE "/functions/#{function_index}", return r end |
#delete_document(docid, options = {}) ⇒ Object
153 154 155 156 157 |
# File 'lib/indextank_client.rb', line 153 def delete_document(docid, ={}) .merge!( :docid => docid ) code, r = DELETE "/docs", return r end |
#delete_index ⇒ Object
220 221 222 223 |
# File 'lib/indextank_client.rb', line 220 def delete_index() code, r = DELETE "" return r end |
#exists? ⇒ Boolean
120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/indextank_client.rb', line 120 def exists? begin return true rescue HttpCodeException if $!.code == "404" return false end raise end end |
#list_functions(options = {}) ⇒ Object
201 202 203 204 |
# File 'lib/indextank_client.rb', line 201 def list_functions(={}) code, r = GET "/functions" return r end |
#metadata ⇒ Object
225 226 227 228 |
# File 'lib/indextank_client.rb', line 225 def if @metadata.nil? return @metadata end |
#metadata! ⇒ Object
230 231 232 233 |
# File 'lib/indextank_client.rb', line 230 def code, @metadata = GET "" return @metadata end |
#promote(docid, query, options = {}) ⇒ Object
the options argument may contain an :index_code definition to override this instance’s default index_code
161 162 163 164 165 |
# File 'lib/indextank_client.rb', line 161 def promote(docid, query, ={}) .merge!( :docid => docid, :query => query ) code, r = PUT "/promote", return r end |
#running? ⇒ Boolean
108 109 110 |
# File 'lib/indextank_client.rb', line 108 def running? return ['started'] end |
#search(query, options = {}) ⇒ Object
the options argument may contain an :index_code definition to override this instance’s default index_code it can also contain any of the following:
:start => an int with the number of results to skip
:len => an int with the number of results to return
:snippet => a comma separated list of field names for which a snippet
should be returned. (requires an index that supports snippets)
:fetch => a comma separated list of field names for which its content
should be returned. (requires an index that supports storage)
:function => an int with the index of the scoring function to be used
for this query
179 180 181 182 183 184 185 186 187 188 |
# File 'lib/indextank_client.rb', line 179 def search(query, ={}) = { :start => 0, :len => 10 }.merge() .merge!( :q => query ) begin code, r = GET "/search", return r rescue HttpCodeException raise end end |
#size ⇒ Object
116 117 118 |
# File 'lib/indextank_client.rb', line 116 def size return ['size'] end |
#update_variables(docid, variables, options = {}) ⇒ Object
147 148 149 150 151 |
# File 'lib/indextank_client.rb', line 147 def update_variables(docid, variables, ={}) .merge!( :docid => docid, :variables => variables ) code, r = PUT "/docs/variables", return r end |