Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add advanced type definition for Atlas Search Indexes #3234

Draft
wants to merge 1 commit into
base: 5.x
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 94 additions & 10 deletions src/Schema/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,98 @@
use function is_string;
use function key;

/**
* @link https://www.mongodb.com/docs/atlas/atlas-search/define-field-mappings/#std-label-fts-field-mappings
* @phpstan-type TypeSearchIndexField array{
* type: 'boolean'|'date'|'dateFacet'|'objectId'|'stringFacet'|'uuid',
* } | array{
* type: 'autocomplete',
* analyzer?: string,
* maxGrams?: int,
* minGrams?: int,
* tokenization?: 'edgeGram'|'rightEdgeGram'|'nGram',
* foldDiacritics?: bool,
* } | array{
* type: 'document'|'embeddedDocuments',
* dynamic?:bool,
* fields: array<string, array<mixed>>,
* } | array{
* type: 'geo',
* indexShapes?: bool,
* } | array{
* type: 'number'|'numberFacet',
* representation?: 'int64'|'double',
* indexIntegers?: bool,
* indexDoubles?: bool,
* } | array{
* type: 'token',
* normalizer?: 'lowercase'|'none',
* } | array{
* type: 'string',
* analyzer?: string,
* searchAnalyzer?: string,
* indexOptions?: 'docs'|'freqs'|'positions'|'offsets',
* store?: bool,
* ignoreAbove?: int,
* multi?: array<string, array<string, mixed>>,
* norms?: 'include'|'omit',
* }
* @link https://www.mongodb.com/docs/atlas/atlas-search/analyzers/character-filters/
* @phpstan-type TypeSearchIndexCharFilter array{
* type: 'icuNormalize'|'persian',
* } | array{
* type: 'htmlStrip',
* ignoredTags?: string[],
* } | array{
* type: 'mapping',
* mappings?: array<string, string>,
* }
* @link https://www.mongodb.com/docs/atlas/atlas-search/analyzers/token-filters/
* @phpstan-type TypeSearchIndexTokenFilter array{type: string, ...}
* @link https://www.mongodb.com/docs/atlas/atlas-search/analyzers/custom/
* @phpstan-type TypeSearchIndexAnalyzer array{
* name: string,
* charFilters?: TypeSearchIndexCharFilter,
* tokenizer: array{type: string},
* tokenFilters?: TypeSearchIndexTokenFilter,
* }
* @link https://www.mongodb.com/docs/atlas/atlas-search/stored-source-definition/#std-label-fts-stored-source-definition
* @phpstan-type TypeSearchIndexStoredSource bool | array{
* includes: array<string>,
* } | array{
* excludes: array<string>,
* }
* @link https://www.mongodb.com/docs/atlas/atlas-search/synonyms/#std-label-synonyms-ref
* @phpstan-type TypeSearchIndexSynonyms array{
* analyzer: string,
* name: string,
* source?: array{collection: string},
* }
* @link https://www.mongodb.com/docs/manual/reference/command/createSearchIndexes/#std-label-search-index-definition-create
* @phpstan-type TypeSearchIndexDefinition array{
* analyzer?: string,
* analyzers?: TypeSearchIndexAnalyzer[],
* searchAnalyzer?: string,
* mappings: array{dynamic: true} | array{dynamic?: bool, fields: array<string, TypeSearchIndexField|TypeSearchIndexField[]>},
* storedSource?: TypeSearchIndexStoredSource,
* synonyms?: TypeSearchIndexSynonyms[],
* }
* @link https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-type/#atlas-vector-search-index-fields
* @phpstan-type TypeVectorSearchIndexField array{
* type: 'vector',
* path: string,
* numDimensions: int,
* similarity: 'euclidean'|'cosine'|'dotProduct',
* quantization?: 'none'|'scalar'|'binary',
* } | array{
* type: 'filter',
* path: string,
* }
* @link https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-type/#atlas-vector-search-index-fields
* @phpstan-type TypeVectorSearchIndexDefinition array{
* fields: array<string, TypeVectorSearchIndexField>,
* }
*/
class Blueprint extends SchemaBlueprint
{
/**
Expand Down Expand Up @@ -308,15 +400,7 @@ public function sparse_and_unique($columns = null, $options = [])
*
* @see https://www.mongodb.com/docs/manual/reference/command/createSearchIndexes/#std-label-search-index-definition-create
*
* @phpstan-param array{
* analyzer?: string,
* analyzers?: list<array>,
* searchAnalyzer?: string,
* mappings: array{dynamic: true} | array{dynamic?: bool, fields: array<string, array>},
* storedSource?: bool|array,
* synonyms?: list<array>,
* ...
* } $definition
* @phpstan-param TypeSearchIndexDefinition $definition
*/
public function searchIndex(array $definition, string $name = 'default'): static
{
Expand All @@ -330,7 +414,7 @@ public function searchIndex(array $definition, string $name = 'default'): static
*
* @see https://www.mongodb.com/docs/manual/reference/command/createSearchIndexes/#std-label-vector-search-index-definition-create
*
* @phpstan-param array{fields: array<string, array{type: string, ...}>} $definition
* @phpstan-param TypeVectorSearchIndexDefinition $definition
*/
public function vectorSearchIndex(array $definition, string $name = 'default'): static
{
Expand Down
Loading