diff --git a/.examples/laravel/app/Http/Controllers/SearchController.php b/.examples/laravel/app/Http/Controllers/SearchController.php index 2acfafef..cf91409e 100644 --- a/.examples/laravel/app/Http/Controllers/SearchController.php +++ b/.examples/laravel/app/Http/Controllers/SearchController.php @@ -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 @@ -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 << env('TEST_INDEX_PREFIX', ''), + /* |-------------------------------------------------------------------------- | Schema configs diff --git a/.examples/laravel/docker-compose.yml b/.examples/laravel/docker-compose.yml index b78f8f16..0eeb1e2f 100644 --- a/.examples/laravel/docker-compose.yml +++ b/.examples/laravel/docker-compose.yml @@ -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 diff --git a/.examples/laravel/routes/web.php b/.examples/laravel/routes/web.php index 41a60790..bab91425 100644 --- a/.examples/laravel/routes/web.php +++ b/.examples/laravel/routes/web.php @@ -2,7 +2,6 @@ declare(strict_types=1); -use App\Http\Controllers\SearchController; use Illuminate\Support\Facades\Route; /* @@ -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()); diff --git a/.examples/mezzio/docker-compose.yml b/.examples/mezzio/docker-compose.yml index b78f8f16..39cc0514 100644 --- a/.examples/mezzio/docker-compose.yml +++ b/.examples/mezzio/docker-compose.yml @@ -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 @@ -55,7 +56,7 @@ services: environment: REDIS_ARGS: --requirepass supersecure volumes: - - redisearch-data:/data + - redisearch-data:/data typesense: image: typesense/typesense:0.24.0 @@ -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"] diff --git a/.examples/mezzio/src/App/src/ConfigProvider.php b/.examples/mezzio/src/App/src/ConfigProvider.php index 5db2d36f..7c1dd677 100644 --- a/.examples/mezzio/src/App/src/ConfigProvider.php +++ b/.examples/mezzio/src/App/src/ConfigProvider.php @@ -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', diff --git a/.examples/spiral/app/config/schranz_search.php b/.examples/spiral/app/config/schranz_search.php index b89e96f3..6b0d09a4 100644 --- a/.examples/spiral/app/config/schranz_search.php +++ b/.examples/spiral/app/config/schranz_search.php @@ -3,6 +3,7 @@ declare(strict_types=1); return [ + 'index_name_prefix' => env('TEST_INDEX_PREFIX', ''), 'schemas' => [ 'algolia' => [ 'dir' => 'app/schemas', diff --git a/.examples/spiral/docker-compose.yml b/.examples/spiral/docker-compose.yml index b78f8f16..39cc0514 100644 --- a/.examples/spiral/docker-compose.yml +++ b/.examples/spiral/docker-compose.yml @@ -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 @@ -55,7 +56,7 @@ services: environment: REDIS_ARGS: --requirepass supersecure volumes: - - redisearch-data:/data + - redisearch-data:/data typesense: image: typesense/typesense:0.24.0 @@ -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"] diff --git a/.examples/symfony/.env b/.examples/symfony/.env index 9ec2a6d2..7e16ae80 100644 --- a/.examples/symfony/.env +++ b/.examples/symfony/.env @@ -21,3 +21,5 @@ APP_SECRET=3340f1a66508f0d347d64d00b0880f15 ALGOLIA_APPLICATION_ID=ALGOLIA_APPLICATION_ID ALGOLIA_ADMIN_API_KEY=ALGOLIA_ADMIN_API_KEY + +TEST_INDEX_PREFIX= diff --git a/.examples/symfony/config/packages/schranz_search.yaml b/.examples/symfony/config/packages/schranz_search.yaml index fb024423..9ff827e7 100644 --- a/.examples/symfony/config/packages/schranz_search.yaml +++ b/.examples/symfony/config/packages/schranz_search.yaml @@ -1,4 +1,5 @@ schranz_search: + index_name_prefix: '%env(TEST_INDEX_PREFIX)%' schemas: algolia: dir: '%kernel.project_dir%/config/schemas' diff --git a/.examples/symfony/docker-compose.yml b/.examples/symfony/docker-compose.yml index b78f8f16..39cc0514 100644 --- a/.examples/symfony/docker-compose.yml +++ b/.examples/symfony/docker-compose.yml @@ -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 @@ -55,7 +56,7 @@ services: environment: REDIS_ARGS: --requirepass supersecure volumes: - - redisearch-data:/data + - redisearch-data:/data typesense: image: typesense/typesense:0.24.0 @@ -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"] diff --git a/.examples/yii/config/common/params.php b/.examples/yii/config/common/params.php index c17d94c2..b2c68970 100644 --- a/.examples/yii/config/common/params.php +++ b/.examples/yii/config/common/params.php @@ -36,6 +36,7 @@ ], 'schranz-search/yii-module' => [ + 'index_name_prefix' => \getenv('TEST_INDEX_PREFIX') ?: $_ENV['TEST_INDEX_PREFIX'] ?? '', 'schemas' => [ 'algolia' => [ 'dir' => 'config/schemas', diff --git a/.examples/yii/docker-compose.yml b/.examples/yii/docker-compose.yml index b78f8f16..39cc0514 100644 --- a/.examples/yii/docker-compose.yml +++ b/.examples/yii/docker-compose.yml @@ -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 @@ -55,7 +56,7 @@ services: environment: REDIS_ARGS: --requirepass supersecure volumes: - - redisearch-data:/data + - redisearch-data:/data typesense: image: typesense/typesense:0.24.0 @@ -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"] diff --git a/integrations/laravel/README.md b/integrations/laravel/README.md index 3d5feb82..5b008854 100644 --- a/integrations/laravel/README.md +++ b/integrations/laravel/README.md @@ -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' => '', ]; ``` diff --git a/integrations/laravel/config/schranz_search.php b/integrations/laravel/config/schranz_search.php index 9eaa53af..008976d5 100644 --- a/integrations/laravel/config/schranz_search.php +++ b/integrations/laravel/config/schranz_search.php @@ -20,7 +20,7 @@ | Define the prefix used for the index names to avoid conflicts. */ - 'prefix' => '', + 'index_name_prefix' => '', /* |-------------------------------------------------------------------------- diff --git a/integrations/laravel/src/SearchProvider.php b/integrations/laravel/src/SearchProvider.php index 4770a6ed..f98fb257 100644 --- a/integrations/laravel/src/SearchProvider.php +++ b/integrations/laravel/src/SearchProvider.php @@ -70,13 +70,13 @@ public function boot(): void /** * @var array{ - * prefix: string, + * index_name_prefix: string, * engines: array, * schemas: array, * } $config */ $config = $globalConfig['schranz_search']; - $prefix = $config['prefix']; + $indexNamePrefix = $config['index_name_prefix']; $engines = $config['engines']; $schemas = $config['schemas']; @@ -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 */ diff --git a/integrations/mezzio/README.md b/integrations/mezzio/README.md index 6cdfcd63..30c89d9c 100644 --- a/integrations/mezzio/README.md +++ b/integrations/mezzio/README.md @@ -136,6 +136,10 @@ class ConfigProvider 'adapter' => 'read-write://elasticsearch?write=multi', ], ], + 'index_name_prefix' => '', + 'reindex_providers' => [ + \App\Search\BlogReindexProvider::class, + ], ], ]; } diff --git a/integrations/mezzio/src/ConfigProvider.php b/integrations/mezzio/src/ConfigProvider.php index 0beb09f4..d19fbf26 100644 --- a/integrations/mezzio/src/ConfigProvider.php +++ b/integrations/mezzio/src/ConfigProvider.php @@ -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' => [], diff --git a/integrations/mezzio/src/Service/SealContainerFactory.php b/integrations/mezzio/src/Service/SealContainerFactory.php index 8402b2a2..4dbde2e3 100644 --- a/integrations/mezzio/src/Service/SealContainerFactory.php +++ b/integrations/mezzio/src/Service/SealContainerFactory.php @@ -35,7 +35,7 @@ public function __invoke(ContainerInterface $container): SealContainer /** * @var array{ - * prefix: string, + * index_name_prefix: string, * schemas: arraycreateAdapter($adapterDsn); - $loader = new PhpFileLoader($dirs, $prefix); + $loader = new PhpFileLoader($dirs, $indexNamePrefix); $schema = $loader->load(); $engine = new Engine($adapter, $schema); diff --git a/integrations/spiral/README.md b/integrations/spiral/README.md index b41f6027..30ccfae3 100644 --- a/integrations/spiral/README.md +++ b/integrations/spiral/README.md @@ -121,6 +121,10 @@ return [ 'adapter' => 'read-write://elasticsearch?write=multi', ], ], + 'index_name_prefix' => '', + 'reindex_providers' => [ + \App\Search\BlogReindexProvider::class, + ], ]; ``` diff --git a/integrations/spiral/src/Bootloader/SearchBootloader.php b/integrations/spiral/src/Bootloader/SearchBootloader.php index 1cdf5605..e0d85024 100644 --- a/integrations/spiral/src/Bootloader/SearchBootloader.php +++ b/integrations/spiral/src/Bootloader/SearchBootloader.php @@ -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', @@ -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( diff --git a/integrations/spiral/src/Config/SearchConfig.php b/integrations/spiral/src/Config/SearchConfig.php index 001f5d5c..0c62f551 100644 --- a/integrations/spiral/src/Config/SearchConfig.php +++ b/integrations/spiral/src/Config/SearchConfig.php @@ -24,7 +24,7 @@ final class SearchConfig extends InjectableConfig /** * @var array{ - * prefix: string, + * index_name_prefix: string, * schemas: array '', + 'index_name_prefix' => '', 'schemas' => [], 'engines' => [], 'reindex_providers' => [], ]; - public function getPrefix(): string + public function getIndexNamePrefix(): string { - return $this->config['prefix']; + return $this->config['index_name_prefix']; } /** diff --git a/integrations/symfony/README.md b/integrations/symfony/README.md index 63e31d4d..11ce5295 100644 --- a/integrations/symfony/README.md +++ b/integrations/symfony/README.md @@ -98,6 +98,7 @@ schranz_search: adapter: 'multi://elasticsearch?adapters[]=opensearch' read-write: adapter: 'read-write://elasticsearch?write=multi' + index_name_prefix: '' ``` ## Usage @@ -113,7 +114,7 @@ class Some { } ``` -A specific engine is available under the config key prefix with `Engine`: +A specific engine is available under the config key suffix with `Engine`: ```php class Some { diff --git a/integrations/symfony/src/SearchBundle.php b/integrations/symfony/src/SearchBundle.php index 4b20fd0e..d9a52007 100644 --- a/integrations/symfony/src/SearchBundle.php +++ b/integrations/symfony/src/SearchBundle.php @@ -39,7 +39,7 @@ public function configure(DefinitionConfigurator $definition): void // @phpstan-ignore-next-line $definition->rootNode() ->children() - ->scalarNode('prefix')->defaultValue('')->end() + ->scalarNode('index_name_prefix')->defaultValue('')->end() ->arrayNode('schemas') ->useAttributeAsKey('name') ->arrayPrototype() @@ -62,14 +62,14 @@ public function configure(DefinitionConfigurator $definition): void /** * @param array{ - * prefix: string, + * index_name_prefix: string, * engines: array, * schemas: array, * } $config */ public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void { - $prefix = $config['prefix']; + $indexNamePrefix = $config['index_name_prefix']; $engines = $config['engines']; $schemas = $config['schemas']; @@ -97,7 +97,7 @@ public function loadExtension(array $config, ContainerConfigurator $container, C $dirs = $engineSchemaDirs[$name] ?? []; $builder->register($schemaLoaderServiceId, PhpFileLoader::class) - ->setArguments([$dirs, $prefix]); + ->setArguments([$dirs, $indexNamePrefix]); $builder->register($schemaId, Schema::class) ->setFactory([new Reference($schemaLoaderServiceId), 'load']); diff --git a/integrations/yii/README.md b/integrations/yii/README.md index dbaabdf4..dff03469 100644 --- a/integrations/yii/README.md +++ b/integrations/yii/README.md @@ -68,6 +68,10 @@ return [ 'adapter' => 'meilisearch://127.0.0.1:7700', ], ], + 'index_name_prefix' => '', + 'reindex_providers' => [ + \App\Search\BlogReindexProvider::class, + ], ], ]; ``` diff --git a/integrations/yii/config/di.php b/integrations/yii/config/di.php index 9d5b8a60..1accbf08 100644 --- a/integrations/yii/config/di.php +++ b/integrations/yii/config/di.php @@ -37,13 +37,13 @@ /** * @var array{ - * prefix: string, + * index_name_prefix: string, * engines: array, * schemas: array, * } $config */ $config = $params['schranz-search/yii-module']; -$prefix = $config['prefix']; +$indexNamePrefix = $config['index_name_prefix']; $engines = $config['engines']; $schemas = $config['schemas']; @@ -140,7 +140,7 @@ return $factory->createAdapter($adapterDsn); }; - $diConfig[$schemaLoaderServiceId] = static fn (ContainerInterface $container) => new PhpFileLoader($dirs, $prefix); + $diConfig[$schemaLoaderServiceId] = static fn (ContainerInterface $container) => new PhpFileLoader($dirs, $indexNamePrefix); $diConfig[$schemaId] = static function (ContainerInterface $container) use ($schemaLoaderServiceId) { /** @var LoaderInterface $loader */ diff --git a/integrations/yii/config/params.php b/integrations/yii/config/params.php index 7ba54814..bc3b9ebb 100644 --- a/integrations/yii/config/params.php +++ b/integrations/yii/config/params.php @@ -17,7 +17,7 @@ return [ 'schranz-search/yii-module' => [ - 'prefix' => '', + 'index_name_prefix' => '', 'schemas' => [ 'app' => [ 'dir' => 'config/schemas', diff --git a/packages/seal/src/Schema/Loader/PhpFileLoader.php b/packages/seal/src/Schema/Loader/PhpFileLoader.php index e9c4a2ea..d256d568 100644 --- a/packages/seal/src/Schema/Loader/PhpFileLoader.php +++ b/packages/seal/src/Schema/Loader/PhpFileLoader.php @@ -24,7 +24,7 @@ final class PhpFileLoader implements LoaderInterface */ public function __construct( private readonly array $directories, - private readonly string $prefix = '', + private readonly string $indexNamePrefix = '', ) { } @@ -63,7 +63,7 @@ public function load(): Schema foreach ($pathIndexes as $index) { $name = $index->name; if (isset($indexes[$name])) { - $index = new Index($this->prefix . $name, $this->mergeFields($indexes[$index->name]->fields, $index->fields)); + $index = new Index($this->indexNamePrefix . $name, $this->mergeFields($indexes[$index->name]->fields, $index->fields)); } $indexes[$name] = $index;