3
0
2026-05-07 17:29:31 +01:00
2026-05-07 17:11:08 +01:00
2022-07-20 20:38:09 +01:00
2022-07-20 20:38:09 +01:00
2022-07-20 20:38:09 +01:00
2022-07-20 09:23:11 +01:00
2026-05-05 11:00:29 +01:00
2026-05-05 10:41:46 +01:00
2026-05-05 10:41:53 +01:00
2022-07-21 15:10:19 +01:00
2022-07-20 09:23:11 +01:00
2026-05-07 17:29:31 +01:00

PCM Search Bundle

Provides a search system for Symfony projects.

Installation

Add the repo to your composer.json file:


"repositories": [
    {
        "type": "vcs",
        "url": "https://git.pcmdev.co.uk/pcm-libraries/pcm-search-bundle.git"
    }
]

Then install the bundle via Composer:

composer require pcm/search-bundle

Usage

Make any entity searchable by implementing SearchableInterface. The bundle's SearchService will then index, re-index, and remove entries automatically via Doctrine event subscribers.

To (re)build the index for all searchable entities, run:

php bin/console pcm:search:reindex

Inject Pcm\SearchBundle\Service\SearchService into your own services to query, index, or un-index entities programmatically.

Make your entity searchable by implementing SearchableInterface:

use Pcm\SearchBundle\Interface\SearchableInterface;

#[ORM\Entity]
class Company implements SearchableInterface
{
    public function getSearchTitle(): string
    {
        return $this->name;
    }

    public function getSearchValues(): array
    {
        return [
            $this->name,
            $this->website
        ];
    }
}

Query the index from a controller and resolve each hit to a URL:

#[Route('/search', name: 'app_search', methods: ['GET'])]
public function search(Request $request, SearchIndexRepository $repo): Response
{
    $routes = [Company::class => 'app_company_show'];
    $rows = $repo->findAllPagination($request->query->get('q', ''))->getResult();

    $results = [];
    foreach ($rows as [$index]) {
        $route = $routes[$index->getEntityClass()] ?? null;
        if ($route === null) {
            continue;
        }
        $results[] = [
            'title' => $index->getTitle(),
            'url'   => $this->generateUrl($route, ['id' => $index->getEntityId()]),
        ];
    }

    return $this->render('search/_results.html.twig', ['results' => $results]);
}

Each row from findAllPagination() is [SearchIndex $hit, 'score' => float].

S
Description
No description provided
Readme 87 KiB
Languages
PHP 96.8%
Just 2.2%
Dockerfile 1%