Skip to content

Commit 4908571

Browse files
committed
Create classes for Search operators
1 parent 110aad7 commit 4908571

27 files changed

+1422
-1068
lines changed

generator/composer.json

Lines changed: 1 addition & 1 deletion
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

Lines changed: 12 additions & 0 deletions
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

Lines changed: 9 additions & 0 deletions
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,9 @@
168172
'GeoPoint' => [
169173
'acceptedTypes' => [...$bsonTypes['object']],
170174
],
175+
176+
// Search
177+
'searchPath' => [
178+
'acceptedTypes' => ['string', 'array'],
179+
],
171180
];

generator/config/schema.json

Lines changed: 6 additions & 3 deletions
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
},
@@ -63,7 +64,8 @@
6364
"flat_object",
6465
"dollar_object",
6566
"single",
66-
"group"
67+
"group",
68+
"search"
6769
]
6870
},
6971
"description": {
@@ -133,7 +135,8 @@
133135
"resolvesToInt", "intFieldPath", "int",
134136
"resolvesToTimestamp", "timestampFieldPath", "timestamp",
135137
"resolvesToLong", "longFieldPath", "long",
136-
"resolvesToDecimal", "decimalFieldPath", "decimal"
138+
"resolvesToDecimal", "decimalFieldPath", "decimal",
139+
"searchPath", "searchOperator"
137140
]
138141
}
139142
},
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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: query
15+
type:
16+
- string
17+
-
18+
name: path
19+
type:
20+
- string
21+
- object
22+
- array
23+
#- searchPath
24+
-
25+
name: tokenOrder
26+
optional: true
27+
type:
28+
- string #tokenOrder
29+
-
30+
name: fuzzy
31+
optional: true
32+
type:
33+
- object
34+
-
35+
name: score
36+
optional: true
37+
type:
38+
- object
39+
tests:
40+
-
41+
name: 'Autocomplete Basic'
42+
link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#basic-example'
43+
pipeline:
44+
-
45+
$search:
46+
autocomplete:
47+
query: 'off'
48+
path: 'title'
49+
-
50+
$limit: 10
51+
-
52+
$project:
53+
_id: 0
54+
title: 1
55+
56+
-
57+
name: 'Autocomplete Fuzzy'
58+
link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#fuzzy-example'
59+
pipeline:
60+
-
61+
$search:
62+
autocomplete:
63+
query: 'pre'
64+
path: 'title'
65+
fuzzy:
66+
maxEdits: 1
67+
prefixLength: 1
68+
maxExpansions: 256
69+
-
70+
$limit: 10
71+
-
72+
$project:
73+
_id: 0
74+
title: 1
75+
76+
-
77+
name: 'Autocomplete Token Order any'
78+
link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#simple-any-example'
79+
pipeline:
80+
-
81+
$search:
82+
autocomplete:
83+
query: 'men with'
84+
path: 'title'
85+
tokenOrder: 'any'
86+
-
87+
$limit: 4
88+
-
89+
$project:
90+
_id: 0
91+
title: 1
92+
93+
-
94+
name: 'Autocomplete Token Order sequential'
95+
link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#simple-sequential-example'
96+
pipeline:
97+
-
98+
$search:
99+
autocomplete:
100+
query: 'men with'
101+
path: 'title'
102+
tokenOrder: 'sequential'
103+
-
104+
$limit: 4
105+
-
106+
$project:
107+
_id: 0
108+
title: 1
109+
110+
-
111+
name: 'Autocomplete Highlighting'
112+
link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#highlighting-example'
113+
pipeline:
114+
-
115+
$search:
116+
autocomplete:
117+
query: 'ger'
118+
path: 'title'
119+
highlight:
120+
path: 'title'
121+
-
122+
$limit: 5
123+
-
124+
$project:
125+
score:
126+
$meta: 'searchScore'
127+
_id: 0
128+
title: 1
129+
highlights:
130+
$meta: 'searchHighlights'
131+
132+
-
133+
name: 'Autocomplete Across Multiple Fields'
134+
link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#search-across-multiple-fields'
135+
pipeline:
136+
-
137+
$search:
138+
compound:
139+
should:
140+
-
141+
autocomplete:
142+
query: 'inter'
143+
path: 'title'
144+
-
145+
autocomplete:
146+
query: 'inter'
147+
path: 'plot'
148+
minimumShouldMatch: 1
149+
-
150+
$limit: 10
151+
-
152+
$project:
153+
_id: 0
154+
title: 1
155+
plot: 1

