Giter Club home page Giter Club 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 ***/
        sngrl\SphinxSearch\SphinxSearchServiceProvider::class,
    ),

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

use sngrl\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=sngrl\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

eleven26 avatar jeremyhutchings avatar mrbad avatar nekhbet avatar sngrl avatar woodymendoza avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

sphinxsearch's Issues

publish issue

 __DIR__.'../../../../config/sphinxsearch.php' => config_path('sphinxsearch.php'),

change

__DIR__.'/../../../config/sphinxsearch.php' => config_path('sphinxsearch.php'),

ErrorException: Trying to get property of non-object SphinxSearch.php:277

Laravel 5.3

After changing sphinx's file configuration from
'indexes' => array( 'index_name' => array('table' => 'table_name', 'column' => 'id') )
to
'indexes' => array( 'index_name' => false )

I have got that exception

ErrorException: Trying to get property of non-object
in vendor/sngrl/sphinxsearch/src/sngrl/SphinxSearch/SphinxSearch.php:277

Tag a release

Hi,

Any chance you could tag a release so we don't have to rely on 'dev-master'

Thanks

Laravel 5.4 inconsistency

Hello,
I had tried to install sngrl/sphinxsearch to Laravel 5.4 and I got these:

  1. Providers array format is not the same with the one given in the project but you can adjust it to the proper format easily: Remove single quotes and ::class to the end of the class before the comma.
  2. Publishing config file gives error. Error message is below:
    [Symfony\Component\Debug\Exception\FatalThrowableError]
    Call to undefined method Illuminate\Foundation\Application::share()

Hope these will be solved.

Empty Query

i need to use sphinx only for filtering using attributes,
If i make request using blank query :
$sphinx->search("", 'myindex_index')
results are always empty.
It's normal or is a problem of sphinx.conf configuration?

is possibile make request using blank query field?

thnx

Host name must be a string

I get an exception InvalidArgumentException Host name must be a string.

Even though my settings are like this in sphinxsearch.php:

return [
    'host'    => '178.257.2.3',
    'port'    => 9312,
    'timeout' => 30,
    'indexes' => [
        'myIndex' => false,
    ],
];

Eager loading related Models

Hi,

Thank you for such a GREAT integration into Sphinx, it's awesome.

I have other details I want eager loaded into the model query that I'm already using.

I tried

$results = $sphinx->search($search, 'tracker')
->load('details')
->get();

But that didn't load any data, I also tried ->with() but no go.

Do these associations need to be defined in my Search model? Product is the main Model I have defined in my sphinxsearch.php config file.

Any suggestions?

Thank you!

Using share()

php artisan vendor:publish --provider=sngrl\SphinxSearch\SphinxSearchServiceProvider --force

Results in :

[Symfony\Component\Debug\Exception\FatalThrowableError]              
Call to undefined method Illuminate\Foundation\Application::share()  

As of laravel 5.4 share has been removed. You will have to use the singleton instead.

See: laravel/framework@1a1969b

Limit and Order

i need to get last 10 inserted rows in my table.
so i have my sphinx object and in query i use follow conditions:

->limit(10)
->setSortMode(\Sphinx\SphinxClient::SPH_SORT_EXTENDED,"created_at DESC" )

in this way sphinx get the first 10 records of table and order these.

what is correct way to do it?

i used also ->get(true) but i have an error on row 290 of SphinxSearch Class.

How to configure this with the lumen 5.2?

As I can not add providers directly, So need to make so many changes and still can not configure it.
Can anyone help me how to configure it with the lumen 5.2 framework?

spinx search greater then less condition

I want to implement greater then and less then condition in sphinx search

I have one table contain job

    id   | job_title      | min_experience | max_experience 
    101  | php Developer  | 4              | 10
    102  | PHP Developer  | 6              | 9
    103  | PHP Developer  | 4              | 5

If user search with 7 year to 8 year experience jobs then 2 (101 and 102) records will display because in these records range are between them. How can I implement this logic on sphinx search. Please if you have an idea share.

there is a setFilterRange range but it will work on one field

If I will implement this


    $sphinx->setFilterRange("min_experience", 7 , 8);  
    // no result  because both are less then 7

    $sphinx->setFilterRange("min_experience", 7 , 8); 
    // no result will display because max experience is 10 or 9

But both records are valid

http://stackoverflow.com/questions/37608667/spinx-search-greater-then-less-condition

How can i use jointure

Hello,

I need to some thinks like:

$sphinx->search($search, 'inews')->with('type','category')->get()
but the whith jointure dont work.

How can i do that
Thanks

Searching across Multiple words

When trying to do a search for BMW Motorrad or partials of it.

searching for:

BMW is ok
BMW M or any characters after return no results
BMW Motorrad returns the company


public static function getQSAdvertiser($keyword){
        $sphinx = new SphinxSearch();
        $results = $sphinx
            ->search($keyword, 'companyqs')
            ->limit(10000)
            ->setMatchMode(\Sphinx\SphinxClient::SPH_MATCH_EXTENDED2)
            ->setRankingMode(\Sphinx\SphinxClient::SPH_RANK_MATCHANY)
            ->query();

        return $results;
    }

composer install warning

I'm getting this warning whenever I add this package. Is there a resolution to address it?

Warning: Ambiguous class resolution, "Sphinx\SphinxClient" was found in both "/home/vagrant/code/vendor/kamikax/wtsphinxphp/src/Sphinx/SphinxClient.php" and "/home/vagrant/code/vendor/gigablah/sphinxphp/src/Sphinx/SphinxClient.php", the first will be used.

setIndexWeights

Please add a method to set index weights on multiple indexes.
Should be something like this:
public function setIndexWeights($weights)
{
$this->_connection->setIndexWeights($weights);
return $this;
}

using pagination

So it seems there is not built in pagination, I'm trying to build my own.

That said, when I use ->query() it gives me the total_count number I need. But when I use ->get() it gives me the model I want (with the relations), but no total count so I can't paginate properly.

Is there a way to get the total count while using get()?

the parameters of limit

    public function limit($limit, $offset = 0, $max_matches = 1000, $cutoff = 1000)
    {
        $this->_connection->setLimits($offset, $limit, $max_matches, $cutoff);
        return $this;
    }

The change of parameters order is just killing me.

Database connection parameters

Why is it that the DB name and password are left blank on the mysqli connection function call, instead of them being set as blank on the config file? This would make changing the DB connection parameters a lot easier

Filter using array?

I have a country field and array of searchableCountries.

$searchableCountry = explode(",", Input::get('searchableCountry'));
if ($searchableCountry != null) {
            $results = $cl->Filter('country', [$searchableCountry]);
        }

However, when I search using single string it works:

$country           = Input::get('country');
if ($country != "" || $country != null) {
            $results = $cl->Filter('country', [$country]);
        }

PHP artisan vendor publish issue

Hi,

I tried to install this package but I got problem when try to run "php artisan vendor:publish sngrl/sphinxsearch", it says "Too many arguments", Im using Laravel 5.0

Thank you,
Noel

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.