File tree Expand file tree Collapse file tree 3 files changed +126
-0
lines changed
generator/config/expression Expand file tree Collapse file tree 3 files changed +126
-0
lines changed Original file line number Diff line number Diff line change @@ -11,3 +11,29 @@ arguments:
11
11
name : keyword
12
12
type :
13
13
- string
14
+ tests :
15
+ -
16
+ name : ' textScore'
17
+ link : ' https://www.mongodb.com/docs/manual/reference/operator/aggregation/meta/#-meta---textscore-'
18
+ pipeline :
19
+ -
20
+ $match :
21
+ $text :
22
+ $search : ' cake'
23
+ -
24
+ $group :
25
+ _id :
26
+ $meta : ' textScore'
27
+ count :
28
+ $sum : 1
29
+ -
30
+ name : ' indexKey'
31
+ link : ' https://www.mongodb.com/docs/manual/reference/operator/aggregation/meta/#-meta---indexkey-'
32
+ pipeline :
33
+ -
34
+ $match :
35
+ type : ' apparel'
36
+ -
37
+ $addFields :
38
+ idxKey :
39
+ $meta : ' indexKey'
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace MongoDB \Tests \Builder \Expression ;
6
+
7
+ use MongoDB \Builder \Accumulator ;
8
+ use MongoDB \Builder \Expression ;
9
+ use MongoDB \Builder \Pipeline ;
10
+ use MongoDB \Builder \Query ;
11
+ use MongoDB \Builder \Stage ;
12
+ use MongoDB \Tests \Builder \PipelineTestCase ;
13
+
14
+ /**
15
+ * Test $meta expression
16
+ */
17
+ class MetaOperatorTest extends PipelineTestCase
18
+ {
19
+ public function testIndexKey (): void
20
+ {
21
+ $ pipeline = new Pipeline (
22
+ Stage::match (
23
+ type: 'apparel ' ,
24
+ ),
25
+ Stage::addFields (
26
+ idxKey: Expression::meta ('indexKey ' ),
27
+ ),
28
+ );
29
+
30
+ $ this ->assertSamePipeline (Pipelines::MetaIndexKey, $ pipeline );
31
+ }
32
+
33
+ public function testTextScore (): void
34
+ {
35
+ $ pipeline = new Pipeline (
36
+ Stage::match (
37
+ Query::text (
38
+ search: 'cake ' ,
39
+ ),
40
+ ),
41
+ Stage::group (
42
+ _id: Expression::meta ('textScore ' ),
43
+ count: Accumulator::sum (1 ),
44
+ ),
45
+ );
46
+
47
+ $ this ->assertSamePipeline (Pipelines::MetaTextScore, $ pipeline );
48
+ }
49
+ }
You can’t perform that action at this time.
0 commit comments