File tree 6 files changed +109
-5
lines changed
6 files changed +109
-5
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+ namespace Elastica \Query ;
3
+
4
+ /**
5
+ * Abstract query object. Should be extended by all query types.
6
+ *
7
+ * @author Alessandro Chitolina <[email protected] >
8
+ */
9
+ abstract class AbstractSpanQuery extends AbstractQuery
10
+ {
11
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ namespace Elastica \Query ;
3
+
4
+ use Elastica \Exception \InvalidException ;
5
+
6
+ /**
7
+ * SpanFirst query.
8
+ *
9
+ * @author Alessandro Chitolina <[email protected] >
10
+ *
11
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-first-query.html
12
+ */
13
+ class SpanFirst extends AbstractSpanQuery
14
+ {
15
+ /**
16
+ * Set the query to be wrapped into the span multi query.
17
+ *
18
+ * @param \Elastica\Query\AbstractSpanQuery|array $args Matching query
19
+ *
20
+ * @return $this
21
+ */
22
+ public function setMatch ($ args )
23
+ {
24
+ return $ this ->_addQuery ('match ' , $ args );
25
+ }
26
+
27
+ /**
28
+ * Set the maximum end position for the match query.
29
+ *
30
+ * @param int $end
31
+ *
32
+ * @return $this
33
+ */
34
+ public function setEnd ($ end )
35
+ {
36
+ $ this ->setParam ('end ' , $ end );
37
+
38
+ return $ this ;
39
+ }
40
+
41
+ /**
42
+ * Adds a query to the current object.
43
+ *
44
+ * @param string $type Query type
45
+ * @param \Elastica\Query\AbstractQuery|array $args Query
46
+ *
47
+ * @throws \Elastica\Exception\InvalidException If not valid query
48
+ *
49
+ * @return $this
50
+ */
51
+ protected function _addQuery ($ type , $ args )
52
+ {
53
+ if (!is_array ($ args ) && !($ args instanceof AbstractSpanQuery)) {
54
+ throw new InvalidException ('Invalid parameter. Has to be array or instance of Elastica\Query\AbstractSpanQuery ' );
55
+ }
56
+
57
+ return $ this ->setParam ($ type , $ args );
58
+ }
59
+ }
Original file line number Diff line number Diff line change 6
6
/**
7
7
* SpanMulti query.
8
8
*
9
+ * @author Alessandro Chitolina <[email protected] >
10
+ *
9
11
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-multi-term-query.html
10
12
*/
11
- class SpanMulti extends AbstractQuery
13
+ class SpanMulti extends AbstractSpanQuery
12
14
{
13
15
/**
14
16
* Set the query to be wrapped into the span multi query.
Original file line number Diff line number Diff line change 4
4
/**
5
5
* SpanTerm query.
6
6
*
7
+ * @author Alessandro Chitolina <[email protected] >
8
+ *
7
9
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-term-query.html
8
10
*/
9
- class SpanTerm extends AbstractQuery
11
+ class SpanTerm extends AbstractSpanQuery
10
12
{
11
13
/**
12
14
* Constructs the SpanTerm query object.
Original file line number Diff line number Diff line change
1
+ <?php
2
+ namespace Elastica \Test \Query ;
3
+
4
+ use Elastica \Query \SpanFirst ;
5
+ use Elastica \Query \SpanTerm ;
6
+ use Elastica \Test \Base as BaseTest ;
7
+
8
+ class SpanFirstTest extends BaseTest
9
+ {
10
+ /**
11
+ * @group unit
12
+ */
13
+ public function testToArray ()
14
+ {
15
+ $ query = new SpanFirst ();
16
+ $ query ->setMatch (new SpanTerm (['user ' => 'kimchy ' ]));
17
+ $ query ->setEnd (3 );
18
+
19
+ $ data = $ query ->toArray ();
20
+
21
+ $ this ->assertEquals ([
22
+ 'span_first ' => [
23
+ 'match ' => [
24
+ 'span_term ' => ['user ' => 'kimchy ' ],
25
+ ],
26
+ 'end ' => 3 ,
27
+ ],
28
+ ], $ data );
29
+ }
30
+ }
Original file line number Diff line number Diff line change @@ -20,9 +20,9 @@ public function testToArray()
20
20
$ this ->assertEquals ([
21
21
'span_multi ' => [
22
22
'match ' => [
23
- 'prefix ' => ['user ' => ['value ' => 'ki ' ]]
24
- ]
25
- ]
23
+ 'prefix ' => ['user ' => ['value ' => 'ki ' ]],
24
+ ],
25
+ ],
26
26
], $ data );
27
27
}
28
28
}
You can’t perform that action at this time.
0 commit comments