Class: Ferret::Search::SloppyPhraseScorer

Inherits:
PhraseScorer show all
Defined in:
lib/ferret/search/sloppy_phrase_scorer.rb

Constant Summary

Constants inherited from Scorer

Ferret::Search::Scorer::MAX_DOCS

Instance Attribute Summary

Attributes inherited from Scorer

#similarity

Instance Method Summary collapse

Methods inherited from PhraseScorer

#do_next, #doc, #each, #explain, #first_to_last, #init, #next?, #pq_to_list, #score, #skip_to, #sort, #to_s

Methods inherited from Scorer

#doc, #each_hit, #each_hit_up_to, #explain, #next?, #score, #skip_to

Constructor Details

#initialize(weight, tps, positions, similarity, slop, norms) ⇒ SloppyPhraseScorer



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

def initialize(weight, tps, positions, similarity, slop, norms) 
  super(weight, tps, positions, similarity, norms)
  @slop = slop
end

Instance Method Details

#phrase_freqObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ferret/search/sloppy_phrase_scorer.rb', line 9

def phrase_freq()
  @pq.clear()
  last_pos = 0
  each do |pp|
    pp.first_position()
    last_pos = pp.position if (pp.position > last_pos)
    @pq.push(pp)         # build pq from list

  end

  freq = 0.0
  done = false
  begin 
    pp = @pq.pop()
    pos = start = pp.position
    next_pos = @pq.top().position
    while pos <= next_pos
      start = pos       # advance pp to min window

      if not pp.next_position()
        done = true     # ran out of a term -- done

        break
      end
      pos = pp.position
    end

    match_length = last_pos - start
    if (match_length <= @slop)
      freq += @similarity.sloppy_freq(match_length) # score match

    end

    if (pp.position > last_pos)
      last_pos = pp.position
    end
    @pq.push(pp)         # restore pq

  end while (!done)

  return freq
end