Skip to content

Commit f5b1b66

Browse files
Statamic 6: Search indexing improvements (#48)
1 parent f46187c commit f5b1b66

File tree

6 files changed

+19
-45
lines changed

6 files changed

+19
-45
lines changed

.github/workflows/run-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
matrix:
2525
os: [ubuntu-latest]
2626
php: [8.3, 8.4]
27-
laravel: [11.*, 12.*]
27+
laravel: [12.*]
2828
stability: [prefer-lowest, prefer-stable]
2929

3030
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

composer.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@
2727
"meilisearch/meilisearch-php": "^1.0",
2828
"guzzlehttp/guzzle": "^7.3",
2929
"http-interop/http-factory-guzzle": "^1.0",
30-
"illuminate/support": "^10.0 || ^11.0 || ^12.0",
31-
"statamic/cms": "^6.0"
30+
"illuminate/support": "^12.0",
31+
"statamic/cms": "^6.0.0-beta.4",
32+
"spatie/laravel-ray": "^1.0@dev"
3233
},
3334
"require-dev": {
3435
"laravel/pint": "^1.21",
35-
"orchestra/testbench": "^9.0 || ^10.0",
36+
"orchestra/testbench": "^10.0",
3637
"phpunit/phpunit": "^11.5.10"
3738
},
3839
"autoload": {
@@ -68,5 +69,6 @@
6869
"developer": "Statamic Rad Pack"
6970
}
7071
},
71-
"minimum-stability": "dev"
72+
"minimum-stability": "dev",
73+
"prefer-stable": true
7274
}

config/statamic-meilisearch.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/Meilisearch/Index.php

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,12 @@ public function insert($document)
3131
return $this->insertMultiple(collect([$document]));
3232
}
3333

34-
public function insertMultiple($documents)
35-
{
36-
$documents
37-
->chunk(config('statamic-meilisearch.insert_chunk_size', 100))
38-
->each(function ($documents, $index) {
39-
$documents = $documents
40-
->map(fn ($document) => array_merge(
41-
$this->searchables()->fields($document),
42-
$this->getDefaultFields($document),
43-
))
44-
->values()
45-
->toArray();
46-
47-
$this->insertDocuments(new Documents($documents));
48-
});
49-
50-
return $this;
34+
public function fields(Searchable $searchable)
35+
{
36+
return array_merge(
37+
$this->searchables()->fields($searchable),
38+
$this->getDefaultFields($searchable)
39+
);
5140
}
5241

5342
public function delete($document)
@@ -66,9 +55,9 @@ public function exists()
6655
}
6756
}
6857

69-
protected function insertDocuments(Documents $documents)
58+
public function insertDocuments(Documents $documents)
7059
{
71-
$this->getIndex()->updateDocuments($documents->all());
60+
$this->getIndex()->updateDocuments($documents->values()->all());
7261
}
7362

7463
protected function deleteIndex()

src/ServiceProvider.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,6 @@ class ServiceProvider extends AddonServiceProvider
1111
{
1212
public function bootAddon()
1313
{
14-
$this->mergeConfigFrom(__DIR__.'/../config/statamic-meilisearch.php', 'statamic-meilisearch');
15-
16-
if ($this->app->runningInConsole()) {
17-
18-
$this->publishes([
19-
__DIR__.'/../config/statamic-meilisearch.php' => config_path('statamic-meilisearch.php'),
20-
], 'statamic-meilisearch-config');
21-
22-
}
23-
2414
Search::extend('meilisearch', function (Application $app, array $config, $name, $locale = null) {
2515
$client = $app->makeWith(Client::class, [
2616
'url' => $config['credentials']['url'],

tests/TestCase.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@ protected function resolveApplicationConfiguration($app)
1515
{
1616
parent::resolveApplicationConfiguration($app);
1717

18-
// add driver
1918
$app['config']->set('statamic.search.drivers.meilisearch', [
2019
'credentials' => [
2120
'url' => 'http://localhost:7700',
2221
'secret' => 'masterKey',
2322
],
2423
]);
2524

26-
// add index
25+
$app['config']->set('statamic.search.indexes.cp', [
26+
'driver' => 'null',
27+
]);
28+
2729
$app['config']->set('statamic.search.indexes.meilisearch_index', [
2830
'driver' => 'meilisearch',
2931
'searchables' => ['collection:pages'],

0 commit comments

Comments
 (0)