Skip to content

Commit

Permalink
Rename prefix to index_name_prefix (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz authored May 10, 2023
1 parent f8f374d commit 44a42a1
Show file tree
Hide file tree
Showing 28 changed files with 105 additions and 63 deletions.
8 changes: 4 additions & 4 deletions .examples/laravel/app/Http/Controllers/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace App\Http\Controllers;

use Schranz\Search\Integration\Laravel\Facade\Engine as EngineFacade;
use Schranz\Search\Integration\Laravel\Facade\EngineRegistry as EngineRegistryFacade;
use Schranz\Search\SEAL\Adapter\AdapterInterface;
use Schranz\Search\SEAL\EngineInterface;
use Schranz\Search\Integration\Laravel\Facade\EngineRegistry as EngineRegistryFacade;
use Schranz\Search\Integration\Laravel\Facade\Engine as EngineFacade;
use Symfony\Component\HttpFoundation\Response;

class SearchController extends Controller
Expand Down Expand Up @@ -43,8 +43,8 @@ public function home(): string

$engineFacadeClass = EngineFacade::class;
$engineRegistryFacadeClass = EngineRegistryFacade::class;
$engineFacadeTargetClass = get_class(EngineFacade::getFacadeRoot());
$engineRegistryFacadeTargetClass = get_class(EngineRegistryFacade::getFacadeRoot());
$engineFacadeTargetClass = EngineFacade::getFacadeRoot()::class; // @phpstan-ignore-line
$engineRegistryFacadeTargetClass = EngineRegistryFacade::getFacadeRoot()::class; // @phpstan-ignore-line

return
<<<HTML
Expand Down
9 changes: 9 additions & 0 deletions .examples/laravel/config/schranz_search.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
declare(strict_types=1);

return [
/*
|--------------------------------------------------------------------------
| Schema prefix
|--------------------------------------------------------------------------
|
| Define the prefix used for the index names to avoid conflicts.
*/
'index_name_prefix' => env('TEST_INDEX_PREFIX', ''),

/*
|--------------------------------------------------------------------------
| Schema configs
Expand Down
5 changes: 3 additions & 2 deletions .examples/laravel/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ services:
discovery.type: single-node
plugins.security.disabled: 'true'
cluster.routing.allocation.disk.threshold_enabled: 'false'
http.port: 9201
ports:
- "9201:9200"
- "9201:9201"
- "9601:9600"
healthcheck:
test: ["CMD-SHELL", "curl --silent --fail localhost:9200/_cluster/health || exit 1"]
test: ["CMD-SHELL", "curl --silent --fail localhost:9201/_cluster/health || exit 1"]
interval: 5s
timeout: 5s
retries: 10
Expand Down
23 changes: 11 additions & 12 deletions .examples/laravel/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

declare(strict_types=1);

use App\Http\Controllers\SearchController;
use Illuminate\Support\Facades\Route;

/*
Expand All @@ -16,14 +15,14 @@
|
*/

Route::get('/', [SearchController::class, 'home']);
Route::get('/algolia', [SearchController::class, 'algolia']);
Route::get('/elasticsearch', [SearchController::class, 'elasticsearch']);
Route::get('/meilisearch', [SearchController::class, 'meilisearch']);
Route::get('/memory', [SearchController::class, 'memory']);
Route::get('/opensearch', [SearchController::class, 'opensearch']);
Route::get('/redisearch', [SearchController::class, 'redisearch']);
Route::get('/solr', [SearchController::class, 'solr']);
Route::get('/typesense', [SearchController::class, 'typesense']);
Route::get('/multi', [SearchController::class, 'multi']);
Route::get('/read-write', [SearchController::class, 'readWrite']);
Route::get('/', fn (): string => (new \App\Http\Controllers\SearchController())->home());
Route::get('/algolia', fn (): \Symfony\Component\HttpFoundation\Response => (new \App\Http\Controllers\SearchController())->algolia());
Route::get('/elasticsearch', fn (): \Symfony\Component\HttpFoundation\Response => (new \App\Http\Controllers\SearchController())->elasticsearch());
Route::get('/meilisearch', fn (): \Symfony\Component\HttpFoundation\Response => (new \App\Http\Controllers\SearchController())->meilisearch());
Route::get('/memory', fn (): \Symfony\Component\HttpFoundation\Response => (new \App\Http\Controllers\SearchController())->memory());
Route::get('/opensearch', fn (): \Symfony\Component\HttpFoundation\Response => (new \App\Http\Controllers\SearchController())->opensearch());
Route::get('/redisearch', fn (): \Symfony\Component\HttpFoundation\Response => (new \App\Http\Controllers\SearchController())->redisearch());
Route::get('/solr', fn (): \Symfony\Component\HttpFoundation\Response => (new \App\Http\Controllers\SearchController())->solr());
Route::get('/typesense', fn (): \Symfony\Component\HttpFoundation\Response => (new \App\Http\Controllers\SearchController())->typesense());
Route::get('/multi', fn (): \Symfony\Component\HttpFoundation\Response => (new \App\Http\Controllers\SearchController())->multi());
Route::get('/read-write', fn (): \Symfony\Component\HttpFoundation\Response => (new \App\Http\Controllers\SearchController())->readWrite());
11 changes: 6 additions & 5 deletions .examples/mezzio/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ services:
discovery.type: single-node
plugins.security.disabled: 'true'
cluster.routing.allocation.disk.threshold_enabled: 'false'
http.port: 9201
ports:
- "9201:9200"
- "9201:9201"
- "9601:9600"
healthcheck:
test: ["CMD-SHELL", "curl --silent --fail localhost:9200/_cluster/health || exit 1"]
test: ["CMD-SHELL", "curl --silent --fail localhost:9201/_cluster/health || exit 1"]
interval: 5s
timeout: 5s
retries: 10
Expand All @@ -55,7 +56,7 @@ services:
environment:
REDIS_ARGS: --requirepass supersecure
volumes:
- redisearch-data:/data
- redisearch-data:/data

typesense:
image: typesense/typesense:0.24.0
Expand All @@ -74,8 +75,8 @@ services:
solr:
image: "solr:9"
ports:
- "8983:8983"
- "9983:9983"
- "8983:8983"
- "9983:9983"
command: solr -f -cloud
healthcheck:
test: ["CMD-SHELL", "curl --silent --fail localhost:8983 || exit 1"]
Expand Down
1 change: 1 addition & 0 deletions .examples/mezzio/src/App/src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function __invoke(): array
return [
'dependencies' => $this->getDependencies(),
'schranz_search' => [
'index_name_prefix' => \getenv('TEST_INDEX_PREFIX') ?: $_ENV['TEST_INDEX_PREFIX'] ?? '',
'schemas' => [
'algolia' => [
'dir' => 'config/schemas',
Expand Down
1 change: 1 addition & 0 deletions .examples/spiral/app/config/schranz_search.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
declare(strict_types=1);

return [
'index_name_prefix' => env('TEST_INDEX_PREFIX', ''),
'schemas' => [
'algolia' => [
'dir' => 'app/schemas',
Expand Down
11 changes: 6 additions & 5 deletions .examples/spiral/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ services:
discovery.type: single-node
plugins.security.disabled: 'true'
cluster.routing.allocation.disk.threshold_enabled: 'false'
http.port: 9201
ports:
- "9201:9200"
- "9201:9201"
- "9601:9600"
healthcheck:
test: ["CMD-SHELL", "curl --silent --fail localhost:9200/_cluster/health || exit 1"]
test: ["CMD-SHELL", "curl --silent --fail localhost:9201/_cluster/health || exit 1"]
interval: 5s
timeout: 5s
retries: 10
Expand All @@ -55,7 +56,7 @@ services:
environment:
REDIS_ARGS: --requirepass supersecure
volumes:
- redisearch-data:/data
- redisearch-data:/data

typesense:
image: typesense/typesense:0.24.0
Expand All @@ -74,8 +75,8 @@ services:
solr:
image: "solr:9"
ports:
- "8983:8983"
- "9983:9983"
- "8983:8983"
- "9983:9983"
command: solr -f -cloud
healthcheck:
test: ["CMD-SHELL", "curl --silent --fail localhost:8983 || exit 1"]
Expand Down
2 changes: 2 additions & 0 deletions .examples/symfony/.env
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ APP_SECRET=3340f1a66508f0d347d64d00b0880f15

ALGOLIA_APPLICATION_ID=ALGOLIA_APPLICATION_ID
ALGOLIA_ADMIN_API_KEY=ALGOLIA_ADMIN_API_KEY

TEST_INDEX_PREFIX=
1 change: 1 addition & 0 deletions .examples/symfony/config/packages/schranz_search.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
schranz_search:
index_name_prefix: '%env(TEST_INDEX_PREFIX)%'
schemas:
algolia:
dir: '%kernel.project_dir%/config/schemas'
Expand Down
11 changes: 6 additions & 5 deletions .examples/symfony/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ services:
discovery.type: single-node
plugins.security.disabled: 'true'
cluster.routing.allocation.disk.threshold_enabled: 'false'
http.port: 9201
ports:
- "9201:9200"
- "9201:9201"
- "9601:9600"
healthcheck:
test: ["CMD-SHELL", "curl --silent --fail localhost:9200/_cluster/health || exit 1"]
test: ["CMD-SHELL", "curl --silent --fail localhost:9201/_cluster/health || exit 1"]
interval: 5s
timeout: 5s
retries: 10
Expand All @@ -55,7 +56,7 @@ services:
environment:
REDIS_ARGS: --requirepass supersecure
volumes:
- redisearch-data:/data
- redisearch-data:/data

typesense:
image: typesense/typesense:0.24.0
Expand All @@ -74,8 +75,8 @@ services:
solr:
image: "solr:9"
ports:
- "8983:8983"
- "9983:9983"
- "8983:8983"
- "9983:9983"
command: solr -f -cloud
healthcheck:
test: ["CMD-SHELL", "curl --silent --fail localhost:8983 || exit 1"]
Expand Down
1 change: 1 addition & 0 deletions .examples/yii/config/common/params.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
],

'schranz-search/yii-module' => [
'index_name_prefix' => \getenv('TEST_INDEX_PREFIX') ?: $_ENV['TEST_INDEX_PREFIX'] ?? '',
'schemas' => [
'algolia' => [
'dir' => 'config/schemas',
Expand Down
11 changes: 6 additions & 5 deletions .examples/yii/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ services:
discovery.type: single-node
plugins.security.disabled: 'true'
cluster.routing.allocation.disk.threshold_enabled: 'false'
http.port: 9201
ports:
- "9201:9200"
- "9201:9201"
- "9601:9600"
healthcheck:
test: ["CMD-SHELL", "curl --silent --fail localhost:9200/_cluster/health || exit 1"]
test: ["CMD-SHELL", "curl --silent --fail localhost:9201/_cluster/health || exit 1"]
interval: 5s
timeout: 5s
retries: 10
Expand All @@ -55,7 +56,7 @@ services:
environment:
REDIS_ARGS: --requirepass supersecure
volumes:
- redisearch-data:/data
- redisearch-data:/data

typesense:
image: typesense/typesense:0.24.0
Expand All @@ -74,8 +75,8 @@ services:
solr:
image: "solr:9"
ports:
- "8983:8983"
- "9983:9983"
- "8983:8983"
- "9983:9983"
command: solr -f -cloud
healthcheck:
test: ["CMD-SHELL", "curl --silent --fail localhost:8983 || exit 1"]
Expand Down
10 changes: 10 additions & 0 deletions integrations/laravel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,16 @@ return [
'adapter' => 'read-write://elasticsearch?write=multi',
],
],

/*
|--------------------------------------------------------------------------
| Schema prefix
|--------------------------------------------------------------------------
|
| Define the prefix used for the index names to avoid conflicts.
*/

'index_name_prefix' => '',
];
```

Expand Down
2 changes: 1 addition & 1 deletion integrations/laravel/config/schranz_search.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
| Define the prefix used for the index names to avoid conflicts.
*/

'prefix' => '',
'index_name_prefix' => '',

/*
|--------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions integrations/laravel/src/SearchProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ public function boot(): void

/**
* @var array{
* prefix: string,
* index_name_prefix: string,
* engines: array<string, array{adapter: string}>,
* schemas: array<string, array{dir: string, engine?: string}>,
* } $config
*/
$config = $globalConfig['schranz_search'];
$prefix = $config['prefix'];
$indexNamePrefix = $config['index_name_prefix'];
$engines = $config['engines'];
$schemas = $config['schemas'];

Expand Down Expand Up @@ -105,7 +105,7 @@ public function boot(): void
return $factory->createAdapter($adapterDsn);
});

$this->app->singleton($schemaLoaderServiceId, fn () => new PhpFileLoader($dirs, $prefix));
$this->app->singleton($schemaLoaderServiceId, fn () => new PhpFileLoader($dirs, $indexNamePrefix));

$this->app->singleton($schemaId, function ($app) use ($schemaLoaderServiceId) {
/** @var LoaderInterface $loader */
Expand Down
4 changes: 4 additions & 0 deletions integrations/mezzio/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ class ConfigProvider
'adapter' => 'read-write://elasticsearch?write=multi',
],
],
'index_name_prefix' => '',
'reindex_providers' => [
\App\Search\BlogReindexProvider::class,
],
],
];
}
Expand Down
2 changes: 1 addition & 1 deletion integrations/mezzio/src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __invoke(): array
'dependencies' => $this->getDependencies(),
'schranz_search' => [
'adapter_factories' => $this->getAdapterFactories(), // we are going over a config as there are no tagged services in mezzio
'prefix' => '',
'index_name_prefix' => '',
'schemas' => [],
'engines' => [],
'reindex_providers' => [],
Expand Down
6 changes: 3 additions & 3 deletions integrations/mezzio/src/Service/SealContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __invoke(ContainerInterface $container): SealContainer

/**
* @var array{
* prefix: string,
* index_name_prefix: string,
* schemas: array<string, array{
* dir: string,
* engine?: string,
Expand All @@ -49,7 +49,7 @@ public function __invoke(ContainerInterface $container): SealContainer
*/
$config = $config['schranz_search'];

$prefix = $config['prefix'];
$indexNamePrefix = $config['index_name_prefix'];
$adapterFactoriesConfig = $config['adapter_factories'];

$engineSchemaDirs = [];
Expand Down Expand Up @@ -92,7 +92,7 @@ public function __invoke(ContainerInterface $container): SealContainer
$dirs = $engineSchemaDirs[$name] ?? [];

$adapter = $adapterFactory->createAdapter($adapterDsn);
$loader = new PhpFileLoader($dirs, $prefix);
$loader = new PhpFileLoader($dirs, $indexNamePrefix);
$schema = $loader->load();

$engine = new Engine($adapter, $schema);
Expand Down
4 changes: 4 additions & 0 deletions integrations/spiral/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ return [
'adapter' => 'read-write://elasticsearch?write=multi',
],
],
'index_name_prefix' => '',
'reindex_providers' => [
\App\Search\BlogReindexProvider::class,
],
];
```

Expand Down
4 changes: 2 additions & 2 deletions integrations/spiral/src/Bootloader/SearchBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function init(
$this->config->setDefaults(
SearchConfig::CONFIG,
[
'prefix' => $environment->get('SEAL_SEARCH_PREFIX', ''),
'index_name_prefix' => $environment->get('SEAL_SEARCH_PREFIX', ''),
'schemas' => [
'app' => [
'dir' => $dirs->get('app') . 'schemas',
Expand Down Expand Up @@ -120,7 +120,7 @@ public function boot(Container $container, SearchConfig $config): void

$container->bindSingleton(
$schemaLoaderServiceId,
static fn (Container $container): PhpFileLoader => new PhpFileLoader($dirs, $config->getPrefix()),
static fn (Container $container): PhpFileLoader => new PhpFileLoader($dirs, $config->getIndexNamePrefix()),
);

$container->bindSingleton(
Expand Down
Loading

0 comments on commit 44a42a1

Please sign in to comment.