Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 11
CRAP
0.00% covered (danger)
0.00%
0 / 1
MediaSearchASTClassifier
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 11
132
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 classify
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 classes
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 visitWordsQueryNode
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 visitPhraseQueryNode
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 visitPhrasePrefixNode
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 visitFuzzyNode
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 visitPrefixNode
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 visitWildcardNode
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 visitEmptyQueryNode
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 visitKeywordFeatureNode
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace Wikibase\MediaInfo\Search;
4
5use CirrusSearch\Parser\AST\EmptyQueryNode;
6use CirrusSearch\Parser\AST\FuzzyNode;
7use CirrusSearch\Parser\AST\KeywordFeatureNode;
8use CirrusSearch\Parser\AST\ParsedQuery;
9use CirrusSearch\Parser\AST\PhrasePrefixNode;
10use CirrusSearch\Parser\AST\PhraseQueryNode;
11use CirrusSearch\Parser\AST\PrefixNode;
12use CirrusSearch\Parser\AST\Visitor\LeafVisitor;
13use CirrusSearch\Parser\AST\WildcardNode;
14use CirrusSearch\Parser\AST\WordsQueryNode;
15use CirrusSearch\Parser\ParsedQueryClassifier;
16
17class MediaSearchASTClassifier extends LeafVisitor implements ParsedQueryClassifier {
18    /** @var string[] */
19    private $profiles;
20
21    /** @var string[] */
22    private $supported = [];
23
24    /** @var string[] */
25    private $unsupported = [];
26
27    /**
28     * @param string[] $profiles
29     */
30    public function __construct( array $profiles = [] ) {
31        parent::__construct();
32        $this->profiles = $profiles;
33    }
34
35    /**
36     * @inheritDoc
37     */
38    public function classify( ParsedQuery $query ) {
39        $query->getRoot()->accept( $this );
40        return array_diff( $this->supported, $this->unsupported );
41    }
42
43    /**
44     * @inheritDoc
45     */
46    public function classes() {
47        return $this->profiles;
48    }
49
50    /**
51     * @inheritDoc
52     */
53    public function visitWordsQueryNode( WordsQueryNode $node ) {
54        $this->supported = array_unique( array_merge( $this->supported, $this->profiles ) );
55    }
56
57    /**
58     * @inheritDoc
59     */
60    public function visitPhraseQueryNode( PhraseQueryNode $node ) {
61        $this->supported = array_unique( array_merge( $this->supported, $this->profiles ) );
62    }
63
64    /**
65     * @inheritDoc
66     */
67    public function visitPhrasePrefixNode( PhrasePrefixNode $node ) {
68        $this->unsupported = array_unique( array_merge( $this->unsupported, $this->profiles ) );
69    }
70
71    /**
72     * @inheritDoc
73     */
74    public function visitFuzzyNode( FuzzyNode $node ) {
75        $this->unsupported = array_unique( array_merge( $this->unsupported, $this->profiles ) );
76    }
77
78    /**
79     * @inheritDoc
80     */
81    public function visitPrefixNode( PrefixNode $node ) {
82        $this->unsupported = array_unique( array_merge( $this->unsupported, $this->profiles ) );
83    }
84
85    /**
86     * @inheritDoc
87     */
88    public function visitWildcardNode( WildcardNode $node ) {
89        $this->unsupported = array_unique( array_merge( $this->unsupported, $this->profiles ) );
90    }
91
92    /**
93     * @inheritDoc
94     */
95    public function visitEmptyQueryNode( EmptyQueryNode $node ) {
96        // not relevant here
97    }
98
99    /**
100     * @inheritDoc
101     */
102    public function visitKeywordFeatureNode( KeywordFeatureNode $node ) {
103        // not relevant here
104    }
105}