Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
92.86% covered (success)
92.86%
13 / 14
80.00% covered (warning)
80.00%
4 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
MoreLikeThisFeature
92.86% covered (success)
92.86%
13 / 14
80.00% covered (warning)
80.00%
4 / 5
7.02
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getFeatureName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getKeywords
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 doApply
90.00% covered (success)
90.00%
9 / 10
0.00% covered (danger)
0.00%
0 / 1
3.01
 getConfig
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace CirrusSearch\Query;
4
5use CirrusSearch\Search\SearchContext;
6use CirrusSearch\SearchConfig;
7
8/**
9 * Finds pages similar to another one.
10 * (Non-greedy replacement of MoreLikeFeature)
11 */
12class MoreLikeThisFeature extends SimpleKeywordFeature {
13    use MoreLikeTrait;
14
15    /**
16     * @var SearchConfig
17     */
18    private $config;
19
20    public function __construct( SearchConfig $config ) {
21        $this->config = $config;
22    }
23
24    /**
25     * @inheritDoc
26     */
27    public function getFeatureName( $key, $valueDelimiter ) {
28        return "more_like";
29    }
30
31    /**
32     * @inheritDoc
33     */
34    protected function getKeywords() {
35        return [ "morelikethis" ];
36    }
37
38    /**
39     * @inheritDoc
40     */
41    protected function doApply( SearchContext $context, $key, $value, $quotedValue, $negated ) {
42        $context->setCacheTtl( $this->config->get( 'CirrusSearchMoreLikeThisTTL' ) );
43        $titles = $this->doExpand( $key, $value, $context );
44        if ( $titles === [] ) {
45            $context->setResultsPossible( false );
46            return [ null, true ];
47        }
48        $mlt = $this->buildMoreLikeQuery( $titles );
49        if ( !$negated ) {
50            $context->addNonTextQuery( $mlt );
51            return [ null, false ];
52        } else {
53            return [ $mlt, false ];
54        }
55    }
56
57    /**
58     * @return SearchConfig
59     */
60    public function getConfig(): SearchConfig {
61        return $this->config;
62    }
63}