PHP code example of javer / sphinx-bundle

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

    

javer / sphinx-bundle example snippets


$results = $this->container->get('sphinx')
    ->select('id', 'column1', 'column2', 'WEIGHT() as weight')
    ->from('index1', 'index2')
    ->where('column3', 'value1')
    ->where('column4', '>', 4)
    ->where('column5', [5, '6'])
    ->where('column6', 'NOT IN', [7, '8'])
    ->where('column7', 'BETWEEN', [9, 10])
    ->match('column8', 'value2')
    ->match(['column9', 'column10'], 'value3')
    ->groupBy('column11')
    ->groupBy('column12')
    ->withinGroupOrderBy('column13', 'desc')
    ->withinGroupOrderBy('column14')
    ->having('weight', '>', 2)
    ->orderBy('column15', 'desc')
    ->orderBy('column16')
    ->offset(5)
    ->limit(10)
    ->option('agent_query_timeout', 10000)
    ->option('max_matches', 1000)
    ->option('field_weights', '(column9=10, column10=3)')
    ->getResults();

$queryBuilder = $this->container->get('doctrine.orm.default_entity_manager')
    ->createQueryBuilder()
    ->select('p', 'i')
    ->from('AppBundle:Product', 'p')
    ->join('AppBundle:Image', 'i')
    ->where('p.owner = :owner')
    ->setParameter('owner', $this->getUser());

$query = $this->container->get('sphinx')
    ->createQuery()
    ->select('*')
    ->from('product')
    ->match(['name', 'description'], $searchQuery)
    ->where('owner_id', $this->getUser()->getId())
    ->orderBy('created', 'desc')
    ->useQueryBuilder($queryBuilder, 'p');

$paginator = $this->container->get('knp_paginator')
    ->paginate($query, $request->query->get('page', 1), 20);