Class: IndexTank::Document
- Inherits:
-
Object
- Object
- IndexTank::Document
- Defined in:
- lib/indextank/document.rb
Instance Attribute Summary collapse
-
#docid ⇒ Object
readonly
Returns the value of attribute docid.
Instance Method Summary collapse
-
#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.
- #delete(options = {}) ⇒ Object
-
#initialize(document_url, docid) ⇒ Document
constructor
:docid => a String or Symbol, that is no longer than 1024 bytes when UTF-8 encoded.
-
#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.
- #update_variables(variables, options = {}) ⇒ Object
Constructor Details
#initialize(document_url, docid) ⇒ Document
:docid => a String or Symbol, that is no longer than 1024 bytes when UTF-8 encoded
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
#docid ⇒ Object (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, = {}) .merge!(:docid => self.docid, :fields => fields) resp = @conn.put do |req| req.url "" req.body = .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( = {}) .merge!(:docid => self.docid) resp = @conn.delete do |req| req.url "" req.body = .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, = {} ) .merge!(:docid => self.docid, :categories => categories) resp = @conn.put do |req| req.url "categories" req.body = .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, = {}) .merge!(:docid => self.docid, :variables => variables) resp = @conn.put do |req| req.url "variables" req.body = .to_json end resp.status end |