Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

namespace Doctrine\ODM\MongoDB\Aggregation\Stage\Search;

use GeoJson\Geometry\LineString;
use GeoJson\Geometry\MultiPolygon;
use GeoJson\Geometry\Point;
use GeoJson\Geometry\Polygon;
use MongoDB\BSON\ObjectId;
use MongoDB\BSON\UTCDateTime;

interface CompoundSearchOperatorInterface extends SupportsCompoundableSearchOperators
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't want to repeat all the methods, we could make SupportsCompoundableSearchOperators generic and have a return type declared as Autocomplete&T. But that would not enforce the type as we can do with concrete return types.

Copy link
Copy Markdown
Member Author

@GromNaN GromNaN Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would mean an @extends tag for each interface implemented by SupportsAutocompleteOperator, which is worse.

/**
 * @template T of object
 * @extends SupportsAutocompleteOperator<T>
 * @extends SupportsEmbeddedDocumentOperator<T>
 * @extends SupportsEqualsOperator<T>
 * @extends SupportsExistsOperator<T>
 * @extends SupportsGeoShapeOperator<T>
 * @extends SupportsGeoWithinOperator<T>
 * @extends SupportsMoreLikeThisOperator<T>
 * @extends SupportsNearOperator<T>
 * @extends SupportsPhraseOperator<T>
 * @extends SupportsQueryStringOperator<T>
 * @extends SupportsRangeOperator<T>
 * @extends SupportsRegexOperator<T>
 * @extends SupportsTextOperator<T>
 * @extends SupportsWildcardOperator<T>
 */
