### Home Classes Methods

### In Files

- ext/r_index.c

### Parent

Hash

### Namespace

- CLASS Ferret::Index::LazyDoc::LazyDocData

### Methods

- #default
- #fields
- #load

### Files

- MIT-LICENSE
- README
- TODO
- TUTORIAL

### Class/Module Index

Quicksearch

- Ferret
- Ferret::Analysis
- Ferret::Analysis::Analyzer
- Ferret::Analysis::AsciiLetterAnalyzer
- Ferret::Analysis::AsciiLetterTokenizer
- Ferret::Analysis::AsciiLowerCaseFilter
- Ferret::Analysis::AsciiStandardAnalyzer
- Ferret::Analysis::AsciiStandardTokenizer
- Ferret::Analysis::AsciiWhiteSpaceAnalyzer
- Ferret::Analysis::AsciiWhiteSpaceTokenizer
- Ferret::Analysis::HyphenFilter
- Ferret::Analysis::LetterAnalyzer
- Ferret::Analysis::LetterTokenizer
- Ferret::Analysis::LowerCaseFilter
- Ferret::Analysis::MappingFilter
- Ferret::Analysis::PerFieldAnalyzer
- Ferret::Analysis::RegExpAnalyzer
- Ferret::Analysis::RegExpTokenizer
- Ferret::Analysis::StandardAnalyzer
- Ferret::Analysis::StandardTokenizer
- Ferret::Analysis::StemFilter
- Ferret::Analysis::StopFilter
- Ferret::Analysis::Token
- Ferret::Analysis::TokenStream
- Ferret::Analysis::WhiteSpaceAnalyzer
- Ferret::Analysis::WhiteSpaceTokenizer
- Ferret::BlankSlate
- Ferret::BoostMixin
- Ferret::Browser
- Ferret::Browser::Controller
- Ferret::Browser::Delegator
- Ferret::Browser::DocumentController
- Ferret::Browser::ErrorController
- Ferret::Browser::HelpController
- Ferret::Browser::HomeController
- Ferret::Browser::TermController
- Ferret::Browser::TermVectorController
- Ferret::Browser::ViewHelper
- Ferret::Document
- Ferret::Field
- Ferret::FieldSymbol
- Ferret::FieldSymbolMethods
- Ferret::FileNotFoundError
- Ferret::Index
- Ferret::Index::FieldInfo
- Ferret::Index::FieldInfos
- Ferret::Index::Index
- Ferret::Index::IndexReader
- Ferret::Index::IndexWriter
- Ferret::Index::LazyDoc
- Ferret::Index::LazyDoc::LazyDocData
- Ferret::Index::TermDocEnum
- Ferret::Index::TermEnum
- Ferret::Index::TermVector
- Ferret::Index::TermVector::TVOffsets
- Ferret::Index::TermVector::TVTerm
- Ferret::ParseError
- Ferret::QueryParser
- Ferret::QueryParser::QueryParseException
- Ferret::Search
- Ferret::Search::BooleanQuery
- Ferret::Search::BooleanQuery::BooleanClause
- Ferret::Search::ConstantScoreQuery
- Ferret::Search::Explanation
- Ferret::Search::Filter
- Ferret::Search::FilteredQuery
- Ferret::Search::FuzzyQuery
- Ferret::Search::Hit
- Ferret::Search::MatchAllQuery
- Ferret::Search::MultiSearcher
- Ferret::Search::MultiTermQuery
- Ferret::Search::PhraseQuery
- Ferret::Search::PrefixQuery
- Ferret::Search::Query
- Ferret::Search::QueryFilter
- Ferret::Search::RangeFilter
- Ferret::Search::RangeQuery
- Ferret::Search::Searcher
- Ferret::Search::Sort
- Ferret::Search::SortField
- Ferret::Search::Spans
- Ferret::Search::Spans::SpanFirstQuery
- Ferret::Search::Spans::SpanMultiTermQuery
- Ferret::Search::Spans::SpanNearQuery
- Ferret::Search::Spans::SpanNotQuery
- Ferret::Search::Spans::SpanOrQuery
- Ferret::Search::Spans::SpanPrefixQuery
- Ferret::Search::Spans::SpanTermQuery
- Ferret::Search::TermQuery
- Ferret::Search::TopDocs
- Ferret::Search::TypedRangeFilter
- Ferret::Search::TypedRangeQuery
- Ferret::Search::WildcardQuery
- Ferret::StateError
- Ferret::Store
- Ferret::Store::Directory
- Ferret::Store::FSDirectory
- Ferret::Store::Lock
- Ferret::Store::Lock::LockError
- Ferret::Store::RAMDirectory
- Ferret::Utils
- Ferret::Utils::BitVector
- Ferret::Utils::MultiMapper
- Ferret::Utils::PriorityQueue
- WEBrick
- WEBrick::FerretBrowserHandler
- Date
- DateTime
- FileUtils
- Float
- Integer
- String
- Symbol
- Time

No matching classes.

# Ferret::Index::LazyDoc

## 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]

### Public Instance Methods

default(key) → string click to toggle source

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));
    }

fields → array of available fields click to toggle source

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 → lazy_doc click to toggle source

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;
    }

[Validate]

Generated with the Darkfish Rdoc Generator 2.