1. Go to this page and download the library: Download symkit/search-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Symkit\SearchBundle\Attribute\AsSearchProvider;
use Symkit\SearchBundle\Contract\SearchProviderInterface;
use Symkit\SearchBundle\Model\SearchResult;
#[AsSearchProvider]
final readonly class PageSearchProvider implements SearchProviderInterface
{
public function search(string $query): iterable
{
// yield SearchResult instances...
}
public function getCategory(): string
{
return 'Pages';
}
public function getPriority(): int
{
return 10;
}
}
#[AsSearchProvider(engine: 'admin')]
final readonly class UserSearchProvider implements SearchProviderInterface
{
// Only available in the "admin" engine
}
use Symkit\SearchBundle\Contract\SearchServiceInterface;
use Symkit\SearchBundle\Contract\SearchEngineRegistryInterface;
final readonly class MyController
{
public function __construct(
private SearchServiceInterface $search, // default engine
private SearchEngineRegistryInterface $registry, // all engines
) {}
public function __invoke(): Response
{
// Default engine
$results = $this->search->search('hello');
// Specific engine
$adminResults = $this->registry->get('admin')->search('hello');
}
}
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use Symkit\SearchBundle\Event\PreSearchEvent;
use Symkit\SearchBundle\Event\PostSearchEvent;
#[AsEventListener]
final readonly class SearchAnalyticsListener
{
public function __invoke(PostSearchEvent $event): void
{
// Log searches, filter results, add scoring, etc.
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.