Skip to content

Commit 99b1889

Browse files
Merge v1.x into v2.x (#1550)
2 parents 213648f + c386f6d commit 99b1889

File tree

375 files changed

+10727
-1956
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

375 files changed

+10727
-1956
lines changed

.gitattributes

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ rector.php export-ignore
2222
/src/Builder/Accumulator/*.php linguist-generated=true
2323
/src/Builder/Expression/*.php linguist-generated=true
2424
/src/Builder/Query/*.php linguist-generated=true
25-
/src/Builder/Projection/*.php linguist-generated=true
25+
/src/Builder/Search/*.php linguist-generated=true
2626
/src/Builder/Stage/*.php linguist-generated=true
2727
/tests/Builder/*/Pipelines.php linguist-generated=true

generator/README.md

+21-6
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,40 @@ Updating the generated code can be done only by modifying the code generator, or
1010
To run the generator, you need to have PHP 8.1+ installed and Composer.
1111

1212
1. Move to the `generator` directory: `cd generator`
13-
1. Install dependencies: `composer install`
14-
1. Run the generator: `./generate`
13+
2. Install dependencies: `composer install`
14+
3. Run the generator: `./generate`
1515

1616
## Configuration
1717

1818
The `generator/config/*.yaml` files contains the list of operators and stages that are supported by the library.
1919

20+
### Arguments
21+
22+
| Field | Type | Description |
23+
|---------------|---------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
24+
| `name` | `string` | The name of the argument. If it starts with `$`, the dollar is trimmed from the class property name |
25+
| `type` | list of `string` | The list of accepted types |
26+
| `description` | `string` | The description of the argument from MongoDB's documentation |
27+
| `optional` | `boolean` | Whether the argument is optional or not |
28+
| `valueMin` | `number` | The minimum value for a numeric argument |
29+
| `valueMax` | `number` | The maximum value for a numeric argument |
30+
| `variadic` | `string` | If sent, the argument is variadic. Defines the format `array` for a list or `object` for a map |
31+
| `variadicMin` | `integer` | The minimum number of arguments for a variadic parameter |
32+
| `default` | `scalar` or `array` | The default value for the argument |
33+
| `mergeObject` | `bool` | Default `false`. If `true`, the value must be an object and the properties of the value object are merged into the parent operator. `$group` stage uses it for the fields |
34+
2035
### Test pipelines
2136

22-
Each operator can contain a `tests` section with a list if pipelines. To represent specific BSON objects,
23-
it is necessary to use Yaml tags:
37+
Each operator can contain a `tests` section with a list if pipelines. To represent specific BSON objects, it is necessary to use Yaml tags:
2438

2539
| BSON Type | Example |
2640
|-------------|--------------------------------------------------------|
2741
| Regex | `!bson_regex '^abc'` <br/> `!bson_regex ['^abc', 'i']` |
2842
| Int64 | `!bson_int64 '123456789'` |
2943
| Decimal128 | `!bson_decimal128 '0.9'` |
3044
| UTCDateTime | `!bson_utcdatetime 0` |
45+
| ObjectId | `!bson_ObjectId '5a9427648b0beebeb69589a1` |
3146
| Binary | `!bson_binary 'IA=='` |
47+
| Binary UUID | `!bson_uuid 'fac32260-b511-4c69-8485-a2be5b7dda9e'` |
3248

33-
To add new test cases to operators, you can get inspiration from the official MongoDB documentation and use
34-
the `generator/js2yaml.html` web page to manually convert a pipeline array from JS to Yaml.
49+
To add new test cases to operators, you can get inspiration from the official MongoDB documentation and use the `generator/js2yaml.html` web page to manually convert a pipeline array from JS to Yaml.

generator/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"repositories": [
55
{
66
"type": "path",
7-
"url": "../",
7+
"url": "..",
88
"symlink": true
99
}
1010
],

generator/config/definitions.php

+12
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,16 @@
5858
OperatorTestGenerator::class,
5959
],
6060
],
61+
62+
// Search Operators
63+
[
64+
'configFiles' => __DIR__ . '/search',
65+
'namespace' => 'MongoDB\\Builder\\Search',
66+
'classNameSuffix' => 'Operator',
67+
'generators' => [
68+
OperatorClassGenerator::class,
69+
OperatorFactoryGenerator::class,
70+
OperatorTestGenerator::class,
71+
],
72+
],
6173
];

generator/config/expression/case.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ name: $case
33
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/switch/'
44
type:
55
- switchBranch
6-
encode: flat_object
6+
encode: object
7+
wrapObject: false
78
description: |
89
Represents a single case in a $switch expression
910
arguments:

generator/config/expressions.php

+12
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@
109109
'implements' => [ResolvesToAny::class],
110110
'acceptedTypes' => ['string'],
111111
],
112+
'searchOperator' => [
113+
'returnType' => Type\SearchOperatorInterface::class,
114+
'acceptedTypes' => [Type\SearchOperatorInterface::class, ...$bsonTypes['object']],
115+
],
112116
'geometry' => [
113117
'returnType' => Type\GeometryInterface::class,
114118
'acceptedTypes' => [Type\GeometryInterface::class, ...$bsonTypes['object']],
@@ -168,4 +172,12 @@
168172
'GeoPoint' => [
169173
'acceptedTypes' => [...$bsonTypes['object']],
170174
],
175+
176+
// Search
177+
'searchPath' => [
178+
'acceptedTypes' => ['string', 'array'],
179+
],
180+
'searchScore' => [
181+
'acceptedTypes' => [...$bsonTypes['object']],
182+
],
171183
];

generator/config/query/geoIntersects.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ name: $geoIntersects
33
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/geoIntersects/'
44
type:
55
- fieldQuery
6-
encode: single
6+
encode: object
77
description: |
88
Selects geometries that intersect with a GeoJSON geometry. The 2dsphere index supports $geoIntersects.
99
arguments:
1010
-
1111
name: geometry
12+
mergeObject: true
1213
type:
1314
- geometry
1415
tests:

generator/config/query/geoWithin.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ name: $geoWithin
33
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/'
44
type:
55
- fieldQuery
6-
encode: single
6+
encode: object
77
description: |
88
Selects geometries within a bounding GeoJSON geometry. The 2dsphere and 2d indexes support $geoWithin.
99
arguments:
1010
-
1111
name: geometry
12+
mergeObject: true
1213
type:
1314
- geometry
1415
tests:

generator/config/query/near.yaml

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,24 @@ name: $near
33
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/near/'
44
type:
55
- fieldQuery
6-
encode: dollar_object
6+
encode: object
77
description: |
88
Returns geospatial objects in proximity to a point. Requires a geospatial index. The 2dsphere and 2d indexes support $near.
99
arguments:
1010
-
1111
name: geometry
12+
mergeObject: true
1213
type:
1314
- geometry
1415
-
15-
name: maxDistance
16+
name: $maxDistance
1617
type:
1718
- number
1819
optional: true
1920
description: |
2021
Distance in meters. Limits the results to those documents that are at most the specified distance from the center point.
2122
-
22-
name: minDistance
23+
name: $minDistance
2324
type:
2425
- number
2526
optional: true

generator/config/query/nearSphere.yaml

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,24 @@ name: $nearSphere
33
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/nearSphere/'
44
type:
55
- fieldQuery
6-
encode: dollar_object
6+
encode: object
77
description: |
88
Returns geospatial objects in proximity to a point on a sphere. Requires a geospatial index. The 2dsphere and 2d indexes support $nearSphere.
99
arguments:
1010
-
1111
name: geometry
12+
mergeObject: true
1213
type:
1314
- geometry
1415
-
15-
name: maxDistance
16+
name: $maxDistance
1617
type:
1718
- number
1819
optional: true
1920
description: |
2021
Distance in meters.
2122
-
22-
name: minDistance
23+
name: $minDistance
2324
type:
2425
- number
2526
optional: true

