Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
80.00% covered (warning)
80.00%
4 / 5
CRAP
93.33% covered (success)
93.33%
14 / 15
MoreLikeThisFeature
0.00% covered (danger)
0.00%
0 / 1
80.00% covered (warning)
80.00%
4 / 5
7.01
93.33% covered (success)
93.33%
14 / 15
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getFeatureName
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getKeywords
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 doApply
0.00% covered (danger)
0.00%
0 / 1
3.01
90.00% covered (success)
90.00%
9 / 10
 getConfig
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
<?php
namespace CirrusSearch\Query;
use CirrusSearch\Search\SearchContext;
use CirrusSearch\SearchConfig;
/**
 * Finds pages similar to another one.
 * (Non-greedy replacement of MoreLikeFeature)
 */
class MoreLikeThisFeature extends SimpleKeywordFeature {
    use MoreLikeTrait;
    /**
     * @var SearchConfig
     */
    private $config;
    public function __construct( SearchConfig $config ) {
        $this->config = $config;
    }
    /**
     * @inheritDoc
     */
    public function getFeatureName( $key, $valueDelimiter ) {
        return "more_like";
    }
    /**
     * @inheritDoc
     */
    protected function getKeywords() {
        return [ "morelikethis" ];
    }
    /**
     * @inheritDoc
     */
    protected function doApply( SearchContext $context, $key, $value, $quotedValue, $negated ) {
        $context->setCacheTtl( $this->config->get( 'CirrusSearchMoreLikeThisTTL' ) );
        $titles = $this->doExpand( $key, $value, $context );
        if ( $titles === [] ) {
            $context->setResultsPossible( false );
            return [ null, true ];
        }
        $mlt = $this->buildMoreLikeQuery( $titles );
        if ( !$negated ) {
            $context->addNonTextQuery( $mlt );
            return [ null, false ];
        } else {
            return [ $mlt, false ];
        }
    }
    /**
     * @return SearchConfig
     */
    public function getConfig(): SearchConfig {
        return $this->config;
    }
}