Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
92.31% covered (success)
92.31%
12 / 13
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
WeightedTags
92.31% covered (success)
92.31%
12 / 13
66.67% covered (warning)
66.67%
2 / 3
3.00
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 getMapping
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
 getEngineHints
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace CirrusSearch\Wikimedia;
4
5use CirrusSearch\Search\CirrusIndexField;
6use SearchEngine;
7use SearchIndexFieldDefinition;
8
9/**
10 * Field definitions for the (Wikimedia-specific) weighted_tags search feature.
11 * @package CirrusSearch\Wikimedia
12 * @see WeightedTagsHooks
13 */
14class WeightedTags extends SearchIndexFieldDefinition {
15    /**
16     * @var string
17     */
18    private $indexAnalyzer;
19    /**
20     * @var string
21     */
22    private $searchAnalyzer;
23    /**
24     * @var string
25     */
26    private $similarity;
27
28    /**
29     * @param string $name name of the field
30     * @param string $type type of the field
31     * @param string $indexAnalyzer
32     * @param string $searchAnalyzer
33     * @param string $similarity similiraty name to use
34     */
35    public function __construct(
36        $name,
37        $type,
38        string $indexAnalyzer,
39        string $searchAnalyzer,
40        string $similarity
41    ) {
42        parent::__construct( $name, $type );
43        $this->indexAnalyzer = $indexAnalyzer;
44        $this->searchAnalyzer = $searchAnalyzer;
45        $this->similarity = $similarity;
46    }
47
48    /**
49     * @param SearchEngine $engine the search engine requesting this mapping
50     * @return array the elasticsearch mapping for this field
51     */
52    public function getMapping( SearchEngine $engine ) {
53        return [
54            'type' => 'text',
55            'analyzer' => $this->indexAnalyzer,
56            'search_analyzer' => $this->searchAnalyzer,
57            'index_options' => 'freqs',
58            'norms' => false,
59            'similarity' => $this->similarity,
60        ];
61    }
62
63    /**
64     * @inheritDoc
65     */
66    public function getEngineHints( SearchEngine $engine ) {
67        // see https://github.com/wikimedia/search-extra/blob/master/docs/super_detect_noop.md
68        return [ CirrusIndexField::NOOP_HINT => CirrusIndexField::MULTILIST_HANDLER ];
69    }
70}