Skip to content

Commit c386f6d

Browse files
authored
PHPLIB-1596 Fully describe $search, $searchMeta and $vectorSearch stages (#1537)
1 parent 373bbc4 commit c386f6d

File tree

78 files changed

+9301
-55
lines changed

Some content is hidden

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

78 files changed

+9301
-55
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -22,5 +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/Search/*.php linguist-generated=true
2526
/src/Builder/Stage/*.php linguist-generated=true
2627
/tests/Builder/*/Pipelines.php linguist-generated=true

generator/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ Each operator can contain a `tests` section with a list if pipelines. To represe
4242
| Int64 | `!bson_int64 '123456789'` |
4343
| Decimal128 | `!bson_decimal128 '0.9'` |
4444
| UTCDateTime | `!bson_utcdatetime 0` |
45+
| ObjectId | `!bson_ObjectId '5a9427648b0beebeb69589a1` |
4546
| Binary | `!bson_binary 'IA=='` |
47+
| Binary UUID | `!bson_uuid 'fac32260-b511-4c69-8485-a2be5b7dda9e'` |
4648

4749
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/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/schema.json

+6-3
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,7 +61,8 @@
6061
"enum": [
6162
"array",
6263
"object",
63-
"single"
64+
"single",
65+
"search"
6466
]
6567
},
6668
"description": {
@@ -135,7 +137,8 @@
135137
"resolvesToInt", "intFieldPath", "int",
136138
"resolvesToTimestamp", "timestampFieldPath", "timestamp",
137139
"resolvesToLong", "longFieldPath", "long",
138-
"resolvesToDecimal", "decimalFieldPath", "decimal"
140+
"resolvesToDecimal", "decimalFieldPath", "decimal",
141+
"searchPath", "searchScore", "searchOperator"
139142
]
140143
}
141144
},
+152
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# $schema: ../schema.json
2+
name: autocomplete
3+
link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/'
4+
type:
5+
- searchOperator
6+
encode: object
7+
description: |
8+
The autocomplete operator performs a search for a word or phrase that
9+
contains a sequence of characters from an incomplete input string. The
10+
fields that you intend to query with the autocomplete operator must be
11+
indexed with the autocomplete data type in the collection's index definition.
12+
arguments:
13+
-
14+
name: path
15+
type:
16+
- searchPath
17+
-
18+
name: query
19+
type:
20+
- string
21+
-
22+
name: tokenOrder
23+
optional: true
24+
type:
25+
- string # any|sequential
26+
-
27+
name: fuzzy
28+
optional: true
29+
type:
30+
- object
31+
-
32+
name: score
33+
optional: true
34+
type:
35+
- searchScore
36+
tests:
37+
-
38+
name: 'Basic'
39+
link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#basic-example'
40+
pipeline:
41+
-
42+
$search:
43+
autocomplete:
44+
query: 'off'
45+
path: 'title'
46+
-
47+
$limit: 10
48+
-
49+
$project:
50+
_id: 0
51+
title: 1
52+
53+
-
54+
name: 'Fuzzy'
55+
link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#fuzzy-example'
56+
pipeline:
57+
-
58+
$search:
59+
autocomplete:
60+
query: 'pre'
61+
path: 'title'
62+
fuzzy:
63+
maxEdits: 1
64+
prefixLength: 1
65+
maxExpansions: 256
66+
-
67+
$limit: 10
68+
-
69+
$project:
70+
_id: 0
71+
title: 1
72+
73+
-
74+
name: 'Token Order any'
75+
link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#simple-any-example'
76+
pipeline:
77+
-
78+
$search:
79+
autocomplete:
80+
query: 'men with'
81+
path: 'title'
82+
tokenOrder: 'any'
83+
-
84+
$limit: 4
85+
-
86+
$project:
87+
_id: 0
88+
title: 1
89+
90+
-
91+
name: 'Token Order sequential'
92+
link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#simple-sequential-example'
93+
pipeline:
94+
-
95+
$search:
96+
autocomplete:
97+
query: 'men with'
98+
path: 'title'
99+
tokenOrder: 'sequential'
100+
-
101+
$limit: 4
102+
-
103+
$project:
104+
_id: 0
105+
title: 1
106+
107+
-
108+
name: 'Highlighting'
109+
link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#highlighting-example'
110+
pipeline:
111+
-
112+
$search:
113+
autocomplete:
114+
query: 'ger'
115+
path: 'title'
116+
highlight:
117+
path: 'title'
118+
-
119+
$limit: 5
120+
-
121+
$project:
122+
score:
123+
$meta: 'searchScore'
124+
_id: 0
125+
title: 1
126+
highlights:
127+
$meta: 'searchHighlights'
128+
129+
-
130+
name: 'Across Multiple Fields'
131+
link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#search-across-multiple-fields'
132+
pipeline:
133+
-
134+
$search:
135+
compound:
136+
should:
137+
-
138+
autocomplete:
139+
query: 'inter'
140+
path: 'title'
141+
-
142+
autocomplete:
143+
query: 'inter'
144+
path: 'plot'
145+
minimumShouldMatch: 1
146+
-
147+
$limit: 10
148+
-
149+
$project:
150+
_id: 0
151+
title: 1
152+
plot: 1

0 commit comments

Comments
 (0)