Skip to content

Commit df9daca

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

Some content is hidden

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

72 files changed

+8181
-6421
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: 12 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,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

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", "searchScore", "searchOperator"
137140
]
138141
}
139142
},
Lines changed: 152 additions & 0 deletions
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 #tokenOrder
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

generator/config/search/compound.yaml

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
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: minimumShouldMatch
38+
optional: true
39+
type:
40+
- int
41+
-
42+
name: score
43+
optional: true
44+
type:
45+
- searchScore
46+
tests:
47+
-
48+
name: 'must and mustNot'
49+
link: 'https://www.mongodb.com/docs/atlas/atlas-search/compound/#must-and-mustnot-example'
50+
pipeline:
51+
-
52+
$search:
53+
compound:
54+
must:
55+
-
56+
text:
57+
query: 'varieties'
58+
path: 'description'
59+
mustNot:
60+
-
61+
text:
62+
query: 'apples'
63+
path: 'description'
64+
65+
-
66+
name: 'must and should'
67+
link: 'https://www.mongodb.com/docs/atlas/atlas-search/compound/#must-and-should-example'
68+
pipeline:
69+
-
70+
$search:
71+
compound:
72+
must:
73+
-
74+
text:
75+
query: 'varieties'
76+
path: 'description'
77+
should:
78+
-
79+
text:
80+
query: 'Fuji'
81+
path: 'description'
82+
-
83+
$project:
84+
score:
85+
$meta: 'searchScore'
86+
87+
-
88+
name: 'minimumShouldMatch'
89+
link: 'https://www.mongodb.com/docs/atlas/atlas-search/compound/#minimumshouldmatch-example'
90+
pipeline:
91+
-
92+
$search:
93+
compound:
94+
must:
95+
-
96+
text:
97+
query: 'varieties'
98+
path: 'description'
99+
should:
100+
-
101+
text:
102+
query: 'Fuji'
103+
path: 'description'
104+
-
105+
text:
106+
query: 'Golden Delicious'
107+
path: 'description'
108+
minimumShouldMatch: 1
109+
110+
-
111+
name: 'Filter'
112+
link: 'https://www.mongodb.com/docs/atlas/atlas-search/compound/#filter-examples'
113+
pipeline:
114+
-
115+
$search:
116+
compound:
117+
must:
118+
-
119+
text:
120+
query: 'varieties'
121+
path: 'description'
122+
should:
123+
-
124+
text:
125+
query: 'banana'
126+
path: 'description'
127+
filter:
128+
-
129+
text:
130+
query: 'granny'
131+
path: 'description'
132+
133+
-
134+
name: 'Nested'
135+
link: 'https://www.mongodb.com/docs/atlas/atlas-search/compound/#nested-example'
136+
pipeline:
137+
-
138+
$search:
139+
compound:
140+
should:
141+
-
142+
text:
143+
query: 'apple'
144+
path: 'type'
145+
-
146+
compound:
147+
must:
148+
-
149+
text:
150+
query: 'organic'
151+
path: 'category'
152+
-
153+
equals:
154+
value: true
155+
path: 'in_stock'
156+
minimumShouldMatch: 1

0 commit comments

Comments
 (0)