Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 19ed55e

Browse files
authored
PHPORM-28 Add Scout engine to index into MongoDB Search (#3205)
1 parent 697c36f commit 19ed55e

14 files changed

+1555
-8
lines changed

‎.github/workflows/build-ci.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ jobs:
6565
until docker exec --tty mongodb mongosh 127.0.0.1:27017 --eval "db.runCommand({ ping: 1 })"; do
6666
sleep 1
6767
done
68+
until docker exec --tty mongodb mongosh 127.0.0.1:27017 --eval "db.createCollection('connection_test') && db.getCollection('connection_test').createSearchIndex({mappings:{dynamic: true}})"; do
69+
sleep 1
70+
done
6871
6972
- name: "Show MongoDB server status"
7073
run: |

‎composer.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
},
3636
"require-dev": {
3737
"mongodb/builder": "^0.2",
38+
"laravel/scout": "^11",
3839
"league/flysystem-gridfs": "^3.28",
3940
"league/flysystem-read-only": "^3.0",
4041
"phpunit/phpunit": "^10.3",

‎docker-compose.yml‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: '3.5'
2-
31
services:
42
app:
53
tty: true
@@ -16,11 +14,11 @@ services:
1614

1715
mongodb:
1816
container_name: mongodb
19-
image: mongo:latest
17+
image: mongodb/mongodb-atlas-local:latest
2018
ports:
2119
- "27017:27017"
2220
healthcheck:
23-
test: echo 'db.runCommand("ping").ok' | mongosh mongodb:27017 --quiet
21+
test: mongosh --quiet --eval 'db.runCommand("ping").ok'
2422
interval: 10s
2523
timeout: 10s
2624
retries: 5

‎phpstan-baseline.neon‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,8 @@ parameters:
2424
message: "#^Method Illuminate\\\\Database\\\\Schema\\\\Blueprint\\:\\:create\\(\\) invoked with 1 parameter, 0 required\\.$#"
2525
count: 1
2626
path: src/Schema/Builder.php
27+
28+
-
29+
message: "#^Call to an undefined method Illuminate\\\\Support\\\\HigherOrderCollectionProxy\\<\\(int\\|string\\), Illuminate\\\\Database\\\\Eloquent\\\\Model\\>\\:\\:pushSoftDeleteMetadata\\(\\)\\.$#"
30+
count: 1
31+
path: src/Scout/ScoutEngine.php

‎phpunit.xml.dist‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</testsuite>
1818
</testsuites>
1919
<php>
20-
<env name="MONGODB_URI" value="mongodb://mongodb/"/>
20+
<env name="MONGODB_URI" value="mongodb://mongodb/?directConnection=true"/>
2121
<env name="MONGODB_DATABASE" value="unittest"/>
2222
<env name="SQLITE_DATABASE" value=":memory:"/>
2323
<env name="QUEUE_CONNECTION" value="database"/>

‎src/MongoDBServiceProvider.php‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,22 @@
77
use Closure;
88
use Illuminate\Cache\CacheManager;
99
use Illuminate\Cache\Repository;
10+
use Illuminate\Container\Container;
1011
use Illuminate\Filesystem\FilesystemAdapter;
1112
use Illuminate\Filesystem\FilesystemManager;
1213
use Illuminate\Foundation\Application;
1314
use Illuminate\Session\SessionManager;
1415
use Illuminate\Support\ServiceProvider;
1516
use InvalidArgumentException;
17+
use Laravel\Scout\EngineManager;
1618
use League\Flysystem\Filesystem;
1719
use League\Flysystem\GridFS\GridFSAdapter;
1820
use League\Flysystem\ReadOnly\ReadOnlyFilesystemAdapter;
1921
use MongoDB\GridFS\Bucket;
2022
use MongoDB\Laravel\Cache\MongoStore;
2123
use MongoDB\Laravel\Eloquent\Model;
2224
use MongoDB\Laravel\Queue\MongoConnector;
25+
use MongoDB\Laravel\Scout\ScoutEngine;
2326
use RuntimeException;
2427
use Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler;
2528

@@ -102,6 +105,7 @@ public function register()
102105
});
103106

104107
$this->registerFlysystemAdapter();
108+
$this->registerScoutEngine();
105109
}
106110

107111
private function registerFlysystemAdapter(): void
@@ -155,4 +159,21 @@ private function registerFlysystemAdapter(): void
155159
});
156160
});
157161
}
162+
163+
private function registerScoutEngine(): void
164+
{
165+
$this->app->resolving(EngineManager::class, function (EngineManager $engineManager) {
166+
$engineManager->extend('mongodb', function (Container $app) {
167+
$connectionName = $app->get('config')->get('scout.mongodb.connection', 'mongodb');
168+
$connection = $app->get('db')->connection($connectionName);
169+
$softDelete = (bool) $app->get('config')->get('scout.soft_delete', false);
170+
171+
assert($connection instanceof Connection, new InvalidArgumentException(sprintf('The connection "%s" is not a MongoDB connection.', $connectionName)));
172+
173+
return new ScoutEngine($connection->getMongoDB(), $softDelete);
174+
});
175+
176+
return $engineManager;
177+
});
178+
}
158179
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /