fix(search): match Arabic ye/kaf with Persian letters in admin search
Customer names stored with ي/ك were missed when typing ی/ک; fold both sides of LIKE. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+16
-14
@@ -1,5 +1,8 @@
|
||||
<?php
|
||||
namespace App\DB\Te;
|
||||
|
||||
use App\Support\PersianText;
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: AraNote
|
||||
@@ -13,7 +16,8 @@ class Search
|
||||
|
||||
public static function query(&$query, $cols, $search)
|
||||
{
|
||||
$query->where(function ($q) use ($cols, $search) {
|
||||
$like = PersianText::likePattern(strtolower((string) $search));
|
||||
$query->where(function ($q) use ($cols, $like) {
|
||||
$first = true;
|
||||
foreach ($cols as $col) {
|
||||
if (self::hasJoin($col)) {
|
||||
@@ -25,11 +29,9 @@ class Search
|
||||
$whereHas = 'orWhereHas';
|
||||
}
|
||||
$q->$whereHas
|
||||
($exp[0], function ($q) use ($exp, $search) {
|
||||
return $q->whereHas($exp[1], function ($q2) use ($exp, $search) {
|
||||
|
||||
// return $q2->where($exp[2], 'LIKE', '%' . $search . '%');
|
||||
return $q2->whereRaw('lower(`'.$exp[2].'`) like ?', ['%' . strtolower($search) . '%']);
|
||||
($exp[0], function ($q) use ($exp, $like) {
|
||||
return $q->whereHas($exp[1], function ($q2) use ($exp, $like) {
|
||||
return $q2->whereRaw(self::foldedLikeSql($exp[2]), [$like]);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
@@ -39,10 +41,8 @@ class Search
|
||||
$whereHas1 = 'orWhereHas';
|
||||
}
|
||||
$q->$whereHas1
|
||||
// $q->{($first) ? 'whereHas' : 'orWhereHas'}
|
||||
($exp[0], function ($q) use ($exp, $search) {
|
||||
return $q->whereRaw('lower(`'.$exp[1].'`) like ?', ['%' . strtolower($search) . '%']);
|
||||
// return $q->where($exp[1], 'LIKE', '%' . $search . '%');
|
||||
($exp[0], function ($q) use ($exp, $like) {
|
||||
return $q->whereRaw(self::foldedLikeSql($exp[1]), [$like]);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
@@ -51,10 +51,7 @@ class Search
|
||||
}else{
|
||||
$where = 'orWhereRaw';
|
||||
}
|
||||
// return $q->whereRaw('lower(`'.$col.'`) like ?', ['%' . strtolower($search) . '%']);
|
||||
$q->$where('lower(`'.$col.'`) like ?', ['%' . strtolower($search) . '%']);
|
||||
// $q->{($first) ? 'where' : 'orWhere'}($col, 'LIKE', '%' . $search . '%');
|
||||
// $q->{($first) ? 'whereRaw ' : 'orWhereRaw '}($col, 'LIKE', '%' . $search . '%');
|
||||
$q->$where(self::foldedLikeSql($col), [$like]);
|
||||
}
|
||||
if ($first) {
|
||||
$first = false;
|
||||
@@ -63,6 +60,11 @@ class Search
|
||||
});
|
||||
}
|
||||
|
||||
private static function foldedLikeSql(string $column): string
|
||||
{
|
||||
return PersianText::sqlFoldExpr('lower(`'.$column.'`)').' like ?';
|
||||
}
|
||||
|
||||
public static function hasJoin($col)
|
||||
{
|
||||
return sizeof(explode('.', $col)) > 1;
|
||||
|
||||
Reference in New Issue
Block a user