Installation
composer require beecms/search-bundle
Ensure BeeCMS\SearchBundle\BeeCMSSearchBundle is registered in config/bundles.php.
Initial Setup Run the setup command to initialize the search system (creates default file-based or DB-backed index):
php bin/console search:setup
First Use Case: Basic Search
Inject the SearchService into a controller or service:
use BeeCMS\SearchBundle\Service\SearchService;
class MyController extends AbstractController {
public function search(SearchService $searchService) {
$results = $searchService->search('query');
return $this->json($results);
}
}
var/search/).Indexing Content
var/search/ (configurable via search.yml).
# config/packages/bee_cms_search.yaml
bee_cms_search:
indexer:
type: file
directory: '%kernel.project_dir%/var/search'
search:generate-index to rebuild the index:
php bin/console search:generate-index
Querying
$results = $searchService->search('laravel');
$results = $searchService->search('laravel', ['type' => 'article']);
$results = $searchService->search('laravel', [], 1, 10); // Page 1, 10 items
Integration with Laravel
SearchService to a custom interface for loose coupling:
$container->bind(MySearchInterface::class, SearchService::class);
search.indexing or search.indexed events to hook into indexing logic:
$eventDispatcher->addListener('search.indexed', function ($event) {
// Post-indexing logic (e.g., log, notify)
});
Caching
search.yml:
bee_cms_search:
cache:
enabled: true
provider: cache.app
php bin/console cache:clear
Indexing Overhead
search:generate-index can be resource-intensive for large datasets. Run during low-traffic periods.cache.enabled: true to mitigate.Configuration Conflicts
search.yml is merged correctly. Override defaults in config/packages/bee_cms_search.yaml:
bee_cms_search:
indexer:
type: db # Force DB-backed search
imports in config/packages/bee_cms_search.yaml if the bundle doesn’t auto-configure:
imports:
- { resource: "@BeeCMSSearchBundle/Resources/config/services.yaml" }
File Permissions
var/search/. Set permissions:
chmod -R 755 var/search
Migration Issues
search:setup fails, manually create the DB tables using the generated migration:
php bin/console doctrine:migrations:migrate
bee_cms_search:
debug: true
search_index (for DB-backed) or files in var/search/ (for file-based).Custom Indexers
Override the default indexer by implementing BeeCMS\SearchBundle\Indexer\IndexerInterface and configure it in search.yml:
bee_cms_search:
indexer:
class: App\CustomIndexer
Query Modifiers
Extend the SearchService to add custom query logic:
class ExtendedSearchService extends SearchService {
public function advancedSearch(string $query, array $filters = []) {
// Custom logic
return $this->search($query, $filters);
}
}
Bind it in services.yaml:
services:
App\Service\ExtendedSearchService: '@BeeCMS\SearchBundle\Service\SearchService'
REST API
Monitor the repo for the upcoming REST API module. Until then, wrap the SearchService in a custom API controller:
class SearchApiController extends AbstractController {
public function __invoke(SearchService $searchService, Request $request) {
$query = $request->query->get('q');
return $this->json($searchService->search($query));
}
}
Route it in routes.yaml:
search:
path: /api/search
controller: App\Controller\SearchApiController
methods: GET
How can I help you explore Laravel packages today?