diezeel / laravel-sphinx
A Laravel query builder for SphinxQL
Installs: 7 361
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 24
Type:project
pkg:composer/diezeel/laravel-sphinx
Requires
- php: >=5.5.9
- foolz/sphinxql-query-builder: ^2.1.0
Requires (Dev)
- illuminate/bus: ~5.2.0|~5.3.0|~5.4.0
- illuminate/database: ~5.2.0|~5.3.0|~5.4.0
- illuminate/support: ~5.2.0|~5.3.0|~5.4.0
- orchestra/testbench: ~3.1
- phpunit/phpunit: ~5.5
- symfony/filesystem: ^3.0
Suggests
- laravel/framework: The Laravel Framework
- prettus/l5-repository: Repositories to the database layer
README
Laravel-Sphinx Database connector, providing an expressive query builder, Eloquent, ActiveRecord style ORM
Installation
laravel-sphinx can be installed with Composer by adding it as a dependency to your project's composer.json file.
{
    "require": {
        "diezeel/laravel-sphinx": "*"
    }
}
Please refer to Composer's documentation for more detailed installation and usage instructions.
Config
After updating composer, add the ServiceProvider to the providers array in config/app.php
DieZeeL\Database\SphinxConnection\SphinxServiceProvider::class,
Finally you can just add Sphinx Connection to the database array in config/database.php
'sphinx' => [ 'driver' => 'sphinx', 'host' => env('SPHINX_HOST', env('DB_HOST','127.0.0.1')), 'port' => 9306, ],
Usage
Get a connection and build queries
$db = \DB::connection('sphinx');
Using The Query Builder
$users = $db->table('rt')->where('votes', '>', 100)->get();
Using The Eloquent ORM
class Product extends \DieZeeL\Database\SphinxConnection\Eloquent\Model {} $product = Product::find(1); $products = Product::where('votes', '>', 1)->get(); $products = Product::match('name', 'match text')->get();
Attribute Casting
For the results of the column attr_multi can choose the format, which is converted to an array.
The values of '(1, 2, 3)' for column type attr_multi converted to an array [1, 2, 3]
class Product extends \DieZeeL\Database\SphinxConnection\Eloquent\Model { protected $casts = [ 'tags' => 'mva', ]; }
Query Builder
$sq = $db->table('rt');
For the build a query, using strong typing of values (how in SphinxQl).
Notice:
id = 1andid = '1'not the same
- 
integer It is used to type integer attr_uint
- 
float It is used to type float attr_float
- 
bool (integer) It is used to type bool attr_bool, will be converted to integer (0 or 1)
- 
array (MVA) It is used to type MVA attr_multi$sq->insert([ 'id' => 1, 'tags' => [1, 2, 3] ]); // Output: INSERT INTO rt (id, tags) VALUES(1, (1, 2, 3)) 
- 
string - string values, escaped when requested $sq->insert([ 'id' => 1, 'name' => "name 'text'" ]); // Output: INSERT INTO rt (id, name) VALUES(1, 'name \'text\'') 
MATCH
- 
$sq->match($column, $value, $half = false) Search in full-text fields. Can be used multiple times in the same query. Column can be an array. Value can be an Expression to bypass escaping (and use your own custom solution). <?php $sq->match('title', 'Otoshimono') ->match('character', 'Nymph') ->match(array('hates', 'despises'), 'Oregano'); $sq->match(function(\Foolz\SphinxQL\Match $m) { $m->not('text'); }); For a function matchused library SphinxQL::match
WITHIN GROUP, ORDER, OPTION
- 
$sq->withinGroupOrderBy($column, $direction = 'ASC') WITHIN GROUP ORDER BY $column [$direction]Direction can be omitted with null, or beASCorDESCcase insensitive.
- 
$sq->orderBy($column, $direction = null) ORDER BY $column [$direction]Direction can be omitted with null, or beASCorDESCcase insensitive.
- 
$sq->option($name, $value) OPTION $name = $valueSet a SphinxQL option such as max_matchesorreverse_scanfor the query.
whereMulti
- 
$sq->whereMulti($column, $operator, $values) All parameters converted to a flat array $sq->whereMulti('id', '=', [1, 2, 3, [4, 5]]); // Output: WHERE id = 1 and id = 2 and id = 3 and id = 4 and id = 5 For the inandnot inis different$sq->whereMulti('id', 'in', [1, 2, 3]); // Output: WHERE id in (1) and id in (2) and id in (3) $sq->whereMulti('id', 'in', [1, [20, 21], [30, 31]]); // Output: WHERE id in (1) and id in (20, 21) and id in (30, 31) // Equivalently $sq->whereMulti('id', 'in', 1, [20, 21], [30, 31]); // Output: WHERE id in (1) and id in (20, 21) and id in (30, 31) 
Replace
- 
$sq->replace($values) $sq->replace([ 'id' => 1, 'name' => 'text name' ]); 
API SphinxConnection
- \Foolz\SphinxQL\Drivers\Pdo\Connection $db->getSphinxQLDriversConnection()
- \Foolz\SphinxQL\Helper $db->getSphinxQLHelper()
- \Foolz\SphinxQL\SphinxQL $db->createSphinxQL()