Class: Isomorfeus::Ferret::Field
- Inherits:
-
Array
- Object
- Array
- Isomorfeus::Ferret::Field
- Includes:
- BoostMixin
- Defined in:
- lib/isomorfeus/ferret/document.rb
Overview
A Field is a section of a Document. A Field is basically an array with a boost attribute. It also provides pretty printing of the field with the #to_s method.
Boost
The boost attribute makes a field more important in the index. That is, you can increase the score of a match for queries that match terms in a boosted field. You may, for example, want to boost a title field so that matches that match in the :title field score more highly than matches that match in the :contents field.
Note: If you’d like to use boosted fields without having to use the Field class you can just include the BoostMixin in the Array class. See BoostMixin.
Instance Attribute Summary
Attributes included from BoostMixin
Instance Method Summary collapse
- #+(o) ⇒ Object
- #eql?(o) ⇒ Boolean (also: #==)
-
#initialize(data = [], boost = 1.0) ⇒ Field
constructor
Create a new Field object.
- #to_s ⇒ Object
Constructor Details
#initialize(data = [], boost = 1.0) ⇒ Field
107 108 109 110 111 112 113 114 |
# File 'lib/isomorfeus/ferret/document.rb', line 107 def initialize(data = [], boost = 1.0) @boost = boost if data.is_a? Array data.each {|v| self << v} else self << data.to_s end end |
Instance Method Details
#+(o) ⇒ Object
121 122 123 |
# File 'lib/isomorfeus/ferret/document.rb', line 121 def +(o) return Field.new(super(o), self.boost) end |
#eql?(o) ⇒ Boolean Also known as: ==
116 117 118 |
# File 'lib/isomorfeus/ferret/document.rb', line 116 def eql?(o) return (o.is_a? Field and (o.boost == @boost) and super(o)) end |
#to_s ⇒ Object
125 126 127 128 129 |
# File 'lib/isomorfeus/ferret/document.rb', line 125 def to_s buf = %{["#{self.join('", "')}"]} buf << "^#@boost" if @boost != 1.0 return buf end |