generator/config/query/text.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,33 @@ name: $text
33
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/text/'
44
type:
55
- query
6-
encode: dollar_object
6+
encode: object
77
description: |
88
Performs text search.
99
arguments:
1010
-
11-
name: search
11+
name: $search
1212
type:
1313
- string
1414
description: |
1515
A string of terms that MongoDB parses and uses to query the text index. MongoDB performs a logical OR search of the terms unless specified as a phrase.
1616
-
17-
name: language
17+
name: $language
1818
type:
1919
- string
2020
optional: true
2121
description: |
2222
The language that determines the list of stop words for the search and the rules for the stemmer and tokenizer. If not specified, the search uses the default language of the index.
2323
If you specify a default_language value of none, then the text index parses through each word in the field, including stop words, and ignores suffix stemming.
2424
-
25-
name: caseSensitive
25+
name: $caseSensitive
2626
type:
2727
- bool
2828
optional: true
2929
description: |
3030
A boolean flag to enable or disable case sensitive search. Defaults to false; i.e. the search defers to the case insensitivity of the text index.
3131
-
32-
name: diacriticSensitive
32+
name: $diacriticSensitive
3333
type:
3434
- bool
3535
optional: true

generator/config/schema.json

+17-7
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
"resolvesToInt",
4747
"resolvesToTimestamp",
4848
"resolvesToLong",
49-
"resolvesToDecimal"
49+
"resolvesToDecimal",
50+
"searchOperator"
5051
]
5152
}
5253
},
@@ -60,16 +61,19 @@
6061
"enum": [
6162
"array",
6263
"object",
63-
"flat_object",
64-
"dollar_object",
6564
"single",
66-
"group"
65+
"search"
6766
]
6867
},
6968
"description": {
7069
"$comment": "The description of the argument from MongoDB's documentation.",
7170
"type": "string"
7271
},
72+
"wrapObject": {
73+
"$comment": "Wrap the properties in an object with the operator name",
74+
"type": "boolean",
75+
"default": true
76+
},
7377
"arguments": {
7478
"$comment": "An optional list of arguments for the operator.",
7579
"type": "array",
@@ -100,7 +104,7 @@
100104
"properties": {
101105
"name": {
102106
"type": "string",
103-
"pattern": "^(_?[a-z][a-zA-Z0-9]*|N)$"
107+
"pattern": "^([_$]?[a-z][a-zA-Z0-9]*|N)$"
104108
},
105109
"type": {
106110
"type": "array",
@@ -133,7 +137,8 @@
133137
"resolvesToInt", "intFieldPath", "int",
134138
"resolvesToTimestamp", "timestampFieldPath", "timestamp",
135139
"resolvesToLong", "longFieldPath", "long",
136-
"resolvesToDecimal", "decimalFieldPath", "decimal"
140+
"resolvesToDecimal", "decimalFieldPath", "decimal",
141+
"searchPath", "searchScore", "searchOperator"
137142
]
138143
}
139144
},
@@ -150,7 +155,7 @@
150155
"type": "number"
151156
},
152157
"valueMax": {
153-
"$comment": "The minimum value for a numeric argument.",
158+
"$comment": "The maximum value for a numeric argument.",
154159
"type": "number"
155160
},
156161
"variadic": {
@@ -169,6 +174,11 @@
169174
"default": {
170175
"$comment": "The default value for the argument.",
171176
"type": ["array", "boolean", "number", "string"]
177+
},
178+
"mergeObject": {
179+
"$comment": "Skip the name in object encoding and merge the properties of the value into the operator",
180+
"type": "boolean",
181+
"default": false
172182
}
173183
},
174184
"required": [

0 commit comments

Comments
 (0)