Class: IndexTank::IndexClient

Inherits:
RestClient show all
Defined in:
lib/indextank_client.rb

Instance Method Summary collapse

Methods inherited from RestClient

#DELETE, #GET, #PUT

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, options={})
    options.merge!( :docid => docid, :fields => fields )
    code, r = PUT "/docs", options
    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, options={})
    options.merge!( :definition => definition )
    code, r = PUT "/functions/#{function_index}", options
    return r
end

#codeObject



104
105
106
# File 'lib/indextank_client.rb', line 104

def code
    return ['code']
end

#create_indexObject



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_timeObject



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, options={})
    code, r = DELETE "/functions/#{function_index}", options
    return r
end

#delete_document(docid, options = {}) ⇒ Object



153
154
155
156
157
# File 'lib/indextank_client.rb', line 153

def delete_document(docid, options={})
    options.merge!( :docid => docid )
    code, r = DELETE "/docs", options
    return r
end

#delete_indexObject



220
221
222
223
# File 'lib/indextank_client.rb', line 220

def delete_index()
    code, r = DELETE ""
    return r
end

#exists?Boolean

Returns:

  • (Boolean)


120
121
122
123
124
125
126
127
128
129
130
# File 'lib/indextank_client.rb', line 120

def exists?
    begin
        metadata!
        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(options={})
    code, r = GET "/functions"
    return r
end

#metadataObject



225
226
227
228
# File 'lib/indextank_client.rb', line 225

def 
    metadata! if @metadata.nil?
    return @metadata
end

#metadata!Object



230
231
232
233
# File 'lib/indextank_client.rb', line 230

def metadata!
    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, options={})
    options.merge!( :docid => docid, :query => query )
    code, r = PUT "/promote", options
    return r
end

#running?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/indextank_client.rb', line 108

def running?
    return metadata!['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, options={})
    options = { :start => 0, :len => 10 }.merge(options)
    options.merge!( :q => query )
    begin
        code, r = GET "/search", options
        return r
    rescue HttpCodeException
        raise
    end
end

#sizeObject



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, options={})
    options.merge!( :docid => docid, :variables => variables )
    code, r = PUT "/docs/variables", options
    return r
end