Class: Ferret::Index::SegmentTermVector
- Inherits:
-
Object
- Object
- Ferret::Index::SegmentTermVector
- Defined in:
- lib/ferret/index/segment_term_vector.rb
Overview
Provides access to stored term vector of a document field.
Instance Attribute Summary collapse
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#offsets ⇒ Object
readonly
Array of term frequencies.
-
#positions ⇒ Object
readonly
Array of term frequencies.
-
#term_frequencies ⇒ Object
readonly
Array of term frequencies.
-
#terms ⇒ Object
readonly
Returns the value of attribute terms.
Instance Method Summary collapse
-
#index_of(term) ⇒ Object
Return an index in the term numbers array returned from get_terms at which the term with the specified term appears.
-
#indexes_of(terms, start, len) ⇒ Object
Just like index_of but searches for a number of terms at the same time.
-
#initialize(field, terms, term_freqs, positions = nil, offsets = nil) ⇒ SegmentTermVector
constructor
A new instance of SegmentTermVector.
-
#size ⇒ Object
Returns the number of unique terms in the field.
- #to_s ⇒ Object
Constructor Details
#initialize(field, terms, term_freqs, positions = nil, offsets = nil) ⇒ SegmentTermVector
Returns a new instance of SegmentTermVector.
13 14 15 16 17 18 19 |
# File 'lib/ferret/index/segment_term_vector.rb', line 13 def initialize(field, terms, term_freqs, positions=nil, offsets=nil) @field = field @terms = terms @term_frequencies = term_freqs @positions = positions @offsets = offsets end |
Instance Attribute Details
#field ⇒ Object (readonly)
Returns the value of attribute field.
11 12 13 |
# File 'lib/ferret/index/segment_term_vector.rb', line 11 def field @field end |
#offsets ⇒ Object (readonly)
Array of term frequencies. Locations of the array correspond one to one to the terms in the array obtained from terms method. Each location in the array contains the number of times this term occurs in the document or the document field.
9 10 11 |
# File 'lib/ferret/index/segment_term_vector.rb', line 9 def offsets @offsets end |
#positions ⇒ Object (readonly)
Array of term frequencies. Locations of the array correspond one to one to the terms in the array obtained from terms method. Each location in the array contains the number of times this term occurs in the document or the document field.
9 10 11 |
# File 'lib/ferret/index/segment_term_vector.rb', line 9 def positions @positions end |
#term_frequencies ⇒ Object (readonly)
Array of term frequencies. Locations of the array correspond one to one to the terms in the array obtained from terms method. Each location in the array contains the number of times this term occurs in the document or the document field.
9 10 11 |
# File 'lib/ferret/index/segment_term_vector.rb', line 9 def term_frequencies @term_frequencies end |
#terms ⇒ Object (readonly)
Returns the value of attribute terms.
11 12 13 |
# File 'lib/ferret/index/segment_term_vector.rb', line 11 def terms @terms end |
Instance Method Details
#index_of(term) ⇒ Object
Return an index in the term numbers array returned from get_terms at which the term with the specified term appears. If this term does not appear in the array, return -1.
42 43 44 |
# File 'lib/ferret/index/segment_term_vector.rb', line 42 def index_of(term) return @terms ? @terms.index(term) : nil end |
#indexes_of(terms, start, len) ⇒ Object
Just like index_of but searches for a number of terms at the same time. Returns an array that has the same size as the number of terms searched for, each slot containing the result of searching for that term number.
- terms
-
array containing terms to look for
- start
-
index in the array where the list of terms starts
- len
-
the number of terms in the list
54 55 56 |
# File 'lib/ferret/index/segment_term_vector.rb', line 54 def indexes_of(terms, start, len) return terms[start, len].map { |term| index_of(term) } end |
#size ⇒ Object
Returns the number of unique terms in the field
35 36 37 |
# File 'lib/ferret/index/segment_term_vector.rb', line 35 def size() return @terms == nil ? 0 : @terms.size end |
#to_s ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ferret/index/segment_term_vector.rb', line 21 def to_s() sb = @field.to_s + ": " if @terms terms.each_with_index do |term, i| sb << ', ' if i > 0 sb << term + '/' + @term_frequencies[i].to_s end end sb << 'end' return sb end |