Class: Ferret::Index::Term
- Inherits:
-
Object
- Object
- Ferret::Index::Term
- Includes:
- Comparable
- Defined in:
- lib/ferret/index/term.rb,
ext/term.c
Overview
A Term represents a word from text. This is the unit of search. It is composed of two elements, the text of the word, as a string, and the name of the field that the text occured in, an interned string.
Note that terms may represent more than words from text fields, but also things like dates, email addresses, urls, etc.
A term contains two attributes;
- field
-
The field indicates the part of a document which this term came from.
- text
-
In the case of words, this is simply the text of the word. In the case of dates and other types, this is an encoding of the object as a string.
Instance Attribute Summary collapse
-
#field ⇒ Object
Returns the value of attribute field.
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
- #<(rother) ⇒ Object
- #<=(rother) ⇒ Object
-
#<=>(other) ⇒ Object
implements comparable giving us the methods >, >=, <, <= and between?.
- #==(rother) ⇒ Object (also: #eql?)
- #>(rother) ⇒ Object
- #>=(rother) ⇒ Object
-
#hash ⇒ Object
Combines the hash() of the field and the text.
-
#initialize(rfield, rtext) ⇒ Term
constructor
Constructs a Term with the given field and text.
-
#set!(rfield, rtext) ⇒ Object
Resets the field and text of a Term.
- #to_s ⇒ Object
Constructor Details
#initialize(rfield, rtext) ⇒ Term
Constructs a Term with the given field and text
20 21 22 23 |
# File 'lib/ferret/index/term.rb', line 20 def initialize(fld_name, txt) @field = fld_name @text = txt end |
Instance Attribute Details
#field ⇒ Object
Returns the value of attribute field.
81 82 83 |
# File 'ext/term.c', line 81 def field @field end |
#text ⇒ Object
Returns the value of attribute text.
57 58 59 |
# File 'ext/term.c', line 57 def text @text end |
Instance Method Details
#<(rother) ⇒ Object
146 147 148 149 150 |
# File 'ext/term.c', line 146 VALUE frt_term_lt(VALUE self, VALUE rother) { return frt_term_compare_to_int(self, rother) < 0 ? Qtrue : Qfalse; } |
#<=(rother) ⇒ Object
158 159 160 161 162 |
# File 'ext/term.c', line 158 VALUE frt_term_le(VALUE self, VALUE rother) { return frt_term_compare_to_int(self, rother) <= 0 ? Qtrue : Qfalse; } |
#<=>(other) ⇒ Object
implements comparable giving us the methods >, >=, <, <= and between?
31 32 33 34 35 36 37 |
# File 'lib/ferret/index/term.rb', line 31 def <=>(other) if @field == other.field return @text <=> other.text else return @field <=> other.field end end |
#==(rother) ⇒ Object Also known as: eql?
170 171 172 173 174 175 176 |
# File 'ext/term.c', line 170 VALUE frt_term_eq(VALUE self, VALUE rother) { if (rother == Qnil) return Qfalse; return frt_term_compare_to_int(self, rother) == 0 ? Qtrue : Qfalse; } |
#>(rother) ⇒ Object
152 153 154 155 156 |
# File 'ext/term.c', line 152 VALUE frt_term_gt(VALUE self, VALUE rother) { return frt_term_compare_to_int(self, rother) > 0 ? Qtrue : Qfalse; } |
#>=(rother) ⇒ Object
164 165 166 167 168 |
# File 'ext/term.c', line 164 VALUE frt_term_ge(VALUE self, VALUE rother) { return frt_term_compare_to_int(self, rother) >= 0 ? Qtrue : Qfalse; } |
#hash ⇒ Object
Combines the hash() of the field and the text.
26 27 28 |
# File 'lib/ferret/index/term.rb', line 26 def hash() return field.hash() + text.hash() end |
#set!(rfield, rtext) ⇒ Object
Resets the field and text of a Term.
41 42 43 |
# File 'lib/ferret/index/term.rb', line 41 def set!(fld_name, txt) initialize(fld_name, txt) end |
#to_s ⇒ Object
96 97 98 |
# File 'ext/term.c', line 96 def to_s @field + ":" + @text end |