Class: Ferret::Search::Spans::SpanScorer
Constant Summary
Ferret::Search::Scorer::MAX_DOCS
Instance Attribute Summary
#similarity
Instance Method Summary
collapse
#each_hit, #each_hit_up_to
Constructor Details
#initialize(spans, weight, similarity, norms) ⇒ SpanScorer
Returns a new instance of SpanScorer.
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/ferret/search/spans/span_scorer.rb', line 5
def initialize(spans, weight, similarity, norms)
@first_time = true
@more = true
super(similarity)
@spans = spans
@norms = norms
@weight = weight
@value = weight.value()
@freq = 0.0
end
|
Instance Method Details
#doc ⇒ Object
37
|
# File 'lib/ferret/search/spans/span_scorer.rb', line 37
def doc() return @doc end
|
#explain(doc) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/ferret/search/spans/span_scorer.rb', line 61
def explain(doc)
tf_explanation = Explanation.new()
skip_to(doc)
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
|
#next? ⇒ Boolean
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/ferret/search/spans/span_scorer.rb', line 17
def next?
if (@first_time)
@more = @spans.next?
@first_time = false
end
return false if not @more
@freq = 0.0
@doc = @spans.doc
while (@more and @doc == @spans.doc)
match_length = @spans.finish - @spans.start
@freq += similarity().sloppy_freq(match_length)
@more = @spans.next?
end
return (@more or @freq != 0.0)
end
|
#score ⇒ Object
39
40
41
42
43
|
# File 'lib/ferret/search/spans/span_scorer.rb', line 39
def score()
raw = similarity().tf(@freq) * @value return raw * Similarity.decode_norm(@norms[@doc])
end
|
#skip_to(target) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/ferret/search/spans/span_scorer.rb', line 45
def skip_to(target)
@more = @spans.skip_to(target)
return false if not @more
@freq = 0.0
@doc = @spans.doc()
while (@more and @spans.doc() == target)
@freq += similarity().sloppy_freq(@spans.finish - @spans.start)
@more = @spans.next?
end
return (@more or @freq != 0.0)
end
|