Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
85.71% covered (warning)
85.71%
12 / 14
60.00% covered (warning)
60.00%
3 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
LexemeResultSet
85.71% covered (warning)
85.71%
12 / 14
60.00% covered (warning)
60.00%
3 / 5
7.14
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
 transformOneResult
80.00% covered (warning)
80.00%
4 / 5
0.00% covered (danger)
0.00%
0 / 1
2.03
 getRawResults
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getElasticaResultSet
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 searchContainedSyntax
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2namespace Wikibase\Lexeme\Search\Elastic;
3
4use CirrusSearch\Search\BaseCirrusSearchResultSet;
5use Elastica\Result;
6use Elastica\ResultSet as ElasticaResultSet;
7use MediaWiki\Language\Language;
8use Wikibase\Lexeme\DataAccess\LexemeDescription;
9
10/**
11 * Result set for Lexeme fulltext search
12 */
13class LexemeResultSet extends BaseCirrusSearchResultSet {
14    /**
15     * @var Language
16     */
17    private $displayLanguage;
18    /**
19     * @var LexemeDescription
20     */
21    private $descriptionMaker;
22    /**
23     * Pre-processed results from Lexeme search, as raw data -
24     * not yet localized and without description generated.
25     * @var array
26     */
27    private $rawResults;
28
29    /**
30     * $rawResults indexed by hash on the originating elastica result set.
31     * @var array[]
32     */
33    private $rawResultsByHash = [];
34
35    /**
36     * @var \Elastica\ResultSet
37     */
38    private $elasticaResultSet;
39
40    /**
41     * @param ElasticaResultSet $ESresult
42     * @param Language $displayLanguage
43     * @param LexemeDescription $descriptionMaker
44     * @param array[] $lexemeResults Pre-processed data from Lexeme
45     */
46    public function __construct(
47        ElasticaResultSet $ESresult,
48        Language $displayLanguage,
49        LexemeDescription $descriptionMaker,
50        array $lexemeResults
51    ) {
52        $this->displayLanguage = $displayLanguage;
53        $this->descriptionMaker = $descriptionMaker;
54        $this->rawResults = $lexemeResults;
55        $this->elasticaResultSet = $ESresult;
56        foreach ( $lexemeResults as $raw ) {
57            $this->rawResultsByHash[$raw['elastica_result_hash']] = $raw;
58        }
59    }
60
61    /**
62     * @param Result $result
63     * @return LexemeResult|null
64     */
65    protected function transformOneResult( Result $result ) {
66        $hash = spl_object_hash( $result );
67        $raw = $this->rawResultsByHash[$hash] ?? null;
68        if ( $raw === null ) {
69            return null;
70        }
71        return new LexemeResult( $this->displayLanguage, $this->descriptionMaker, $raw );
72    }
73
74    /**
75     * Get raw results.
76     * Used in testing.
77     * @return array
78     */
79    public function getRawResults() {
80        return $this->rawResults;
81    }
82
83    /**
84     * @return \Elastica\ResultSet|null
85     */
86    public function getElasticaResultSet() {
87        return $this->elasticaResultSet;
88    }
89
90    /**
91     * Did the search contain search syntax?  If so, Special:Search won't offer
92     * the user a link to a create a page named by the search string because the
93     * name would contain the search syntax.
94     * @return bool
95     */
96    public function searchContainedSyntax() {
97        return false;
98    }
99
100}