Skip to content

Commit

Permalink
Added against where
Browse files Browse the repository at this point in the history
  • Loading branch information
sciku1 committed Dec 14, 2017
1 parent 2b6dd42 commit fc82278
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/Macros/against.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

$this->search = $search;
$query = "MATCH ($match) AGAINST (? {$modeSql})";
$this->orWhereRaw($query, [$search]);
$this->orderByRaw("($query) $ordering", [$search]);

}
Expand Down
31 changes: 31 additions & 0 deletions src/Macros/againstWhere.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Illuminate\Database\Query\Builder;

Builder::macro("againstWhere", function ($search, $mode = '') {
if (empty($this->matches)) {
$this->matches = [];
}

switch ($mode) {
case 'boolean':
$modeSql = 'IN BOOLEAN MODE';
break;
case 'natural':
$modeSql = 'IN NATURAL LANGUAGE MODE';
break;
default:
$modeSql = '';
break;
}

foreach ($this->matches as $match) {

$this->search = $search;
$query = "MATCH ($match) AGAINST (? {$modeSql})";
$this->orWhereRaw($query, [$search]);

}

return $this;
});

0 comments on commit fc82278

Please sign in to comment.