### Home Classes Methods

### In Files

- lib/ferret/document.rb

### Parent

Hash

### Methods

- ::new
- #==
- #eql?
- #to_s

### Included Modules

- Ferret::BoostMixin

### 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::Document

Documents are the unit of indexing and search.

A Document is a set of fields. Each field has a name and an array of textual values. If you are coming from a Lucene background you should note that Fields don't have any properties except for the boost property. You should use the Ferret::Index::FieldInfos class to set field properties across the whole index instead.

### Boost

The boost attribute makes a Document more important in the index. That is, you can increase the score of a match for queries that match a particular document, making it more likely to appear at the top of search results. You may, for example, want to boost products that have a higher user rating so that they are more likely to appear in search results.

Note: that fields which are not stored (see Ferret::Index::FieldInfos) are not available in documents retrieved from the index, e.g. Ferret::Search::Searcher#doc or Ferret::Index::IndexReader#doc.

Note: that modifying a Document retrieved from the index will not modify the document contained within the index. You need to delete the old version of the document and add the new version of the document.

### Public Class Methods

new(boost = 1.0) click to toggle source

Create a new Document object with a boost. The boost defaults to 1.0.

    # File lib/ferret/document.rb, line 49
    def initialize(boost = 1.0)
      @boost = boost
    end

### Public Instance Methods

==(o) click to toggle source
Alias for: eql?
eql?(o) click to toggle source

Return true if the documents are equal, ie they have the same fields

    # File lib/ferret/document.rb, line 54
    def eql?(o)
      return (o.is_a? Document and (o.boost == @boost) and
              (self.keys == o.keys) and (self.values == o.values))
    end

Also aliased as: ==
to_s() click to toggle source

Create a string representation of the document

    # File lib/ferret/document.rb, line 61
    def to_s
      buf = ["Document {"]
      self.keys.sort_by {|key| key.to_s}.each do |key|
        val = self[key]
        val_str = if val.instance_of? Array then %{["#{val.join('", "')}"]}
                  elsif val.is_a? Field then val.to_s
                  else %{"#{val.to_s}"}
                  end
        buf << "  :#{key} => #{val_str}"
      end
      buf << ["}#{@boost == 1.0 ? "" : "^" + @boost.to_s}"]
      return buf.join("\n")
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.