Class: Ferret::Search::PhraseScorer
- Inherits:
-
Scorer
- Object
- Scorer
- Ferret::Search::PhraseScorer
show all
- Defined in:
- lib/ferret/search/phrase_scorer.rb
Constant Summary
Constants inherited
from Scorer
Scorer::MAX_DOCS
Instance Attribute Summary
Attributes inherited from Scorer
#similarity
Instance Method Summary
collapse
Methods inherited from Scorer
#each_hit, #each_hit_up_to
Constructor Details
#initialize(weight, tps, positions, similarity, norms) ⇒ PhraseScorer
Returns a new instance of PhraseScorer.
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/ferret/search/phrase_scorer.rb', line 6
def initialize(weight, tps, positions, similarity, norms)
super(similarity)
@norms = norms
@weight = weight
@value = weight.value
@first_time = true
@more = true
tps.length.times do |i|
pp = PhrasePositions.new(tps[i], positions[i])
if (@last != nil) @last.next = pp
else
@first = pp
end
@last = pp
end
@pq = PhraseQueue.new(tps.length) end
|
Instance Method Details
#do_next ⇒ Object
next without initial increment
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/ferret/search/phrase_scorer.rb', line 43
def do_next()
while (@more)
while (@more and @first.doc < @last.doc) @more = @first.skip_to(@last.doc) first_to_last() end
if (@more)
@freq = phrase_freq() if (@freq == 0.0) @more = @last.next? else
return true end
end
end
return false end
|
#doc ⇒ Object
28
29
30
|
# File 'lib/ferret/search/phrase_scorer.rb', line 28
def doc()
return @first.doc
end
|
#each ⇒ Object
63
64
65
66
67
68
69
|
# File 'lib/ferret/search/phrase_scorer.rb', line 63
def each()
pp = @first
while (pp != nil)
yield pp
pp = pp.next
end
end
|
#explain(doc) ⇒ Object
124
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/ferret/search/phrase_scorer.rb', line 124
def explain(doc)
tf_explanation = Explanation.new()
while (next? and doc() < doc)
end
phrase_freq = (doc() == doc) ? @freq : 0.0
tf_explanation.value = @similarity.tf(phrase_freq)
tf_explanation.description = "tf(phrase_freq=#{phrase_freq})"
return tf_explanation
end
|
#first_to_last ⇒ Object
117
118
119
120
121
122
|
# File 'lib/ferret/search/phrase_scorer.rb', line 117
def first_to_last()
@last.next = @first @last = @first
@first = @first.next
@last.next = nil
end
|
#init ⇒ Object
86
87
88
89
90
91
92
93
|
# File 'lib/ferret/search/phrase_scorer.rb', line 86
def init()
each do |pp|
break if not @more = pp.next?
end
if @more
sort()
end
end
|
#next? ⇒ Boolean
32
33
34
35
36
37
38
39
40
|
# File 'lib/ferret/search/phrase_scorer.rb', line 32
def next?
if (@first_time)
init()
@first_time = false
elsif (@more)
@more = @last.next? end
return do_next()
end
|
#phrase_freq ⇒ Object
82
83
84
|
# File 'lib/ferret/search/phrase_scorer.rb', line 82
def phrase_freq()
raise NotImplementedError
end
|
#pq_to_list ⇒ Object
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/ferret/search/phrase_scorer.rb', line 103
def pq_to_list()
@last = @first = nil
while (@pq.top() != nil)
pp = @pq.pop()
if (@last != nil) @last.next = pp
else
@first = pp
end
@last = pp
pp.next = nil
end
end
|
#score ⇒ Object
71
72
73
74
|
# File 'lib/ferret/search/phrase_scorer.rb', line 71
def score()
raw = similarity().tf(@freq) * @value return raw * Similarity.decode_norm(@norms[@first.doc]) end
|
#skip_to(target) ⇒ Object
76
77
78
79
80
|
# File 'lib/ferret/search/phrase_scorer.rb', line 76
def skip_to(target)
each() { |pp| break if not @more = pp.skip_to(target) }
sort() if @more return do_next()
end
|
#sort ⇒ Object
95
96
97
98
99
100
101
|
# File 'lib/ferret/search/phrase_scorer.rb', line 95
def sort()
@pq.clear()
each() do |pp|
@pq.push(pp)
end
pq_to_list()
end
|
#to_s ⇒ Object
137
|
# File 'lib/ferret/search/phrase_scorer.rb', line 137
def to_s() return "phrase_scorer(#{@weight})" end
|