Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
75.00% covered (warning)
75.00%
3 / 4
CRAP
80.00% covered (warning)
80.00%
4 / 5
IncomingLinksScoringMethod
0.00% covered (danger)
0.00%
0 / 1
75.00% covered (warning)
75.00%
3 / 4
4.13
80.00% covered (warning)
80.00%
4 / 5
 score
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getRequiredFields
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setMaxDocs
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 explain
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
<?php
namespace CirrusSearch\BuildDocument\Completion;
/**
 * Very simple scoring method based on incoming links
 */
class IncomingLinksScoringMethod implements SuggestScoringMethod {
    /**
     * @inheritDoc
     */
    public function score( array $doc ) {
        return $doc['incoming_links'] ?? 0;
    }
    /**
     * @inheritDoc
     */
    public function getRequiredFields() {
        return [ 'incoming_links' ];
    }
    /**
     * @param int $maxDocs
     */
    public function setMaxDocs( $maxDocs ) {
    }
    /**
     * Explain the score
     * @param array $doc
     * @return array
     */
    public function explain( array $doc ) {
        return [
            'value' => $this->score( $doc ),
            'description' => 'Number of incoming links'
        ];
    }
}