Class: Ferret::Search::FilteredTermEnum

Inherits:
Index::TermEnum show all
Defined in:
lib/ferret/search/filtered_term_enum.rb

Overview

Abstract class for enumerating a subset of all terms.

Term enumerations are always ordered by Term.<=>(). Each term in the enumeration is greater than all that precede it.

Direct Known Subclasses

FuzzyTermEnum, WildcardTermEnum

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Index::TermEnum

#skip_to

Constructor Details

#initializeFilteredTermEnum

Returns a new instance of FilteredTermEnum.



13
14
15
16
17
# File 'lib/ferret/search/filtered_term_enum.rb', line 13

def initialize()
  @term = nil
  @enum = nil
  @reader = nil
end

Instance Attribute Details

#termObject (readonly)

Returns the current Term in the enumeration. Returns nil if no Term matches or all terms have been enumerated.



11
12
13
# File 'lib/ferret/search/filtered_term_enum.rb', line 11

def term
  @term
end

Instance Method Details

#closeObject

Closes the enumeration to further activity, freeing resources.



73
74
75
76
77
# File 'lib/ferret/search/filtered_term_enum.rb', line 73

def close()
  @enum.close()
  @term = nil
  @enum = nil
end

#differenceObject

Equality measure on the term

Raises:

  • (NotImplementedError)


25
26
27
# File 'lib/ferret/search/filtered_term_enum.rb', line 25

def difference()
  raise NotImplementedError
end

#doc_freqObject

Returns the doc_freq of the current Term in the enumeration. Returns -1 if no Term matches or all terms have been enumerated.



47
48
49
50
51
52
# File 'lib/ferret/search/filtered_term_enum.rb', line 47

def doc_freq() 
  if (@enum == nil)
    return -1
  end
  return @enum.doc_freq()
end

#end_enumObject

Indiciates the end of the enumeration has been reached

Raises:

  • (NotImplementedError)


30
31
32
# File 'lib/ferret/search/filtered_term_enum.rb', line 30

def end_enum()
  raise NotImplementedError
end

#enum=(enum) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/ferret/search/filtered_term_enum.rb', line 34

def enum=(enum)
  @enum = enum
  # Find the first term that matches
  term = @enum.term()
  if (term != nil and term_compare(term)) 
    @term = term
  else
    next?
  end
end

#next?Boolean

Increments the enumeration to the next element. True if one exists.

Returns:

  • (Boolean)


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/ferret/search/filtered_term_enum.rb', line 55

def next?()
  return false if (@enum == nil) # enum not initialized
  @term = nil
  while @term.nil? 
    if end_enum() or ! @enum.next?
      return false
    end
    term = @enum.term()
    if (term_compare(term)) 
      @term = term
      return true
    end
  end
  @term = nil
  return false
end

#term_compare(term) ⇒ Object

Equality compare on the term

Raises:

  • (NotImplementedError)


20
21
22
# File 'lib/ferret/search/filtered_term_enum.rb', line 20

def term_compare(term)
  raise NotImplementedError
end