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
-
#<=>(rother) ⇒ Object
implements comparable giving us the methods >, >=, <, <= and between?.
- #==(rother) ⇒ Object (also: #eql?)
- #>(rother) ⇒ Object
- #>=(rother) ⇒ Object
-
#hash ⇒ Object
static VALUE frt_term_compare_to(VALUE self, VALUE other) { return INT2FIX(frt_term_compare_to_int(self, other)); }.
-
#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.
84 85 86 |
# File 'ext/term.c', line 84 def field @field end |
#text ⇒ Object
Returns the value of attribute text.
60 61 62 |
# File 'ext/term.c', line 60 def text @text end |
Instance Method Details
#<(rother) ⇒ Object
188 189 190 191 192 |
# File 'ext/term.c', line 188
VALUE
frt_term_lt(VALUE self, VALUE rother)
{
return frt_term_compare_to_int(self, rother) < 0 ? Qtrue : Qfalse;
}
|
#<=(rother) ⇒ Object
200 201 202 203 204 |
# File 'ext/term.c', line 200
VALUE
frt_term_le(VALUE self, VALUE rother)
{
return frt_term_compare_to_int(self, rother) <= 0 ? Qtrue : Qfalse;
}
|
#<=>(rother) ⇒ 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?
212 213 214 215 216 217 218 |
# File 'ext/term.c', line 212
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
194 195 196 197 198 |
# File 'ext/term.c', line 194
VALUE
frt_term_gt(VALUE self, VALUE rother)
{
return frt_term_compare_to_int(self, rother) > 0 ? Qtrue : Qfalse;
}
|
#>=(rother) ⇒ Object
206 207 208 209 210 |
# File 'ext/term.c', line 206
VALUE
frt_term_ge(VALUE self, VALUE rother)
{
return frt_term_compare_to_int(self, rother) >= 0 ? Qtrue : Qfalse;
}
|
#hash ⇒ Object
static VALUE frt_term_compare_to(VALUE self, VALUE other) { return INT2FIX(frt_term_compare_to_int(self, other)); }
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
108 109 110 |
# File 'ext/term.c', line 108 def to_s @field + ":" + @text end |