Class: IndexTanked::IndexTank::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/index-tanked/indextank/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document_url, docid) ⇒ Document

:docid => a String or Symbol, that is no longer than 1024 bytes when UTF-8 encoded

Raises:



10
11
12
13
14
15
16
# File 'lib/index-tanked/indextank/document.rb', line 10

def initialize(document_url, docid)
  raise InvalidArgument , "docid too long. max is 1024 bytes and got #{String(docid).bytesize}" unless String(docid).bytesize <= 1024
  @docid = docid
  @conn = IndexTanked::IndexTank.setup_connection(document_url) do |faraday|
    faraday.use DocumentResponseMiddleware
  end
end

Instance Attribute Details

#docidObject (readonly)

Returns the value of attribute docid.



7
8
9
# File 'lib/index-tanked/indextank/document.rb', line 7

def docid
  @docid
end

Instance Method Details

#add(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



22
23
24
25
26
27
28
29
30
31
# File 'lib/index-tanked/indextank/document.rb', line 22

def add(fields, options = {})
  options.merge!(:docid => self.docid, :fields => fields)

  resp = @conn.put do |req|
    req.url ""
    req.body = options.to_json
  end

  resp.status
end

#delete(options = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/index-tanked/indextank/document.rb', line 33

def delete(options = {})
  options.merge!(:docid => self.docid)
  resp = @conn.delete do |req|
    req.url ""
    req.body = options.to_json
  end

  resp.status 
end

#update_categories(categories, options = {}) ⇒ Object

updates the categories of a given document the categories argument should be a Hash from string to string defining the value for each category defined by this document.



57
58
59
60
61
62
63
64
65
# File 'lib/index-tanked/indextank/document.rb', line 57

def update_categories(categories, options = {} )
  options.merge!(:docid => self.docid, :categories => categories)
  resp = @conn.put do |req|
    req.url "categories"
    req.body = options.to_json
  end

  resp.status 
end

#update_variables(variables, options = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/index-tanked/indextank/document.rb', line 43

def update_variables(variables, options = {})
  options.merge!(:docid => self.docid, :variables => variables)
  resp = @conn.put do |req|
    req.url "variables"
    req.body = options.to_json
  end

  resp.status
end