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.
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]
This method is used internally to lazily load fields. You should never really need to call it yourself.
static VALUE frb_lzd_default(VALUE self, VALUE rkey) { LazyDoc *lazy_doc = (LazyDoc *)DATA_PTR(rb_ivar_get(self, id_data)); Symbol field = frb_field(rkey); VALUE rfield = FSYM2SYM(field); return frb_lazy_df_load(self, rfield, lazy_doc_get(lazy_doc, field)); }
Returns the list of fields stored for this particular document. If you try to access any of these fields in the document the field will be loaded. Try to access any other field an nil will be returned.
static VALUE frb_lzd_fields(VALUE self) { return rb_ivar_get(self, id_fields); }
Load all unloaded fields in the document from the index.
static VALUE frb_lzd_load(VALUE self) { LazyDoc *lazy_doc = (LazyDoc *)DATA_PTR(rb_ivar_get(self, id_data)); int i; for (i = 0; i < lazy_doc->size; i++) { LazyDocField *lazy_df = lazy_doc->fields[i]; frb_lazy_df_load(self, FSYM2SYM(lazy_df->name), lazy_df); } return self; }
Generated with the Darkfish Rdoc Generator 2.