Class: Ferret::Search::PhrasePositions

Inherits:
Object
  • Object
show all
Defined in:
lib/ferret/search/phrase_positions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tp_enum, offset) ⇒ PhrasePositions

Returns a new instance of PhrasePositions.



6
7
8
9
10
11
# File 'lib/ferret/search/phrase_positions.rb', line 6

def initialize(tp_enum, offset) 
  @tp_enum = tp_enum
  @offset = offset
  @count = @position = @doc = -1
  @next = nil
end

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



3
4
5
# File 'lib/ferret/search/phrase_positions.rb', line 3

def doc
  @doc
end

#nextObject

Returns the value of attribute next.



4
5
6
# File 'lib/ferret/search/phrase_positions.rb', line 4

def next
  @next
end

#positionObject (readonly)

Returns the value of attribute position.



3
4
5
# File 'lib/ferret/search/phrase_positions.rb', line 3

def position
  @position
end

Instance Method Details

#first_positionObject



36
37
38
39
# File 'lib/ferret/search/phrase_positions.rb', line 36

def first_position()
  @count = @tp_enum.freq       # read first pos
  next_position()
end

#next?Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
22
# File 'lib/ferret/search/phrase_positions.rb', line 13

def next?()
  if not @tp_enum.next?
    @tp_enum.close()          # close stream
    @doc = Scorer::MAX_DOCS    # sentinel value
    return false
  end
  @doc = @tp_enum.doc
  @position = 0
  return true
end

#next_positionObject



41
42
43
44
45
46
47
48
49
# File 'lib/ferret/search/phrase_positions.rb', line 41

def next_position()
  @count -= 1
  if @count >= 0          # read subsequent pos's
    @position = @tp_enum.next_position() - @offset
    return true
  else
    return false
  end
end

#skip_to(target) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/ferret/search/phrase_positions.rb', line 24

def skip_to(target)
  if not @tp_enum.skip_to(target)
    @tp_enum.close()          # close stream
    @doc = Scorer::MAX_DOCS    # sentinel value
    return false
  end
  @doc = @tp_enum.doc
  @position = 0
  return true
end

#to_sObject



51
52
53
# File 'lib/ferret/search/phrase_positions.rb', line 51

def to_s
  "pp->(doc => #{@doc}, position => #{position})"
end