Skip to content

Commit 46d3bdd

Browse files
authored
Merge pull request #12 from fobiaphp/develop
Bump version 1.1
2 parents dec8222 + ebf9588 commit 46d3bdd

22 files changed

+499
-144
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Finally you can just add `Sphinx Connection` to the database array in config/dat
4646
'driver' => 'sphinx',
4747
'host' => env('SPHINX_HOST', env('DB_HOST','127.0.0.1')),
4848
'port' => 9306,
49+
'database' => '',
4950
],
5051
```
5152

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
"illuminate/bus": "^6.0|^7.0",
1313
"illuminate/database": "^6.0|^7.0",
1414
"illuminate/support": "^6.0|^7.0",
15+
"laravel/scout": "^7.0|^8.0",
1516
"symfony/filesystem": "^4.0|^5.0",
1617
"orchestra/testbench": "^4.0|^5.0",
1718
"phpunit/phpunit": "^8.5"
1819
},
1920
"suggest": {
2021
"laravel/framework": "The Laravel Framework",
21-
"prettus/l5-repository": "Repositories to the database layer"
22+
"laravel/scout": "The Laravel scout"
2223
},
2324
"autoload": {
2425
"psr-4": {

src/Eloquent/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function paginate($perPage = 15, $columns = ['*'], $pageName = 'page', $p
4242
*/
4343
public function getCountForPagination($columns = ['*'])
4444
{
45-
$results = $this->getQuery()->getConnection()->select("SHOW META");
45+
$results = $this->getQuery()->getConnection()->select('SHOW META');
4646
// mysql> SHOW META;
4747
// +---------------+-------+
4848
// | Variable_name | Value |

src/Eloquent/Model.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ class Model extends \Illuminate\Database\Eloquent\Model
3434
protected $connection = 'sphinx';
3535

3636
protected $perPage = 15;
37+
3738
public $timestamps = false;
39+
3840
public $incrementing = false;
3941

4042
/*
@@ -59,7 +61,7 @@ protected function filterParamsUint($args)
5961
{
6062
$args = Arr::flatten((array) $args);
6163
$args = array_filter((array) $args, function ($v) {
62-
return (($v !== null) && ($v !== ''));
64+
return ($v !== null) && ($v !== '');
6365
});
6466
if (!count($args)) {
6567
return false;
@@ -116,7 +118,6 @@ protected function castAttribute($key, $value)
116118
}
117119
}
118120

119-
120121
/**
121122
* Get a new query builder that doesn't have any global scopes.
122123
*
@@ -147,7 +148,7 @@ public function newEloquentBuilder($query)
147148
protected function newBaseQueryBuilder()
148149
{
149150
$conn = $this->getConnection();
150-
$grammar = new QueryGrammar;
151+
$grammar = new QueryGrammar();
151152

152153
return new QueryBuilder($conn, $grammar, $conn->getPostProcessor());
153154
}

src/Eloquent/Query/Builder.php

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ class Builder extends QueryBuilder
3535
];
3636

3737
public $grouporders;
38+
3839
public $options;
40+
3941
public $facets;
42+
4043
public $match;
4144

4245
/**
@@ -50,7 +53,7 @@ public function toSql()
5053
}
5154

5255
/**
53-
* @inheritdoc
56+
* {@inheritdoc}
5457
*/
5558
protected function runSelect()
5659
{
@@ -130,9 +133,8 @@ public function replace(array $values)
130133
return $this->connection->affectingStatement($sql, $bindings); // insert($sql, $bindings);
131134
}
132135

133-
134136
/**
135-
* @inheritdoc
137+
* {@inheritdoc}
136138
*/
137139
public function update(array $values)
138140
{
@@ -144,7 +146,6 @@ public function update(array $values)
144146
));
145147
}
146148

147-
148149
/**
149150
* Проверка списков MVA либо множественая проверка всех перечисленых значений
150151
*
@@ -165,7 +166,7 @@ public function whereMulti($column, $operator = null, $values = null)
165166
if (is_string($operator) && in_array(strtolower($operator), ['in', 'not in', '=', '<', '>', '<=', '>=', '<>', '!='])) {
166167
//$values = array_slice(func_get_args(), 3);
167168
} else {
168-
throw new \RuntimeException("Not defened operator");
169+
throw new \RuntimeException('Not defened operator');
169170
}
170171

171172
$operator = strtolower($operator);
@@ -217,7 +218,6 @@ public function whereMulti($column, $operator = null, $values = null)
217218
* 'field_weights'= (title=10, body=3), - a named integer list (per-field user weights for ranking)
218219
* 'index_weights' = (products_rt=10, body=3), - a named integer list (per-index user weights for ranking)
219220
*
220-
*
221221
* @param string $name Option name
222222
* @param string $value Option value
223223
*
@@ -233,15 +233,6 @@ public function option($name, $value)
233233
return $this;
234234
}
235235

236-
/**
237-
* @deprecated
238-
*/
239-
public function options($name, $value)
240-
{
241-
return $this->option($name, $value);
242-
}
243-
244-
245236
/**
246237
* WITHIN GROUP ORDER BY clause (SphinxQL-specific)
247238
* Adds to the previously added columns
@@ -256,29 +247,28 @@ public function withinGroupOrderBy($column, $direction = 'ASC')
256247
{
257248
$direction = mb_strtoupper($direction);
258249
if ($direction != 'ASC' && $direction != 'DESC') {
259-
throw new \RuntimeException("Undefined direction group (asc/desc) - " . $direction);
250+
throw new \RuntimeException('Undefined direction group (asc/desc) - ' . $direction);
260251
}
261252
$this->grouporders[$column] = $direction;
262253
return $this;
263254
}
264255

265-
266256
/**
267257
* MATCH clause (Sphinx-specific)
268258
*
269259
* @param mixed $column The column name (can be array, string, Closure, or Match)
270260
* @param string $value The value
271-
* @param boolean $half Exclude ", |, - control characters from being escaped
261+
* @param bool $half Exclude ", |, - control characters from being escaped
272262
*
273263
* @return self
274264
*/
275265
public function match($column, $value = null, $half = false)
276266
{
277267
if ($column === '*' || (is_array($column) && in_array('*', $column))) {
278-
$column = array();
268+
$column = [];
279269
}
280270

281-
$this->match[] = array('column' => $column, 'value' => $value, 'half' => $half);
271+
$this->match[] = ['column' => $column, 'value' => $value, 'half' => $half];
282272

283273
return $this;
284274
}
@@ -295,7 +285,7 @@ public function facet($callback)
295285
{
296286
if (!$callback instanceof Facet) {
297287
if (!$callback instanceof \Closure) {
298-
throw new \Exception("Not Facet");
288+
throw new \Exception('Not Facet');
299289
}
300290
$facet = new Facet($this->getConnection()->getSphinxQLDriversConnection());
301291
$callback($facet);
@@ -308,7 +298,6 @@ public function facet($callback)
308298
return $this;
309299
}
310300

311-
312301
/**
313302
* Масив преобразуется в список целых числе, null и пустые строки игнорятся
314303
*
@@ -323,7 +312,7 @@ protected function filterParamsUint($args)
323312
{
324313
$args = Arr::flatten((array) $args);
325314
$args = array_filter((array) $args, function ($v) {
326-
return (($v !== null) && ($v !== ''));
315+
return ($v !== null) && ($v !== '');
327316
});
328317
if (!count($args)) {
329318
return false;

src/Eloquent/Query/Grammar.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
use Foolz\SphinxQL\Facet;
1212
use Foolz\SphinxQL\Match;
13-
use Illuminate\Database\Query\Grammars\Grammar as BaseGrammar;
1413
use Illuminate\Database\Query\Builder as BaseBuilder;
14+
use Illuminate\Database\Query\Grammars\Grammar as BaseGrammar;
1515

1616
/**
1717
* Class Grammar
@@ -37,7 +37,7 @@ class Grammar extends BaseGrammar
3737
];
3838

3939
/**
40-
* @inheritdoc
40+
* {@inheritdoc}
4141
*/
4242
public function compileSelect(BaseBuilder $query)
4343
{
@@ -54,7 +54,7 @@ protected function compileGrouporders(BaseBuilder $query, $groups)
5454
foreach ($groups as $k => $v) {
5555
$sql[] = $k . ' ' . $v;
5656
}
57-
return 'WITHIN GROUP ORDER BY ' . implode(", ", $sql);
57+
return 'WITHIN GROUP ORDER BY ' . implode(', ', $sql);
5858
}
5959

6060
protected function compileOptions(BaseBuilder $query, $options = null)
@@ -73,9 +73,9 @@ protected function compileOptions(BaseBuilder $query, $options = null)
7373
$weights[] = "{$k} = " . (int) $v;
7474
}
7575
} else {
76-
$weights[] = preg_replace("/\(|\)/", "", $opt_val);
76+
$weights[] = preg_replace("/\(|\)/", '', $opt_val);
7777
}
78-
$opt_val = "(" . implode(", ", $weights) . ")";
78+
$opt_val = '(' . implode(', ', $weights) . ')';
7979
}
8080

8181
if ($opt == 'comment') {
@@ -104,7 +104,7 @@ protected function compileFacets(BaseBuilder $query, $facets)
104104
if (!empty($facets)) {
105105
foreach ($facets as $facet) {
106106
if (!$facet instanceof Facet) {
107-
throw new \Exception("Not Facet");
107+
throw new \Exception('Not Facet');
108108
}
109109
// dynamically set the own SphinxQL connection if the Facet doesn't own one
110110
//if ($facet->getConnection() === null) {
@@ -113,7 +113,7 @@ protected function compileFacets(BaseBuilder $query, $facets)
113113
// // go back to the status quo for reuse
114114
// $facet->setConnection();
115115
//} else {
116-
$sql[] = $facet->getFacet();
116+
$sql[] = $facet->getFacet();
117117
//}
118118
//$facet = "FACET " .
119119
}
@@ -166,7 +166,7 @@ protected function compileOffset(BaseBuilder $query, $offset)
166166
protected function compileFrom(BaseBuilder $query, $table)
167167
{
168168
if (is_array($table)) {
169-
return 'FROM ' . implode(", ", $table);
169+
return 'FROM ' . implode(', ', $table);
170170
}
171171
return 'FROM ' . $this->wrapTable($table);
172172
}
@@ -185,7 +185,7 @@ public function compileMatch(Builder $queryBuilder, $matchs)
185185
$query = '';
186186

187187
if (!empty($matchs)) {
188-
$matched = array();
188+
$matched = [];
189189

190190
foreach ($matchs as $match) {
191191
$pre = '';
@@ -200,6 +200,9 @@ public function compileMatch(Builder $queryBuilder, $matchs)
200200
} elseif (is_array($match['column'])) {
201201
$pre .= '@(' . implode(',', $match['column']) . ') ';
202202
} else {
203+
if (is_numeric($match['column'])) {
204+
$match['column'] = '"' . $match['column'] . '"';
205+
}
203206
$pre .= '@' . $match['column'] . ' ';
204207
}
205208

@@ -208,8 +211,9 @@ public function compileMatch(Builder $queryBuilder, $matchs)
208211
} else {
209212
$pre .= $sphinxQL->escapeMatch($match['value']);
210213
}
211-
212-
$matched[] = '(' . $pre . ')';
214+
if ($pre) {
215+
$matched[] = '(' . $pre . ')';
216+
}
213217
}
214218

215219
$matched = implode(' ', $matched);
@@ -219,7 +223,6 @@ public function compileMatch(Builder $queryBuilder, $matchs)
219223
return $query;
220224
}
221225

222-
223226
public function compileWheres(BaseBuilder $query)
224227
{
225228
$where = parent::compileWheres($query);
@@ -243,7 +246,7 @@ public function prepareBindingsForUpdate(array $bindings, array $values)
243246
}
244247

245248
/**
246-
* @inheritdoc
249+
* {@inheritdoc}
247250
*/
248251
public function wrap($value, $prefixAlias = false)
249252
{
@@ -322,6 +325,7 @@ protected function wrapValue2($value)
322325
if ($value === '*') {
323326
return $value;
324327
}
328+
325329
try {
326330
return \DB::connection('sphinx')->getPdo()->quote($value);
327331
} catch (\Exception $e) {

src/Facade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class Facade extends \Illuminate\Support\Facades\Facade
88
{
99
/**
10-
* {@inheritDoc}
10+
* {@inheritdoc}
1111
*/
1212
protected static function getFacadeAccessor()
1313
{

src/Repository/Repository.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function __construct(\Illuminate\Container\Container $app, \Illuminate\Su
3131
}
3232

3333
/**
34-
* @inheritdoc
34+
* {@inheritdoc}
3535
*/
3636
public function paginate($perPage = null, $columns = ['*'])
3737
{
@@ -43,7 +43,6 @@ public function paginate($perPage = null, $columns = ['*'])
4343
return $this->model->paginate($perPage, $columns);
4444
}
4545

46-
4746
public function returnPaginate($params)
4847
{
4948
$perPage = $this->perPage;

src/Result.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* Result.php file
4+
*/
5+
6+
namespace Fobia\Database\SphinxConnection;
7+
8+
use Illuminate\Support\Collection;
9+
10+
/**
11+
* Class Result
12+
*/
13+
class Result
14+
{
15+
/**
16+
* @var \Illuminate\Support\Collection
17+
*/
18+
public $result;
19+
20+
/**
21+
* @var int
22+
*/
23+
public $total;
24+
25+
public function __construct($result = null)
26+
{
27+
$this->result = new Collection($result ?? []);
28+
$this->total = 0;
29+
}
30+
}

0 commit comments

Comments
 (0)