interface SupportsCompoundableSearchOperators extends SupportsAutocompleteOperator, SupportsEmbeddedDocumentOperator, SupportsEqualsOperator, SupportsExistsOperator, SupportsGeoShapeOperator, SupportsGeoWithinOperator, SupportsMoreLikeThisOperator, SupportsNearOperator, SupportsPhraseOperator, SupportsQueryStringOperator, SupportsRangeOperator, SupportsRegexOperator, SupportsTextOperator, SupportsWildcardOperator
{
}
/** @template T of object */
interface SupportsAutocompleteOperator
{
    /** @return Autocomplete&T */
    public function autocomplete(string $path = '', string ...$query): Autocomplete;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I would typically go for a templated interface, I agree that the list of @extends annotations looks ugly. In that case, I'd rather update the method declarations in this interface, especially since we now have the ability to define the return types natively.

{
public function must(): Compound;
Expand All @@ -13,4 +20,39 @@ public function mustNot(): Compound;
public function should(?int $minimumShouldMatch = null): Compound;

public function filter(): Compound;

public function autocomplete(string $path = '', string ...$query): Autocomplete&CompoundSearchOperatorInterface;

public function embeddedDocument(string $path = ''): EmbeddedDocument&CompoundSearchOperatorInterface;

/** @param string|int|float|ObjectId|UTCDateTime|null $value */
public function equals(string $path = '', $value = null): Equals&CompoundSearchOperatorInterface;

public function exists(string $path): Exists&CompoundSearchOperatorInterface;

/** @param LineString|Point|Polygon|MultiPolygon|array<string, mixed>|null $geometry */
public function geoShape($geometry = null, string $relation = '', string ...$path): GeoShape&CompoundSearchOperatorInterface;

public function geoWithin(string ...$path): GeoWithin&CompoundSearchOperatorInterface;

/** @param array<string, mixed>|object $documents */
public function moreLikeThis(...$documents): MoreLikeThis&CompoundSearchOperatorInterface;

/**
* @param int|float|UTCDateTime|array<string, mixed>|Point|null $origin
* @param int|float|null $pivot
*/
public function near($origin = null, $pivot = null, string ...$path): Near&CompoundSearchOperatorInterface;

public function phrase(): Phrase&CompoundSearchOperatorInterface;

public function queryString(string $query = '', string $defaultPath = ''): QueryString&CompoundSearchOperatorInterface;

public function range(): Range&CompoundSearchOperatorInterface;

public function regex(): Regex&CompoundSearchOperatorInterface;

public function text(): Text&CompoundSearchOperatorInterface;

public function wildcard(): Wildcard&CompoundSearchOperatorInterface;
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function exists(string $path): Exists
return $this->addOperator(new Exists($this->getSearchStage(), $path));
}

/** @param LineString|Point|Polygon|MultiPolygon|array|null $geometry */
/** @param LineString|Point|Polygon|MultiPolygon|array<string, mixed>|null $geometry */
public function geoShape($geometry = null, string $relation = '', string ...$path): GeoShape
{
return $this->addOperator(new GeoShape($this->getSearchStage(), $geometry, $relation, ...$path));
Expand All @@ -70,8 +70,8 @@ public function moreLikeThis(...$documents): MoreLikeThis
}

/**
* @param int|float|UTCDateTime|array|Point|null $origin
* @param int|float|null $pivot
* @param int|float|UTCDateTime|array<string, mixed>|Point|null $origin
* @param int|float|null $pivot
*/
public function near($origin = null, $pivot = null, string ...$path): Near
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,103 +45,79 @@ abstract protected function getAddOperatorClosure(): Closure;
*/
abstract protected function addOperator(SearchOperator $operator): SearchOperator;

/** return Autocomplete&CompoundSearchOperatorInterface */
public function autocomplete(string $path = '', string ...$query): Autocomplete
public function autocomplete(string $path = '', string ...$query): Autocomplete&CompoundSearchOperatorInterface
{
return $this->addOperator(new CompoundedAutocomplete($this->getCompoundStage(), $this->getAddOperatorClosure(), $this->getSearchStage(), $path, ...$query));
}

/** @return EmbeddedDocument&CompoundSearchOperatorInterface */
public function embeddedDocument(string $path = ''): EmbeddedDocument
public function embeddedDocument(string $path = ''): EmbeddedDocument&CompoundSearchOperatorInterface
{
return $this->addOperator(new CompoundedEmbeddedDocument($this->getCompoundStage(), $this->getAddOperatorClosure(), $this->getSearchStage(), $path));
}

/**
* @param string|int|float|ObjectId|UTCDateTime|null $value
*
* @return Equals&CompoundSearchOperatorInterface
*/
public function equals(string $path = '', $value = null): Equals
/** @param string|int|float|ObjectId|UTCDateTime|null $value */
public function equals(string $path = '', $value = null): Equals&CompoundSearchOperatorInterface
{
return $this->addOperator(new CompoundedEquals($this->getCompoundStage(), $this->getAddOperatorClosure(), $this->getSearchStage(), $path, $value));
}

/** @return Exists&CompoundSearchOperatorInterface */
public function exists(string $path): Exists
public function exists(string $path): Exists&CompoundSearchOperatorInterface
{
return $this->addOperator(new CompoundedExists($this->getCompoundStage(), $this->getAddOperatorClosure(), $this->getSearchStage(), $path));
}

/**
* @param LineString|Point|Polygon|MultiPolygon|array|null $geometry
*
* @return GeoShape&CompoundSearchOperatorInterface
*/
public function geoShape($geometry = null, string $relation = '', string ...$path): GeoShape
/** @param LineString|Point|Polygon|MultiPolygon|array<string, mixed>|null $geometry */
public function geoShape($geometry = null, string $relation = '', string ...$path): GeoShape&CompoundSearchOperatorInterface
{
return $this->addOperator(new CompoundedGeoShape($this->getCompoundStage(), $this->getAddOperatorClosure(), $this->getSearchStage(), $geometry, $relation, ...$path));
}

/** @return GeoWithin&CompoundSearchOperatorInterface */
public function geoWithin(string ...$path): GeoWithin
public function geoWithin(string ...$path): GeoWithin&CompoundSearchOperatorInterface
{
return $this->addOperator(new CompoundedGeoWithin($this->getCompoundStage(), $this->getAddOperatorClosure(), $this->getSearchStage(), ...$path));
}

/**
* @param array<string, mixed>|object $documents
*
* @return MoreLikeThis&CompoundSearchOperatorInterface
*/
public function moreLikeThis(...$documents): MoreLikeThis
/** @param array<string, mixed>|object $documents */
public function moreLikeThis(...$documents): MoreLikeThis&CompoundSearchOperatorInterface
{
return $this->addOperator(new CompoundedMoreLikeThis($this->getCompoundStage(), $this->getAddOperatorClosure(), $this->getSearchStage(), ...$documents));
}

/**
* @param int|float|UTCDateTime|array|Point|null $origin
* @param int|float|null $pivot
*
* @return Near&CompoundSearchOperatorInterface
* @param int|float|UTCDateTime|array<string, mixed>|Point|null $origin
* @param int|float|null $pivot
*/
public function near($origin = null, $pivot = null, string ...$path): Near
public function near($origin = null, $pivot = null, string ...$path): Near&CompoundSearchOperatorInterface
{
return $this->addOperator(new CompoundedNear($this->getCompoundStage(), $this->getAddOperatorClosure(), $this->getSearchStage(), $origin, $pivot, ...$path));
}

/** @return Phrase&CompoundSearchOperatorInterface */
public function phrase(): Phrase
public function phrase(): Phrase&CompoundSearchOperatorInterface
{
return $this->addOperator(new CompoundedPhrase($this->getCompoundStage(), $this->getAddOperatorClosure(), $this->getSearchStage()));
}

/** @return QueryString&CompoundSearchOperatorInterface */
public function queryString(string $query = '', string $defaultPath = ''): QueryString
public function queryString(string $query = '', string $defaultPath = ''): QueryString&CompoundSearchOperatorInterface
{
return $this->addOperator(new CompoundedQueryString($this->getCompoundStage(), $this->getAddOperatorClosure(), $this->getSearchStage(), $query, $defaultPath));
}

/** @return Range&CompoundSearchOperatorInterface */
public function range(): Range
public function range(): Range&CompoundSearchOperatorInterface
{
return $this->addOperator(new CompoundedRange($this->getCompoundStage(), $this->getAddOperatorClosure(), $this->getSearchStage()));
}

/** @return Regex&CompoundSearchOperatorInterface */
public function regex(): Regex
public function regex(): Regex&CompoundSearchOperatorInterface
{
return $this->addOperator(new CompoundedRegex($this->getCompoundStage(), $this->getAddOperatorClosure(), $this->getSearchStage()));
}

/** @return Text&CompoundSearchOperatorInterface */
public function text(): Text
public function text(): Text&CompoundSearchOperatorInterface
{
return $this->addOperator(new CompoundedText($this->getCompoundStage(), $this->getAddOperatorClosure(), $this->getSearchStage()));
}

/** @return Wildcard&CompoundSearchOperatorInterface */
public function wildcard(): Wildcard
public function wildcard(): Wildcard&CompoundSearchOperatorInterface
{
return $this->addOperator(new CompoundedWildcard($this->getCompoundStage(), $this->getAddOperatorClosure(), $this->getSearchStage()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

interface SupportsGeoShapeOperator
{
/** @param LineString|Point|Polygon|MultiPolygon|array|null $geometry */
/** @param LineString|Point|Polygon|MultiPolygon|array<string, mixed>|null $geometry */
public function geoShape($geometry = null, string $relation = '', string ...$path): GeoShape;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
interface SupportsNearOperator
{
/**
* @param int|float|UTCDateTime|array|Point|null $origin
* @param int|float|null $pivot
* @param int|float|UTCDateTime|array<string, mixed>|Point|null $origin
* @param int|float|null $pivot
*/
public function near($origin = null, $pivot = null, string ...$path): Near;
}
Loading