GithubHelp home page GithubHelp logo

sphinxsearch's Introduction

Sphinx Search for Laravel 5 - Custom build with snippets support

Simple Laravel 5 package for make queries to Sphinx Search. Inspired by scalia/sphinxsearch package for Laravel 4.

This package was created to import to the site packagist.org and allow installation through Composer (https://getcomposer.org/).

Installation

Require this package in your composer.json:

	"require": {
        /*** Some others packages ***/
		"sngrl/sphinxsearch": "dev-master",
	},

Run in your console composer update command to pull down the latest version of Sphinx Search.

Or just run this in console:

composer require sngrl/sphinxsearch:dev-master

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

	'providers' => array(
        /*** Some others providers ***/
        Iris\SphinxSearch\SphinxSearchServiceProvider::class,
    ),

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

use Iris\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=Iris\SphinxSearch\SphinxSearchServiceProvider --force

This will create the file config/sphinxsearch.php. Modify as needed the host and port, and configure the indexes, binding them to a table and id column.

return array (
	'host'    => '127.0.0.1',
	'port'    => 9312,
	'indexes' => array (
		'my_index_name' => array ( 'table' => 'my_keywords_table', 'column' => 'id' ),
	)
);

Or disable the model querying to just get a list of result id's.

return array (
	'host'    => '127.0.0.1',
	'port'    => 9312,
	'indexes' => array (
		'my_index_name' => FALSE,
	)
);

Usage

Basic query (raw sphinx results)

$sphinx = new SphinxSearch();
$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

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

sphinxsearch's People

Contributors

sngrl avatar iris-xie avatar nekhbet avatar woodymendoza avatar mrbad avatar jeremyhutchings avatar eleven26 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.