Fixed api issue
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Models\Art;
|
||||
use App\Models\Book;
|
||||
use App\Models\Branch;
|
||||
use App\Models\BylawDocument;
|
||||
use App\Models\BylawNode;
|
||||
use App\Models\Chapter;
|
||||
use App\Models\Division;
|
||||
use App\Models\Gate;
|
||||
@@ -26,7 +27,7 @@ class GlobalSearchApiController extends Controller
|
||||
use BaseApiResponse;
|
||||
|
||||
/**
|
||||
* Massive Search across ALL data types
|
||||
* Massive Search across ALL data types (With dynamic Date/Number Sorting & Deep Art Search)
|
||||
*/
|
||||
public function search(Request $request)
|
||||
{
|
||||
@@ -45,7 +46,7 @@ class GlobalSearchApiController extends Controller
|
||||
$results = collect();
|
||||
|
||||
if (!empty($searchTerm)) {
|
||||
$limitPerTable = 100;
|
||||
$limitPerTable = 100; // Performance safeguard
|
||||
|
||||
// 1. Search Bylaw Documents
|
||||
$bylaws = BylawDocument::with(['category', 'approvalAuthority', 'promulgationAuthority'])
|
||||
@@ -65,7 +66,7 @@ class GlobalSearchApiController extends Controller
|
||||
$formatted['type'] = 'bylaw';
|
||||
return $formatted;
|
||||
});
|
||||
$results = $results->merge($bylaws);
|
||||
$results = $results->concat($bylaws); // Changed to concat to prevent overwriting
|
||||
|
||||
// 2. Search Judicial Precedents
|
||||
$judicials = JudicialPrecedent::with('category')
|
||||
@@ -78,7 +79,7 @@ class GlobalSearchApiController extends Controller
|
||||
$formatted['type'] = 'judicial_precedent';
|
||||
return $formatted;
|
||||
});
|
||||
$results = $results->merge($judicials);
|
||||
$results = $results->concat($judicials);
|
||||
|
||||
// 3. Search Legal Opinions
|
||||
$opinions = LegalOpinion::with('category')
|
||||
@@ -92,21 +93,28 @@ class GlobalSearchApiController extends Controller
|
||||
$formatted['type'] = 'legal_opinion';
|
||||
return $formatted;
|
||||
});
|
||||
$results = $results->merge($opinions);
|
||||
$results = $results->concat($opinions);
|
||||
|
||||
// 4. Search Arts (Exact fast Fash search Fash search Fash search Fash search match Fash search Fash search Fash search to ArtController)
|
||||
// 4. Search Arts (Fully restored deep relational search without breaking relationships)
|
||||
$arts = Art::with(['law', 'law.category', 'chapter', 'part', 'volum', 'book', 'section', 'gate'])
|
||||
->where(function ($q) use ($searchTerm) {
|
||||
$q->where('title', '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}%"); });
|
||||
})
|
||||
->take($limitPerTable)->get()->map(function($item) use ($searchTerm) {
|
||||
$formatted = $this->formatArt($item, $searchTerm, Art::class);
|
||||
$formatted['type'] = 'art';
|
||||
return $formatted;
|
||||
});
|
||||
$results = $results->merge($arts);
|
||||
$results = $results->concat($arts);
|
||||
|
||||
// 5. Search Laws and Structural Models
|
||||
$structuralModels = [
|
||||
@@ -128,7 +136,7 @@ class GlobalSearchApiController extends Controller
|
||||
return $formatted;
|
||||
});
|
||||
|
||||
$results = $results->merge($items);
|
||||
$results = $results->concat($items);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,7 +224,7 @@ class GlobalSearchApiController extends Controller
|
||||
$formatted['type'] = 'bylaw';
|
||||
return $formatted;
|
||||
});
|
||||
$results = $results->merge($bylaws);
|
||||
$results = $results->concat($bylaws);
|
||||
|
||||
// 2. Judicial Precedents
|
||||
$judicialQuery = JudicialPrecedent::with('category')
|
||||
@@ -231,7 +239,7 @@ class GlobalSearchApiController extends Controller
|
||||
$formatted['type'] = 'judicial_precedent';
|
||||
return $formatted;
|
||||
});
|
||||
$results = $results->merge($judicials);
|
||||
$results = $results->concat($judicials);
|
||||
|
||||
// 3. Legal Opinions
|
||||
$opinionQuery = LegalOpinion::with('category')
|
||||
@@ -247,14 +255,21 @@ class GlobalSearchApiController extends Controller
|
||||
$formatted['type'] = 'legal_opinion';
|
||||
return $formatted;
|
||||
});
|
||||
$results = $results->merge($opinions);
|
||||
$results = $results->concat($opinions);
|
||||
|
||||
// 4. Search Arts (Exact fast match Fash search to ArtController)
|
||||
// 4. Search Arts
|
||||
$artQuery = Art::with(['law', 'law.category', 'chapter', 'part', 'volum', 'book', 'section', 'gate'])
|
||||
->where(function ($q) use ($searchTerm) {
|
||||
$q->where('title', '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();
|
||||
$arts = $artQuery->take($limitPerTable)->get()->map(function($item) use ($searchTerm) {
|
||||
@@ -262,7 +277,7 @@ class GlobalSearchApiController extends Controller
|
||||
$formatted['type'] = 'art';
|
||||
return $formatted;
|
||||
});
|
||||
$results = $results->merge($arts);
|
||||
$results = $results->concat($arts);
|
||||
|
||||
// 5. Structural Models
|
||||
$structuralModels = [
|
||||
@@ -286,7 +301,7 @@ class GlobalSearchApiController extends Controller
|
||||
$formatted['type'] = ($table === 'section') ? 'sections' : $table;
|
||||
return $formatted;
|
||||
});
|
||||
$results = $results->merge($items);
|
||||
$results = $results->concat($items);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -375,7 +390,6 @@ class GlobalSearchApiController extends Controller
|
||||
|
||||
$text = $art->text ?? '';
|
||||
|
||||
// Multi-byte safe Context Snippet Extraction for Persian/Arabic Fash search Fash search Fash search
|
||||
if (!empty($searchTerm) && !empty($text)) {
|
||||
$pos = mb_stripos($text, $searchTerm);
|
||||
if ($pos !== false) {
|
||||
@@ -391,7 +405,6 @@ class GlobalSearchApiController extends Controller
|
||||
$context = $text;
|
||||
}
|
||||
|
||||
// PERFECTLY MATCHED TO YOUR ARTCONTROLLER MAPPING
|
||||
return [
|
||||
'id' => $art->id,
|
||||
'title' => $art->title,
|
||||
@@ -406,7 +419,6 @@ class GlobalSearchApiController extends Controller
|
||||
'price' => $law?->price,
|
||||
'image' => $law?->image,
|
||||
|
||||
// Relational Objects
|
||||
'law' => $art->law != null ? [
|
||||
'id' => $art->law->id,
|
||||
'title' => $art->law->title,
|
||||
|
||||
Reference in New Issue
Block a user