Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone committed Mar 2, 2021
1 parent eca0a5a commit ff3e8a7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,34 @@ where (
);
```

#### Search with exact wildcard

Use `withoutWildcardSearching()` to disable adding additional search condition.

```php
use App\User;
use Laravie\QueryFilter\Searchable;

$query = App\User::query();

$searchable = (new Searchable(
'crynobone@gmail', ['name', 'email']
))->withoutWildcardSearching();

return $searchable->apply($query)->get();
```

```sql
select * from `users`
where (
(
`name` like 'crynobone@gmail'
) or (
`email` like 'crynobone@gmail'
)
);
```

#### Search with JSON path

This would allow you to query JSON path using `LIKE` with case insensitive (JSON path in MySQL is case-sensitive by default).
Expand Down
6 changes: 5 additions & 1 deletion src/Value/Keyword.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,14 @@ public static function searchable(string $text, ?string $wildcard = '*', ?string
{
$text = static::sanitize($text);

if (\is_null($wildcard) && ! \is_null($replacement)) {
$wildcard = $replacement;
}

if (empty($text)) {
return [];
} elseif (
(! \is_null($wildcard) && ! \is_null($replacement))
! \is_null($replacement)
&& $wildcard !== $replacement
&& ! Str::contains($text, [$wildcard, $replacement])
&& $wildcardSearching === true
Expand Down

0 comments on commit ff3e8a7

Please sign in to comment.