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.
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.
Create a new Document object with a boost. The boost defaults to 1.0.
# File lib/ferret/document.rb, line 49 49: def initialize(boost = 1.0) 50: @boost = boost 51: end
Return true if the documents are equal, ie they have the same fields
# File lib/ferret/document.rb, line 54 54: def eql?(o) 55: return (o.is_a? Document and (o.boost == @boost) and 56: (self.keys == o.keys) and (self.values == o.values)) 57: end
Create a string representation of the document
# File lib/ferret/document.rb, line 61 61: def to_s 62: buf = ["Document {"] 63: self.keys.sort_by {|key| key.to_s}.each do |key| 64: val = self[key] 65: val_str = if val.instance_of? Array then %{["#{val.join('", "')}"]} 66: elsif val.is_a? Field then val.to_s 67: else %{"#{val.to_s}"} 68: end 69: buf << " :#{key} => #{val_str}" 70: end 71: buf << ["}#{@boost == 1.0 ? "" : "^" + @boost.to_s}"] 72: return buf.join("\n") 73: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.