Skip to content

Commit c75317a

Browse files
committed
Clean-ups
1 parent e02da52 commit c75317a

File tree

5 files changed

+17
-20
lines changed

5 files changed

+17
-20
lines changed

src/Scout/ScoutEngine.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,7 @@
5454
*/
5555
final class ScoutEngine extends Engine
5656
{
57-
/**
58-
* Name of the Atlas Search index.
59-
*
60-
* @todo make this configurable
61-
*/
57+
/** Name of the Atlas Search index. */
6258
private const INDEX_NAME = 'scout';
6359

6460
// Atlas Search index management operations are asynchronous.
@@ -201,6 +197,10 @@ protected function performSearch(Builder $builder, ?int $offset = null): array
201197
],
202198
];
203199

200+
// "filter" specifies conditions on exact values to match
201+
// "mustNot" specifies conditions on exact values that must not match
202+
// They don't contribute to the relevance score
203+
// https://www.mongodb.com/docs/atlas/atlas-search/compound/#options
204204
foreach ($builder->wheres as $field => $value) {
205205
$compound['filter'][] = ['equals' => ['path' => $field, 'value' => $value]];
206206
}
@@ -213,6 +213,7 @@ protected function performSearch(Builder $builder, ?int $offset = null): array
213213
$compound['mustNot'][] = ['in' => ['path' => $field, 'value' => $value]];
214214
}
215215

216+
// Sort by field value only if specified
216217
$sort = [];
217218
foreach ($builder->orders as $order) {
218219
$sort[$order['column']] = $order['direction'] === 'asc' ? 1 : -1;
@@ -224,7 +225,7 @@ protected function performSearch(Builder $builder, ?int $offset = null): array
224225
'index' => self::INDEX_NAME,
225226
'compound' => $compound,
226227
'count' => ['type' => 'lowerBound'],
227-
...($builder->orders ? ['sort' => $sort] : []),
228+
...($sort ? ['sort' => $sort] : []),
228229
],
229230
],
230231
[
@@ -482,7 +483,7 @@ private function performSearchIndexOperation(Closure $closure): void
482483
} catch (ServerException $exception) {
483484
// @todo add error codes
484485
if (in_array($exception->getCode(), [])) {
485-
throw new \RuntimeException('Failed to perform search index operation. MongoDB Atlas cluster M10+ is required', 0, $exception);
486+
throw new \RuntimeException('Failed to perform search index operation. A MongoDB Atlas Cluster is required.', 0, $exception);
486487
}
487488
}
488489
}
@@ -497,6 +498,7 @@ private function getMapping(Model $model): array
497498

498499
if ($this->usesSoftDelete($model)) {
499500
// This field is a boolean represented with the integers 0 and 1
501+
// https://www.mongodb.com/docs/atlas/atlas-search/field-types/number-type/#configure-fts-field-type-field-properties
500502
$mapping['fields']['__soft_deleted'] ??= [
501503
'type' => 'number',
502504
'representation' => 'int64',

tests/Models/SchemaVersion.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
namespace MongoDB\Laravel\Tests\Models;
66

77
use MongoDB\Laravel\Eloquent\HasSchemaVersion;
8-
use MongoDB\Laravel\Eloquent\Model as Eloquent;
8+
use MongoDB\Laravel\Eloquent\Model;
99

10-
class SchemaVersion extends Eloquent
10+
class SchemaVersion extends Model
1111
{
1212
use HasSchemaVersion;
1313

tests/Models/SearchableModel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
namespace MongoDB\Laravel\Tests\Models;
66

77
use Laravel\Scout\Searchable;
8-
use MongoDB\Laravel\Eloquent\Model as Eloquent;
8+
use MongoDB\Laravel\Eloquent\Model;
99
use MongoDB\Laravel\Eloquent\SoftDeletes;
1010

11-
class SearchableModel extends Eloquent
11+
class SearchableModel extends Model
1212
{
1313
use Searchable;
1414
use SoftDeletes;

tests/Scout/ScoutEngineTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
use Closure;
77
use DateTimeImmutable;
88
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
9+
use Illuminate\Support\Collection as IlluminateCollection;
910
use Laravel\Scout\Builder;
1011
use Laravel\Scout\Jobs\RemoveFromSearch;
11-
use Laravel\Scout\Tests\Unit\AlgoliaEngineTest;
1212
use Mockery as m;
1313
use MongoDB\BSON\Document;
1414
use MongoDB\BSON\Regex;
@@ -390,7 +390,7 @@ public function testMapIds(array $results): void
390390

391391
$ids = $engine->mapIds($results);
392392

393-
$this->assertInstanceOf(\Illuminate\Support\Collection::class, $ids);
393+
$this->assertInstanceOf(IlluminateCollection::class, $ids);
394394
$this->assertEquals(['key_1', 'key_2'], $ids->all());
395395
}
396396

@@ -509,7 +509,6 @@ public function testDelete(): void
509509
]));
510510
}
511511

512-
/** @see AlgoliaEngineTest::test_delete_with_removeable_scout_collection_using_custom_search_key */
513512
public function testDeleteWithRemoveableScoutCollection(): void
514513
{
515514
$job = new RemoveFromSearch(EloquentCollection::make([

tests/Scout/ScoutIntegrationTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ class ScoutIntegrationTest extends TestCase
1616
{
1717
protected static string $userModel = SqlUser::class;
1818

19-
protected function defineEnvironment($app)
20-
{
21-
$app['config']->set('scout.driver', 'mongodb');
22-
$app['config']->set('scout.prefix', 'scout_');
23-
}
24-
2519
protected function defineDatabaseMigrations(): void
2620
{
2721
SqlUser::executeSchema();
@@ -59,6 +53,8 @@ protected function defineDatabaseMigrations(): void
5953
->state(new Sequence(...$collect->all()))
6054
->create();
6155

56+
// Recreate the indexes using the artisan commands
57+
// Ensure they return a success exit code (0)
6258
self::assertSame(0, artisan($this, 'scout:delete-index', ['name' => SqlUser::class]));
6359
self::assertSame(0, artisan($this, 'scout:index', ['name' => SqlUser::class]));
6460
self::assertSame(0, artisan($this, 'scout:import', ['model' => SqlUser::class]));

0 commit comments

Comments
 (0)