5
5
namespace App \Http \Controllers ;
6
6
7
7
use App \Models \Movie ;
8
+ use Illuminate \Support \Facades \DB ;
8
9
use MongoDB \Laravel \Tests \TestCase ;
9
10
10
11
class ReadOperationsTest extends TestCase
@@ -15,7 +16,10 @@ protected function setUp(): void
15
16
16
17
parent ::setUp ();
17
18
18
- Movie::truncate ();
19
+ $ moviesCollection = DB ::connection ('mongodb ' )->getCollection ('movies ' );
20
+ $ moviesCollection ->drop ();
21
+ $ moviesCollection ->createIndex (['plot ' => 'text ' ]);
22
+
19
23
Movie::insert ([
20
24
['year ' => 2010 , 'imdb ' => ['rating ' => 9 ]],
21
25
['year ' => 2010 , 'imdb ' => ['rating ' => 9.5 ]],
@@ -30,10 +34,6 @@ protected function setUp(): void
30
34
['title ' => 'movie_b ' , 'plot ' => 'love is a long story ' ],
31
35
['title ' => 'movie_c ' , 'plot ' => 'went on a trip ' ],
32
36
]);
33
-
34
- $ collection = MongoDB::connection ('mongodb ' )->collection ('movies ' );
35
- $ index = ['plot ' => 'text ' ];
36
- $ collection ->createIndex ($ index );
37
37
}
38
38
39
39
/**
@@ -125,12 +125,11 @@ public function testTextRelevance(): void
125
125
{
126
126
// start-text-relevance
127
127
$ movies = Movie::where ('$text ' , ['$search ' => '"love story" ' ])
128
- ->orderBy ('score ' , ['$meta ' => 'textScore ' ])
128
+ ->orderBy ('score ' , ['$meta ' => 'textScore ' ])
129
129
->get ();
130
130
// end-text-relevance
131
131
132
132
$ this ->assertNotNull ($ movies );
133
133
$ this ->assertCount (2 , $ movies );
134
134
}
135
-
136
135
}
0 commit comments