class XapianFu::XapianDocValueAccessor

A XapianDocValueAccessor is used to provide the XapianDoc#values interface to read and write field values to a XapianDb. It is usually set up by a XapianDoc so you shouldn't need to set up your own.

Public Class Methods

new(xapian_doc) click to toggle source
   # File lib/xapian_fu/xapian_doc_value_accessor.rb
92 def initialize(xapian_doc)
93   @doc = xapian_doc
94 end
value_key(key) click to toggle source

Convert the given key to an integer that can be used as a Xapian value number

    # File lib/xapian_fu/xapian_doc_value_accessor.rb
143 def self.value_key(key)
144   (key.is_a?(Integer) ? key : Zlib.crc32(key.to_s))
145 end

Public Instance Methods

[](key, type = nil)
Alias for: fetch
[]=(key, value, type = nil)
Alias for: store
delete(key) click to toggle source

Remove the value with the given key from the XapianDoc and return it

    # File lib/xapian_fu/xapian_doc_value_accessor.rb
135 def delete(key)
136   value = fetch(key)
137   @doc.xapian_document.remove_value(XapianDocValueAccessor.value_key(key))
138   value
139 end
fetch(key, type = nil) click to toggle source

Retrieve the value with the given key from the XapianDoc. key can be a symbol or string, in which case it's hashed to get an integer value number. Or you can give the integer value number if you know it.

If the class specified in the database fields for this key (or as the optional argument) has a from_xapian_fu_storage_value method then it is used to instaniate the object from the stored value. This is usually paired with a to_xapian_fu_storage_value instance method.

Due to the design of Xapian, if the value does not exist then an empty string is returned.

    # File lib/xapian_fu/xapian_doc_value_accessor.rb
123 def fetch(key, type = nil)
124   value = @doc.xapian_document.value(XapianDocValueAccessor.value_key(key))
125   @doc.db.unserialize_value(key, value, type)
126 end
Also aliased as: []
size() click to toggle source

Count the values stored in the XapianDoc

    # File lib/xapian_fu/xapian_doc_value_accessor.rb
130 def size
131   @doc.xapian_document.values_count
132 end
store(key, value, type = nil) click to toggle source

Add the given value with the given key to the XapianDoc. If the value has a to_xapian_fu_storage_value method then it is used to generate the final value to be stored, otherwise to_s is used. This is usually paired with a from_xapian_fu_storage_value class method on retrieval.

    # File lib/xapian_fu/xapian_doc_value_accessor.rb
102 def store(key, value, type = nil)
103   converted_value = @doc.db.serialize_value(key, value, type)
104   @doc.xapian_document.add_value(XapianDocValueAccessor.value_key(key), converted_value)
105   value
106 end
Also aliased as: []=