Compare commits
2 Commits
ed95f5b3ee
...
16e68c3048
| Author | SHA1 | Date | |
|---|---|---|---|
| 16e68c3048 | |||
|
|
10463e2f71 |
@@ -94,19 +94,12 @@ class GlobalSearchApiController extends Controller
|
|||||||
});
|
});
|
||||||
$results = $results->merge($opinions);
|
$results = $results->merge($opinions);
|
||||||
|
|
||||||
// 4. Search Arts (DEEP RELATIONAL SEARCH INCLUDED)
|
// 4. Search Arts (Exact fast Fash search Fash search Fash search Fash search match Fash search Fash search Fash search to ArtController)
|
||||||
$arts = Art::with(['law.category', 'chapter', 'part', 'volum', 'book', 'section', 'gate'])
|
$arts = Art::with(['law', 'law.category', 'chapter', 'part', 'volum', 'book', 'section', 'gate'])
|
||||||
->where(function ($q) use ($searchTerm) {
|
->where(function ($q) use ($searchTerm) {
|
||||||
$q->where('title', 'LIKE', "%{$searchTerm}%")
|
$q->where('title', 'LIKE', "%{$searchTerm}%")
|
||||||
->orWhere('text', 'LIKE', "%{$searchTerm}%")
|
->orWhere('text', 'LIKE', "%{$searchTerm}%")
|
||||||
->orWhere('number', 'LIKE', "%{$searchTerm}%") // Added Number Search
|
->orWhere('number', 'LIKE', "%{$searchTerm}%");
|
||||||
->orWhereHas('law', function ($sub) use ($searchTerm) { $sub->where('title', 'LIKE', "%{$searchTerm}%"); })
|
|
||||||
->orWhereHas('volum', function ($sub) use ($searchTerm) { $sub->where('title', 'LIKE', "%{$searchTerm}%"); })
|
|
||||||
->orWhereHas('book', function ($sub) use ($searchTerm) { $sub->where('title', 'LIKE', "%{$searchTerm}%"); })
|
|
||||||
->orWhereHas('section', function ($sub) use ($searchTerm) { $sub->where('title', 'LIKE', "%{$searchTerm}%"); })
|
|
||||||
->orWhereHas('chapter', function ($sub) use ($searchTerm) { $sub->where('title', 'LIKE', "%{$searchTerm}%"); })
|
|
||||||
->orWhereHas('part', function ($sub) use ($searchTerm) { $sub->where('title', 'LIKE', "%{$searchTerm}%"); })
|
|
||||||
->orWhereHas('gate', function ($sub) use ($searchTerm) { $sub->where('title', 'LIKE', "%{$searchTerm}%"); });
|
|
||||||
})
|
})
|
||||||
->take($limitPerTable)->get()->map(function($item) use ($searchTerm) {
|
->take($limitPerTable)->get()->map(function($item) use ($searchTerm) {
|
||||||
$formatted = $this->formatArt($item, $searchTerm, Art::class);
|
$formatted = $this->formatArt($item, $searchTerm, Art::class);
|
||||||
@@ -256,19 +249,12 @@ class GlobalSearchApiController extends Controller
|
|||||||
});
|
});
|
||||||
$results = $results->merge($opinions);
|
$results = $results->merge($opinions);
|
||||||
|
|
||||||
// 4. Search Arts (DEEP RELATIONAL SEARCH INCLUDED)
|
// 4. Search Arts (Exact fast match Fash search to ArtController)
|
||||||
$artQuery = Art::with(['law.category', 'chapter', 'part', 'volum', 'book', 'section', 'gate'])
|
$artQuery = Art::with(['law', 'law.category', 'chapter', 'part', 'volum', 'book', 'section', 'gate'])
|
||||||
->where(function ($q) use ($searchTerm) {
|
->where(function ($q) use ($searchTerm) {
|
||||||
$q->where('title', 'LIKE', "%{$searchTerm}%")
|
$q->where('title', 'LIKE', "%{$searchTerm}%")
|
||||||
->orWhere('text', 'LIKE', "%{$searchTerm}%")
|
->orWhere('text', 'LIKE', "%{$searchTerm}%")
|
||||||
->orWhere('number', 'LIKE', "%{$searchTerm}%")
|
->orWhere('number', 'LIKE', "%{$searchTerm}%");
|
||||||
->orWhereHas('law', function ($sub) use ($searchTerm) { $sub->where('title', 'LIKE', "%{$searchTerm}%"); })
|
|
||||||
->orWhereHas('volum', function ($sub) use ($searchTerm) { $sub->where('title', 'LIKE', "%{$searchTerm}%"); })
|
|
||||||
->orWhereHas('book', function ($sub) use ($searchTerm) { $sub->where('title', 'LIKE', "%{$searchTerm}%"); })
|
|
||||||
->orWhereHas('section', function ($sub) use ($searchTerm) { $sub->where('title', 'LIKE', "%{$searchTerm}%"); })
|
|
||||||
->orWhereHas('chapter', function ($sub) use ($searchTerm) { $sub->where('title', 'LIKE', "%{$searchTerm}%"); })
|
|
||||||
->orWhereHas('part', function ($sub) use ($searchTerm) { $sub->where('title', 'LIKE', "%{$searchTerm}%"); })
|
|
||||||
->orWhereHas('gate', function ($sub) use ($searchTerm) { $sub->where('title', 'LIKE', "%{$searchTerm}%"); });
|
|
||||||
});
|
});
|
||||||
$totalCount += $artQuery->count();
|
$totalCount += $artQuery->count();
|
||||||
$arts = $artQuery->take($limitPerTable)->get()->map(function($item) use ($searchTerm) {
|
$arts = $artQuery->take($limitPerTable)->get()->map(function($item) use ($searchTerm) {
|
||||||
@@ -323,6 +309,7 @@ class GlobalSearchApiController extends Controller
|
|||||||
private function formatBylaw($item)
|
private function formatBylaw($item)
|
||||||
{
|
{
|
||||||
$isLocked = $this->isLockedForCurrentUserGeneric($item);
|
$isLocked = $this->isLockedForCurrentUserGeneric($item);
|
||||||
|
|
||||||
$description = $item->description;
|
$description = $item->description;
|
||||||
|
|
||||||
$cleanDesc = trim(strip_tags($description ?? ''));
|
$cleanDesc = trim(strip_tags($description ?? ''));
|
||||||
@@ -384,11 +371,11 @@ class GlobalSearchApiController extends Controller
|
|||||||
private function formatArt($art, $searchTerm, $modelClass)
|
private function formatArt($art, $searchTerm, $modelClass)
|
||||||
{
|
{
|
||||||
$law = $art->law ?? Law::find($art->law_id);
|
$law = $art->law ?? Law::find($art->law_id);
|
||||||
$isLocked = ! auth()->user()->isSubscriber() && (bool) $law?->is_locked;
|
$isLocked = ! auth()->user()->isSubscriber() && (bool) ($law?->is_locked ?? false);
|
||||||
|
|
||||||
$text = $art->text ?? '';
|
$text = $art->text ?? '';
|
||||||
|
|
||||||
// Multi-byte safe Context Snippet Extraction for Persian/Arabic
|
// Multi-byte safe Context Snippet Extraction for Persian/Arabic Fash search Fash search Fash search
|
||||||
if (!empty($searchTerm) && !empty($text)) {
|
if (!empty($searchTerm) && !empty($text)) {
|
||||||
$pos = mb_stripos($text, $searchTerm);
|
$pos = mb_stripos($text, $searchTerm);
|
||||||
if ($pos !== false) {
|
if ($pos !== false) {
|
||||||
@@ -398,12 +385,13 @@ class GlobalSearchApiController extends Controller
|
|||||||
if ($start > 0) $context = '...' . $context;
|
if ($start > 0) $context = '...' . $context;
|
||||||
if ($start + $length < mb_strlen($text)) $context = $context . '...';
|
if ($start + $length < mb_strlen($text)) $context = $context . '...';
|
||||||
} else {
|
} else {
|
||||||
$context = $text; // Fallback if match was in title/relations
|
$context = $text;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$context = $text;
|
$context = $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PERFECTLY MATCHED TO YOUR ARTCONTROLLER MAPPING
|
||||||
return [
|
return [
|
||||||
'id' => $art->id,
|
'id' => $art->id,
|
||||||
'title' => $art->title,
|
'title' => $art->title,
|
||||||
@@ -460,7 +448,7 @@ class GlobalSearchApiController extends Controller
|
|||||||
private function formatStructure($item, $modelClass)
|
private function formatStructure($item, $modelClass)
|
||||||
{
|
{
|
||||||
$law = Law::find($item?->law_id ?? $item->id);
|
$law = Law::find($item?->law_id ?? $item->id);
|
||||||
$isLocked = ! auth()->user()->isSubscriber() && (bool) $law?->is_locked;
|
$isLocked = ! auth()->user()->isSubscriber() && (bool) ($law?->is_locked ?? false);
|
||||||
|
|
||||||
$payload = [
|
$payload = [
|
||||||
'id' => $item->id,
|
'id' => $item->id,
|
||||||
|
|||||||
Reference in New Issue
Block a user