Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
95.00% covered (success)
95.00%
19 / 20
87.50% covered (warning)
87.50%
7 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 1
PhraseQueryNode
95.00% covered (success)
95.00%
19 / 20
87.50% covered (warning)
87.50%
7 / 8
8
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
 unbalanced
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 toArray
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
 getPhrase
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getSlop
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isStem
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isUnbalanced
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 accept
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace CirrusSearch\Parser\AST;
4
5use CirrusSearch\Parser\AST\Visitor\Visitor;
6
7/**
8 * A phrase
9 */
10class PhraseQueryNode extends ParsedNode {
11    /**
12     * @var string
13     */
14    private $phrase;
15
16    /**
17     * @var int
18     */
19    private $slop;
20
21    /**
22     * @var bool
23     */
24    private $stem;
25
26    /**
27     * @var bool
28     */
29    private $unbalanced = false;
30
31    /**
32     * @param int $start
33     * @param int $end
34     * @param string $phrase
35     * @param int $slop the edit distance (in words) allowed between words defined in this query, set to -1
36     * if a specific slop is not specified in the syntax.
37     * @param bool $stem true if the syntax specifies that this phrase should be applied to stem fields
38     */
39    public function __construct( $start, $end, $phrase, $slop, $stem ) {
40        parent::__construct( $start, $end );
41        $this->phrase = $phrase;
42        $this->slop = $slop;
43        $this->stem = $stem;
44    }
45
46    /**
47     * @param int $start
48     * @param int $end
49     * @param string $phrase
50     * @return PhraseQueryNode
51     */
52    public static function unbalanced( $start, $end, $phrase ) {
53        $node = new self( $start, $end, $phrase, -1, false );
54        $node->unbalanced = true;
55        return $node;
56    }
57
58    /**
59     * @return array
60     */
61    public function toArray() {
62        return [
63            'phrase' => array_merge( parent::baseParams(), [
64                'phrase' => $this->phrase,
65                'slop' => $this->slop,
66                'stem' => $this->stem,
67                'unbalanced' => $this->unbalanced,
68            ] )
69        ];
70    }
71
72    /**
73     * The phrase
74     * @return string
75     */
76    public function getPhrase() {
77        return $this->phrase;
78    }
79
80    /**
81     * number of words allowed between phrase words
82     * (-1 to use wiki defaults)
83     * @return int
84     */
85    public function getSlop() {
86        return $this->slop;
87    }
88
89    /**
90     * Should this phrase be applied on stem fields
91     * @return bool
92     */
93    public function isStem() {
94        return $this->stem;
95    }
96
97    /**
98     * True if this phrase was created by detecting unbalanced quotes in the query
99     * @return bool
100     */
101    public function isUnbalanced() {
102        return $this->unbalanced;
103    }
104
105    /**
106     * @param Visitor $visitor
107     */
108    public function accept( Visitor $visitor ) {
109        $visitor->visitPhraseQueryNode( $this );
110    }
111}