liub1993 / sphinxsearch by Bing
forked from sngrl/sphinxsearch

Laravel package of Sphinxsearch for Laravel ^5.4
2,754
1
3
Package Data
Maintainer Username: Bing
Maintainer Contact: 598604711@qq.com (liub1993)
Package Create Date: 2017-03-12
Package Last Update: 2017-08-18
Language: PHP
License: Apache-2.0
Last Refreshed: 2024-04-26 03:01:59
Package Statistics
Total Downloads: 2,754
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 1
Total Watchers: 3
Total Forks: 1
Total Open Issues: 0

Sphinx Search for Laravel 5.4

Simple Laravel 5.4 package for make queries to Sphinx Search.

Inspired by sngrl/sphinxsearch, and made it also usable in Laravel 5.4.

Installation

Run the following command in your console to pull down the package from packagist.

composer require cugr/sphinxsearch:dev-master

After updating composer, add the ServiceProvider to the "providers" array in config/app.php:

	'providers' => [
        /*** Some others providers ***/
        CuGR\SphinxSearch\SphinxSearchServiceProvider::class,
    ],

You can add this line to the files, where you may use SphinxSearch:

use CuGR\SphinxSearch\SphinxSearch;

Configuration

To use Sphinx Search, you need to configure your indexes and what model it should query. To do so, publish the configuration into your app.

php artisan vendor:publish --provider="CuGR\SphinxSearch\SphinxSearchServiceProvider"

This will create the file config/sphinxsearch.php. Modify as needed.

Usage

Basic query (raw sphinx results)

$sphinx = new SphinxSearch();  // or $sphinx = new SphinxSearch('connection_name');
$results = $sphinx->search('my query', 'index_name')->query();

Basic query (with Eloquent)

$results = $sphinx->search('my query', 'index_name')->get();

Query another Sphinx index with limit and filters.

$results = $sphinx->search('my query', 'index_name')
	->limit(30)
	->filter('attribute', array(1, 2))
	->range('int_attribute', 1, 10)
	->get();

Query with match and sort type specified.

$result = $sphinx->search('my query', 'index_name')
	->setFieldWeights(
		array(
			'partno'  => 10,
			'name'    => 8,
			'details' => 1
		)
	)
	->setMatchMode(\Sphinx\SphinxClient::SPH_MATCH_EXTENDED)
	->setSortMode(\Sphinx\SphinxClient::SPH_SORT_EXTENDED, "@weight DESC")
	->get(true);  //passing true causes get() to respect returned sort order

License

CuGR Sphinx Search is open-sourced software licensed under the MIT license