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\CirrusConfigNames;
6use CirrusSearch\Search\SearchContext;
7use CirrusSearch\SearchConfig;
8
9/**
10 * Finds pages similar to another one.
11 * (Non-greedy replacement of MoreLikeFeature)
12 */
13class MoreLikeThisFeature extends SimpleKeywordFeature {
14    use MoreLikeTrait;
15
16    /**
17     * @var SearchConfig
18     */
19    private $config;
20
21    public function __construct( SearchConfig $config ) {
22        $this->config = $config;
23    }
24
25    /**
26     * @inheritDoc
27     */
28    public function getFeatureName( $key, $valueDelimiter ) {
29        return "more_like";
30    }
31
32    /**
33     * @inheritDoc
34     */
35    protected function getKeywords() {
36        return [ "morelikethis" ];
37    }
38
39    /**
40     * @inheritDoc
41     */
42    protected function doApply( SearchContext $context, $key, $value, $quotedValue, $negated ) {
43        $context->setCacheTtl( $this->config->get( CirrusConfigNames::MoreLikeThisTTL ) );
44        $titles = $this->doExpand( $key, $value, $context );
45        if ( $titles === [] ) {
46            $context->setResultsPossible( false );
47            return [ null, true ];
48        }
49        $mlt = $this->buildMoreLikeQuery( $titles );
50        if ( !$negated ) {
51            $context->addNonTextQuery( $mlt );
52            return [ null, false ];
53        } else {
54            return [ $mlt, false ];
55        }
56    }
57
58    public function getConfig(): SearchConfig {
59        return $this->config;
60    }
61}