Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
85.71% |
6 / 7 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
IncomingLinksScoringMethod | |
85.71% |
6 / 7 |
|
75.00% |
3 / 4 |
4.05 | |
0.00% |
0 / 1 |
score | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getRequiredFields | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setMaxDocs | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
explain | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace CirrusSearch\BuildDocument\Completion; |
4 | |
5 | /** |
6 | * Very simple scoring method based on incoming links |
7 | */ |
8 | class IncomingLinksScoringMethod implements SuggestScoringMethod { |
9 | /** |
10 | * @inheritDoc |
11 | */ |
12 | public function score( array $doc ) { |
13 | return $doc['incoming_links'] ?? 0; |
14 | } |
15 | |
16 | /** |
17 | * @inheritDoc |
18 | */ |
19 | public function getRequiredFields() { |
20 | return [ 'incoming_links' ]; |
21 | } |
22 | |
23 | /** |
24 | * @param int $maxDocs |
25 | */ |
26 | public function setMaxDocs( $maxDocs ) { |
27 | } |
28 | |
29 | /** |
30 | * Explain the score |
31 | * @param array $doc |
32 | * @return array |
33 | */ |
34 | public function explain( array $doc ) { |
35 | return [ |
36 | 'value' => $this->score( $doc ), |
37 | 'description' => 'Number of incoming links' |
38 | ]; |
39 | } |
40 | } |