Class: Ferret::Search::ConjunctionScorer
- Inherits:
-
Scorer
- Object
- Scorer
- Ferret::Search::ConjunctionScorer
show all
- Defined in:
- lib/ferret/search/conjunction_scorer.rb
Overview
Scorer for conjunctions, sets of queries, all of which are required.
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
Returns a new instance of ConjunctionScorer.
6
7
8
9
10
11
|
# File 'lib/ferret/search/conjunction_scorer.rb', line 6
def initialize(similarity)
super
@scorers = []
@first_time = true
@more = true
end
|
Instance Method Details
#add(scorer) ⇒ Object
Also known as:
<<
13
14
15
|
# File 'lib/ferret/search/conjunction_scorer.rb', line 13
def add(scorer)
@scorers << scorer
end
|
#do_next ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/ferret/search/conjunction_scorer.rb', line 39
def do_next()
while @more and first().doc < last().doc @more = first().skip_to(last().doc) @scorers << @scorers.shift end
return @more end
|
#doc ⇒ Object
26
27
28
|
# File 'lib/ferret/search/conjunction_scorer.rb', line 26
def doc()
return first().doc()
end
|
#explain(doc) ⇒ Object
95
96
97
|
# File 'lib/ferret/search/conjunction_scorer.rb', line 95
def explain(doc)
raise NotImplementedError
end
|
#first ⇒ Object
18
19
20
|
# File 'lib/ferret/search/conjunction_scorer.rb', line 18
def first()
return @scorers.first
end
|
#init(init_scorers) ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/ferret/search/conjunction_scorer.rb', line 72
def init(init_scorers)
@coord = similarity().coord(@scorers.size(), @scorers.size())
@more = @scorers.size() > 0
if init_scorers
@scorers.each do |scorer|
break if not @more
@more = scorer.next?
end
sort_scorers() if @more
end
@first_time = false
end
|
#last ⇒ Object
22
23
24
|
# File 'lib/ferret/search/conjunction_scorer.rb', line 22
def last()
return @scorers.last
end
|
#next? ⇒ Boolean
30
31
32
33
34
35
36
37
|
# File 'lib/ferret/search/conjunction_scorer.rb', line 30
def next?()
if (@first_time)
init(true)
elsif (@more)
@more = last().next? end
return do_next()
end
|
#score ⇒ Object
Sums the scores of all of the scorers for the current document.
63
64
65
66
67
68
69
70
|
# File 'lib/ferret/search/conjunction_scorer.rb', line 63
def score()
score = 0.0 @scorers.each do |scorer|
score += scorer.score
end
score *= @coord
return score
end
|
#skip_to(target) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/ferret/search/conjunction_scorer.rb', line 47
def skip_to(target)
if(@first_time)
init(false)
end
@scorers.each do |scorer|
break if not @more
@more = scorer.skip_to(target)
end
sort_scorers() if @more
return do_next()
end
|
#sort_scorers ⇒ Object
90
91
92
93
|
# File 'lib/ferret/search/conjunction_scorer.rb', line 90
def sort_scorers()
@scorers.sort! {|a,b| a.doc <=> b.doc }
end
|