File tree Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Original file line number Diff line number Diff line change 87
87
* quantization?: 'none'|'scalar'|'binary',
88
88
* } | array{
89
89
* type: 'filter',
90
- * path: string,
90
+ * path: string,
91
91
* }
92
92
* @phpstan-type TypeVectorSearchIndexDefinition array{
93
93
* fields: array<string, TypeVectorSearchIndexField>,
Original file line number Diff line number Diff line change @@ -525,9 +525,10 @@ public function testGetIndexes()
525
525
$ this ->assertSame ([], $ indexes );
526
526
}
527
527
528
- /** @todo requires SearchIndex support */
529
528
public function testSearchIndex (): void
530
529
{
530
+ $ this ->skipIfSearchIndexManagementIsNotSupported ();
531
+
531
532
Schema::create ('newcollection ' , function (Blueprint $ collection ) {
532
533
$ collection ->searchIndex ([
533
534
'mappings ' => [
@@ -550,6 +551,8 @@ public function testSearchIndex(): void
550
551
551
552
public function testVectorSearchIndex ()
552
553
{
554
+ $ this ->skipIfSearchIndexManagementIsNotSupported ();
555
+
553
556
Schema::create ('newcollection ' , function (Blueprint $ collection ) {
554
557
$ collection ->vectorSearchIndex ([
555
558
'fields ' => [
Original file line number Diff line number Diff line change 5
5
namespace MongoDB \Laravel \Tests ;
6
6
7
7
use Illuminate \Foundation \Application ;
8
+ use MongoDB \Driver \Exception \ServerException ;
8
9
use MongoDB \Laravel \MongoDBServiceProvider ;
9
10
use MongoDB \Laravel \Tests \Models \User ;
10
11
use MongoDB \Laravel \Validation \ValidationServiceProvider ;
@@ -64,4 +65,23 @@ protected function getEnvironmentSetUp($app): void
64
65
$ app ['config ' ]->set ('queue.failed.database ' , 'mongodb2 ' );
65
66
$ app ['config ' ]->set ('queue.failed.driver ' , 'mongodb ' );
66
67
}
68
+
69
+ public function skipIfSearchIndexManagementIsNotSupported (): void
70
+ {
71
+ try {
72
+ $ this ->getConnection ('mongodb ' )->getCollection ('test ' )->listSearchIndexes (['name ' => 'just_for_testing ' ]);
73
+ } catch (ServerException $ e ) {
74
+ switch ($ e ->getCode ()) {
75
+ // MongoDB 6: Unrecognized pipeline stage name: '$listSearchIndexes'
76
+ case 40324 :
77
+ // MongoDB 7: PlanExecutor error during aggregation :: caused by :: Search index commands are only supported with Atlas.
78
+ case 115 :
79
+ // MongoDB 8: Using Atlas Search Database Commands and the $listSearchIndexes aggregation stage requires additional configuration.
80
+ case 31082 :
81
+ self ::markTestSkipped ('Search index management is not supported on this server ' );
82
+ }
83
+
84
+ throw $ e ;
85
+ }
86
+ }
67
87
}
You can’t perform that action at this time.
0 commit comments