Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 13
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 / 13
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 / 2
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 $supported = [];
20
21    /** @var string[] */
22    private $unsupported = [];
23
24    /**
25     * @param string[] $profiles
26     */
27    public function __construct(
28        private readonly array $profiles = [],
29    ) {
30        parent::__construct();
31    }
32
33    /**
34     * @inheritDoc
35     */
36    public function classify( ParsedQuery $query ) {
37        $query->getRoot()->accept( $this );
38        return array_diff( $this->supported, $this->unsupported );
39    }
40
41    /**
42     * @inheritDoc
43     */
44    public function classes() {
45        return $this->profiles;
46    }
47
48    /**
49     * @inheritDoc
50     */
51    public function visitWordsQueryNode( WordsQueryNode $node ) {
52        $this->supported = array_unique( array_merge( $this->supported, $this->profiles ) );
53    }
54
55    /**
56     * @inheritDoc
57     */
58    public function visitPhraseQueryNode( PhraseQueryNode $node ) {
59        $this->supported = array_unique( array_merge( $this->supported, $this->profiles ) );
60    }
61
62    /**
63     * @inheritDoc
64     */
65    public function visitPhrasePrefixNode( PhrasePrefixNode $node ) {
66        $this->unsupported = array_unique( array_merge( $this->unsupported, $this->profiles ) );
67    }
68
69    /**
70     * @inheritDoc
71     */
72    public function visitFuzzyNode( FuzzyNode $node ) {
73        $this->unsupported = array_unique( array_merge( $this->unsupported, $this->profiles ) );
74    }
75
76    /**
77     * @inheritDoc
78     */
79    public function visitPrefixNode( PrefixNode $node ) {
80        $this->unsupported = array_unique( array_merge( $this->unsupported, $this->profiles ) );
81    }
82
83    /**
84     * @inheritDoc
85     */
86    public function visitWildcardNode( WildcardNode $node ) {
87        $this->unsupported = array_unique( array_merge( $this->unsupported, $this->profiles ) );
88    }
89
90    /**
91     * @inheritDoc
92     */
93    public function visitEmptyQueryNode( EmptyQueryNode $node ) {
94        // not relevant here
95    }
96
97    /**
98     * @inheritDoc
99     */
100    public function visitKeywordFeatureNode( KeywordFeatureNode $node ) {
101        // not relevant here
102    }
103}