Class: IndexTank::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/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:



9
10
11
12
13
14
15
# File 'lib/indextank/document.rb', line 9

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 = IndexTank.setup_connection(document_url) do |faraday|
    faraday.use DocumentResponseMiddleware
  end
end

Instance Attribute Details

#docidObject (readonly)

Returns the value of attribute docid.



6
7
8
# File 'lib/indextank/document.rb', line 6

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



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

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



32
33
34
35
36
37
38
39
40
# File 'lib/indextank/document.rb', line 32

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.



56
57
58
59
60
61
62
63
64
# File 'lib/indextank/document.rb', line 56

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



42
43
44
45
46
47
48
49
50
# File 'lib/indextank/document.rb', line 42

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