2017 © Pedro Peláez
 

library sphinx

image

ttf/sphinx

  • Sunday, April 28, 2013
  • by kwisatz
  • Repository
  • 1 Watchers
  • 2 Stars
  • 553 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

SphinxServiceProvider

This is a simple service provider for silex that ties the SphinxSearch-API in., (*1)

A word of warning

This is currently work in progress and not suitable for use in productive environments., (*2)

The API may change often and erratically. Generally, I would advise against using this before version 1.0.0, (*3)

I you'd really like to use this productively, I recommend to choose a version and stick with it, i.e. set "require 'ttf/sphinx': '0.1.2'" in your composer.json, (*4)

Usage

Register the service provider as you would any other:, (*5)

$app->register( new Ttf\SphinxServiceProvider());

If you're running the sphinx searchd on any host/port combination other than the assumed "localhost:3312", you need to supply these parameters here:, (*6)

$app->register( new Ttf\SphinxServiceProvider(), array( 
    'sphinx.port' => 3413,
    'sphinx.host' => 'sphinx.example.org'
));

Following that, you would use it as any other service provider. Start off by using the search method on the provider, which will return a result object:, (*7)

$app->get('/search', function( Request $request ) use ($app) {
    $result = $app['sphinx']->search( $request->get('q'), 'myCatalog' );
    return new Response( (String) $result, 200 );
});

Coercing the $result object to a string will return a human readable representation of your research results., (*8)

In this case, a call request would look like:, (*9)

http://silex.local/search?q=cheese

A more elaborate example would be:, (*10)

$app->get('/search', function( Request $request ) use ($app) {
    if( $result = $app['sphinx']->search( $request->get('q'), 'catalog' ) ) {
        $indices = $result->fetchIndices();

        $query = 'Select description, tags from stand where fiorg = ?';
        foreach( $indices as $index ) {
            $entries = $app['db']->fetchAssoc( $query, array( $index ));
        }
        $app['twig']->render('search.twig',
            array(
                'results' => $entries
            )
        );
    }
});

Passing parameters to the Sphinx API

Note that you can also directly pass arguments to the sphinxsearch api. Simply use them on the service:, (*11)

$app['sphinx']->SetRankingMode( SPH_RANK_SPH04 );
$app['sphinx']->SetFieldWeights( array( 'tags' => 10, 'description' => 5) );

The Versions

28/04 2013

dev-master

9999999-dev

  Sources   Download

GPL-3.0+

The Requires

 

search sphinx serviceprovider sphinx search

28/04 2013

0.1.3

0.1.3.0

  Sources   Download

GPL-3.0+

The Requires

 

search sphinx serviceprovider sphinx search

28/04 2013

0.1.2

0.1.2.0

  Sources   Download

GPL-3.0+

The Requires

 

search sphinx serviceprovider sphinx search

28/04 2013

0.1.1

0.1.1.0

  Sources   Download

GPL-3.0+

The Requires

 

search sphinx serviceprovider sphinx search