Class: Ferret::Index::LazyDoc

Inherits:
Object
  • Object
show all
Defined in:
ext/r_index.c

Overview

Summary

When a document is retrieved from the index a LazyDoc is returned. Actually, LazyDoc is just a modified Hash object which lazily adds fields to itself when they are accessed. You should not that they keys method will return nothing until you actually access one of the fields. To see what fields are available use LazyDoc#fields rather than LazyDoc#keys. To load all fields use the LazyDoc#load method.

Example

doc = index_reader[0]

doc.keys     #=> []
doc.values   #=> []
doc.fields   #=> [:title, :content]

title = doc[:title] #=> "the title"
doc.keys     #=> [:title]
doc.values   #=> ["the title"]
doc.fields   #=> [:title, :content]

doc.load
doc.keys     #=> [:title, :content]
doc.values   #=> ["the title", "the content"]
doc.fields   #=> [:title, :content]