Skip to content

Commit

Permalink
Create classes for Search operators
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Nov 26, 2024
1 parent 110aad7 commit df9daca
Show file tree
Hide file tree
Showing 72 changed files with 8,181 additions and 6,421 deletions.
2 changes: 1 addition & 1 deletion generator/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"repositories": [
{
"type": "path",
"url": "../",
"url": "..",
"symlink": true
}
],
Expand Down
12 changes: 12 additions & 0 deletions generator/config/definitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,16 @@
OperatorTestGenerator::class,
],
],

// Search Operators
[
'configFiles' => __DIR__ . '/search',
'namespace' => 'MongoDB\\Builder\\Search',
'classNameSuffix' => 'Operator',
'generators' => [
OperatorClassGenerator::class,
OperatorFactoryGenerator::class,
OperatorTestGenerator::class,
],
],
];
12 changes: 12 additions & 0 deletions generator/config/expressions.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@
'implements' => [ResolvesToAny::class],
'acceptedTypes' => ['string'],
],
'searchOperator' => [
'returnType' => Type\SearchOperatorInterface::class,
'acceptedTypes' => [Type\SearchOperatorInterface::class, ...$bsonTypes['object']],
],
'geometry' => [
'returnType' => Type\GeometryInterface::class,
'acceptedTypes' => [Type\GeometryInterface::class, ...$bsonTypes['object']],
Expand Down Expand Up @@ -168,4 +172,12 @@
'GeoPoint' => [
'acceptedTypes' => [...$bsonTypes['object']],
],

// Search
'searchPath' => [
'acceptedTypes' => ['string', 'array'],
],
'searchScore' => [
'acceptedTypes' => [...$bsonTypes['object']],
],
];
9 changes: 6 additions & 3 deletions generator/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"resolvesToInt",
"resolvesToTimestamp",
"resolvesToLong",
"resolvesToDecimal"
"resolvesToDecimal",
"searchOperator"
]
}
},
Expand All @@ -63,7 +64,8 @@
"flat_object",
"dollar_object",
"single",
"group"
"group",
"search"
]
},
"description": {
Expand Down Expand Up @@ -133,7 +135,8 @@
"resolvesToInt", "intFieldPath", "int",
"resolvesToTimestamp", "timestampFieldPath", "timestamp",
"resolvesToLong", "longFieldPath", "long",
"resolvesToDecimal", "decimalFieldPath", "decimal"
"resolvesToDecimal", "decimalFieldPath", "decimal",
"searchPath", "searchScore", "searchOperator"
]
}
},
Expand Down
152 changes: 152 additions & 0 deletions generator/config/search/autocomplete.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
# $schema: ../schema.json
name: autocomplete
link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/'
type:
- searchOperator
encode: object
description: |
The autocomplete operator performs a search for a word or phrase that
contains a sequence of characters from an incomplete input string. The
fields that you intend to query with the autocomplete operator must be
indexed with the autocomplete data type in the collection's index definition.
arguments:
-
name: path
type:
- searchPath
-
name: query
type:
- string
-
name: tokenOrder
optional: true
type:
- string #tokenOrder
-
name: fuzzy
optional: true
type:
- object
-
name: score
optional: true
type:
- searchScore
tests:
-
name: 'Basic'
link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#basic-example'
pipeline:
-
$search:
autocomplete:
query: 'off'
path: 'title'
-
$limit: 10
-
$project:
_id: 0
title: 1

-
name: 'Fuzzy'
link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#fuzzy-example'
pipeline:
-
$search:
autocomplete:
query: 'pre'
path: 'title'
fuzzy:
maxEdits: 1
prefixLength: 1
maxExpansions: 256
-
$limit: 10
-
$project:
_id: 0
title: 1

-
name: 'Token Order any'
link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#simple-any-example'
pipeline:
-
$search:
autocomplete:
query: 'men with'
path: 'title'
tokenOrder: 'any'
-
$limit: 4
-
$project:
_id: 0
title: 1

-
name: 'Token Order sequential'
link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#simple-sequential-example'
pipeline:
-
$search:
autocomplete:
query: 'men with'
path: 'title'
tokenOrder: 'sequential'
-
$limit: 4
-
$project:
_id: 0
title: 1

-
name: 'Highlighting'
link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#highlighting-example'
pipeline:
-
$search:
autocomplete:
query: 'ger'
path: 'title'
highlight:
path: 'title'
-
$limit: 5
-
$project:
score:
$meta: 'searchScore'
_id: 0
title: 1
highlights:
$meta: 'searchHighlights'

-
name: 'Across Multiple Fields'
link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#search-across-multiple-fields'
pipeline:
-
$search:
compound:
should:
-
autocomplete:
query: 'inter'
path: 'title'
-
autocomplete:
query: 'inter'
path: 'plot'
minimumShouldMatch: 1
-
$limit: 10
-
$project:
_id: 0
title: 1
plot: 1
156 changes: 156 additions & 0 deletions generator/config/search/compound.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
# $schema: ../schema.json
name: compound
link: 'https://www.mongodb.com/docs/atlas/atlas-search/equals/'
type:
- searchOperator
encode: object
description: |
The compound operator combines two or more operators into a single query.
Each element of a compound query is called a clause, and each clause
consists of one or more sub-queries.
arguments:
-
name: must
optional: true
type:
- searchOperator
- array # of searchOperator
-
name: mustNot
optional: true
type:
- searchOperator
- array # of searchOperator
-
name: should
optional: true
type:
- searchOperator
- array # of searchOperator
-
name: filter
optional: true
type:
- searchOperator
- array # of searchOperator
-
name: minimumShouldMatch
optional: true
type:
- int
-
name: score
optional: true
type:
- searchScore
tests:
-
name: 'must and mustNot'
link: 'https://www.mongodb.com/docs/atlas/atlas-search/compound/#must-and-mustnot-example'
pipeline:
-
$search:
compound:
must:
-
text:
query: 'varieties'
path: 'description'
mustNot:
-
text:
query: 'apples'
path: 'description'

-
name: 'must and should'
link: 'https://www.mongodb.com/docs/atlas/atlas-search/compound/#must-and-should-example'
pipeline:
-
$search:
compound:
must:
-
text:
query: 'varieties'
path: 'description'
should:
-
text:
query: 'Fuji'
path: 'description'
-
$project:
score:
$meta: 'searchScore'

-
name: 'minimumShouldMatch'
link: 'https://www.mongodb.com/docs/atlas/atlas-search/compound/#minimumshouldmatch-example'
pipeline:
-
$search:
compound:
must:
-
text:
query: 'varieties'
path: 'description'
should:
-
text:
query: 'Fuji'
path: 'description'
-
text:
query: 'Golden Delicious'
path: 'description'
minimumShouldMatch: 1

-
name: 'Filter'
link: 'https://www.mongodb.com/docs/atlas/atlas-search/compound/#filter-examples'
pipeline:
-
$search:
compound:
must:
-
text:
query: 'varieties'
path: 'description'
should:
-
text:
query: 'banana'
path: 'description'
filter:
-
text:
query: 'granny'
path: 'description'

-
name: 'Nested'
link: 'https://www.mongodb.com/docs/atlas/atlas-search/compound/#nested-example'
pipeline:
-
$search:
compound:
should:
-
text:
query: 'apple'
path: 'type'
-
compound:
must:
-
text:
query: 'organic'
path: 'category'
-
equals:
value: true
path: 'in_stock'
minimumShouldMatch: 1
Loading

0 comments on commit df9daca

Please sign in to comment.