generator/config/search/compound.yaml

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
# $schema: ../schema.json
2+
name: compound
3+
link: 'https://www.mongodb.com/docs/atlas/atlas-search/equals/'
4+
type:
5+
- searchOperator
6+
encode: object
7+
description: |
8+
The compound operator combines two or more operators into a single query.
9+
Each element of a compound query is called a clause, and each clause
10+
consists of one or more sub-queries.
11+
arguments:
12+
-
13+
name: must
14+
optional: true
15+
type:
16+
- searchOperator
17+
- array # of searchOperator
18+
-
19+
name: mustNot
20+
optional: true
21+
type:
22+
- searchOperator
23+
- array # of searchOperator
24+
-
25+
name: should
26+
optional: true
27+
type:
28+
- searchOperator
29+
- array # of searchOperator
30+
-
31+
name: filter
32+
optional: true
33+
type:
34+
- searchOperator
35+
- array # of searchOperator
36+
-
37+
name: path
38+
optional: true
39+
type:
40+
- string
41+
- object
42+
- array
43+
#- searchPath
44+
-
45+
name: minimumShouldMatch
46+
optional: true
47+
type:
48+
- int
49+
-
50+
name: score
51+
optional: true
52+
type:
53+
- object
54+
tests:
55+
-
56+
name: 'Compound must and mustNot'
57+
link: 'https://www.mongodb.com/docs/atlas/atlas-search/compound/#must-and-mustnot-example'
58+
pipeline:
59+
-
60+
$search:
61+
compound:
62+
must:
63+
-
64+
text:
65+
query: 'varieties'
66+
path: 'description'
67+
mustNot:
68+
-
69+
text:
70+
query: 'apples'
71+
path: 'description'
72+
73+
-
74+
name: 'Compound must and should'
75+
link: 'https://www.mongodb.com/docs/atlas/atlas-search/compound/#must-and-should-example'
76+
pipeline:
77+
-
78+
$search:
79+
compound:
80+
must:
81+
-
82+
text:
83+
query: 'varieties'
84+
path: 'description'
85+
should:
86+
-
87+
text:
88+
query: 'Fuji'
89+
path: 'description'
90+
-
91+
$project:
92+
score:
93+
$meta: 'searchScore'
94+
95+
-
96+
name: 'Compound minimumShouldMatch'
97+
link: 'https://www.mongodb.com/docs/atlas/atlas-search/compound/#minimumshouldmatch-example'
98+
pipeline:
99+
-
100+
$search:
101+
compound:
102+
must:
103+
-
104+
text:
105+
query: 'varieties'
106+
path: 'description'
107+
should:
108+
-
109+
text:
110+
query: 'Fuji'
111+
path: 'description'
112+
-
113+
text:
114+
query: 'Golden Delicious'
115+
path: 'description'
116+
minimumShouldMatch: 1
117+
118+
-
119+
name: 'Compound Filter'
120+
link: 'https://www.mongodb.com/docs/atlas/atlas-search/compound/#filter-examples'
121+
pipeline:
122+
-
123+
$search:
124+
compound:
125+
must:
126+
-
127+
text:
128+
query: 'varieties'
129+
path: 'description'
130+
should:
131+
-
132+
text:
133+
query: 'banana'
134+
path: 'description'
135+
filter:
136+
-
137+
text:
138+
query: 'granny'
139+
path: 'description'
140+
141+
-
142+
name: 'Compound Nested'
143+
link: 'https://www.mongodb.com/docs/atlas/atlas-search/compound/#nested-example'
144+
pipeline:
145+
-
146+
$search:
147+
compound:
148+
should:
149+
-
150+
text:
151+
query: 'apple'
152+
path: 'type'
153+
-
154+
compound:
155+
must:
156+
-
157+
text:
158+
query: 'organic'
159+
path: 'category'
160+
-
161+
equals:
162+
value: true
163+
path: 'in_stock'
164+
minimumShouldMatch: 1

0 commit comments

Comments
 (0)