PHP code example of alpixel / elastica-query-sorter-bundle

1. Go to this page and download the library: Download alpixel/elastica-query-sorter-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/ */

    

alpixel / elastica-query-sorter-bundle example snippets




use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = [
            new Alpixel\Bundle\ElasticaQuerySorterBundle\AlpixelElasticaQuerySorterBundle(),
        ]
    }
}



namespace AppBundle\Controller;

use AppBundle\Form\MyForm;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Form\Form;
use Symfony\Component\HttpFoundation\Request;

class ResearchController extends Controller
{
    /**
     * @Route("/home", name="home")
     */
    public function shopAction(Request $request)
    {
        $form = $this->createform(MyForm::class);
        $form->handleRequest($request);

        $data               = $form->getData();
        $repository         = $this->get('fos_elastica.manager')->getRepository('AppBundle:MyEntity');
        $query              = $repository->queryCustom($data);

        // You need to pass the repository and the query from elastica (\Elastica\Query)
        $results           = $this->get('alpixel.services.elastica_query_sorter')
            ->sort($repository, $query);

        return $this->render('page/home.html.twig', [
            'results'  => $results,
            'form'     => $form->createView(),
        ]);
    }
}