PHP code example of ayaou / db-search-bundle

1. Go to this page and download the library: Download ayaou/db-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/ */

    

ayaou / db-search-bundle example snippets




namespace App\Controller;

use Ayaou\DbSearchBundle\Searcher\Searcher;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Attribute\Route;

class MyController extends AbstractController
{
    #[Route('/search', name: 'search')]
    public function search(Request $request, Searcher $searcher)
    {
        $q = $request->query->get('q', '');
        
        // Search in all indexes
        $results = $searcher->search($q);
        
        // Search in a specific index
        // $results = $searcher->search($q, 'my_index');
        
        // Search in multiple indexes
        // $results = $searcher->search($q, ['my_index', 'another_index']);
        
        // Search for a specific entity
        // $results = $searcher->search($q, [], 'App\Entity\MyEntity');
        
        // Get raw search results
        // $results = $searcher->searchRaw($q);
        
        return $this->json($results);
    }
}
bash
php bin/console make:migration
php bin/console doctrine:migrations:migrate