Skip to content

Commit 7ee1fe0

Browse files
Statamic 6: Search indexing improvements (#24)
1 parent 2157198 commit 7ee1fe0

6 files changed

Lines changed: 19 additions & 46 deletions

File tree

.github/workflows/run-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ jobs:
2727
matrix:
2828
os: [ubuntu-latest]
2929
php: [8.3, 8.4]
30-
laravel: [11.*, 12.*]
31-
statamic: [5.*, 6.*]
30+
laravel: [12.*]
31+
statamic: [6.*]
3232
dependency-version: [prefer-stable]
3333

3434
name: P${{ matrix.php }} - L${{ matrix.laravel }} - S${{ matrix.statamic }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}

composer.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
"php": "^8.2",
1919
"guzzlehttp/guzzle": "^7.3",
2020
"http-interop/http-factory-guzzle": "^1.0",
21-
"illuminate/support": "^11.0 || ^12.0",
22-
"statamic/cms": "^5.38 || ^6.0",
21+
"illuminate/support": "^12.0",
22+
"statamic/cms": "^6.0.0-beta.4",
2323
"typesense/typesense-php": "^4.9"
2424
},
2525
"require-dev": {
2626
"laravel/pint": "^1.17",
27-
"orchestra/testbench": "^8.14 || ^9.0 || ^10.0",
28-
"phpunit/phpunit": "^10.0 || ^11.0"
27+
"orchestra/testbench": "^10.0",
28+
"phpunit/phpunit": "^11.0"
2929
},
3030
"autoload": {
3131
"psr-4": {
@@ -58,5 +58,7 @@
5858
"name": "Typesense",
5959
"description": "Typesense search driver for Statamic"
6060
}
61-
}
61+
},
62+
"minimum-stability": "dev",
63+
"prefer-stable": true
6264
}

config/statamic-typesense.php

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

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-typesense.php', 'statamic-typesense');
15-
16-
if ($this->app->runningInConsole()) {
17-
18-
$this->publishes([
19-
__DIR__.'/../config/statamic-typesense.php' => config_path('statamic-typesense.php'),
20-
], 'statamic-typesense-config');
21-
22-
}
23-
2414
Search::extend('typesense', function (Application $app, array $config, $name, $locale = null) {
2515
$client = new Client($config['client'] ?? []);
2616

src/Typesense/Index.php

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,12 @@ public function insert($document)
3333
return $this->insertMultiple(collect([$document]));
3434
}
3535

36-
public function insertMultiple($documents)
36+
public function fields(Searchable $searchable)
3737
{
38-
$documents
39-
->chunk(config('statamic-typesense.insert_chunk_size', 100))
40-
->each(function ($documents, $index) {
41-
$documents = $documents
42-
->filter()
43-
->map(fn ($document) => array_merge(
44-
$this->searchables()->fields($document),
45-
$this->getDefaultFields($document),
46-
))
47-
->values()
48-
->toArray();
49-
50-
$this->insertDocuments(new Documents($documents));
51-
});
52-
53-
return $this;
38+
return array_merge(
39+
$this->searchables()->fields($searchable),
40+
$this->getDefaultFields($searchable)
41+
);
5442
}
5543

5644
public function delete($document)
@@ -73,7 +61,7 @@ public function exists()
7361
}
7462
}
7563

76-
protected function insertDocuments(Documents $documents)
64+
public function insertDocuments(Documents $documents)
7765
{
7866
$this->getOrCreateIndex()->documents->import($documents->all(), ['action' => 'upsert']);
7967
}

tests/TestCase.php

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

18-
// add typesense driver
1918
$app['config']->set('statamic.search.drivers.typesense', [
2019
'client' => [
2120
'api_key' => env('TYPESENSE_API_KEY', 'xyz'),
@@ -40,7 +39,10 @@ protected function resolveApplicationConfiguration($app)
4039
],
4140
]);
4241

43-
// add typesense index
42+
$app['config']->set('statamic.search.indexes.cp', [
43+
'driver' => 'null',
44+
]);
45+
4446
$app['config']->set('statamic.search.indexes.typesense_index', [
4547
'driver' => 'typesense',
4648
'searchables' => ['collection:pages'],

0 commit comments

Comments
 (0)