Class: Ferret::Index::SegmentTermVector

Inherits:
Object
  • Object
show all
Defined in:
lib/ferret/index/segment_term_vector.rb

Overview

Provides access to stored term vector of a document field.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#fieldObject (readonly)

Returns the value of attribute field.



11
12
13
# File 'lib/ferret/index/segment_term_vector.rb', line 11

def field
  @field
end

#offsetsObject (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

#positionsObject (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_frequenciesObject (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

#termsObject (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

#sizeObject

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_sObject



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