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;
|
||||
@@ -46,16 +47,18 @@ class GlobalSearchApiController extends Controller
|
||||
if (!empty($searchTerm)) {
|
||||
$limitPerTable = 100; // Performance safeguard
|
||||
|
||||
// 1. Search Bylaw Documents (Including deeper node_content search)
|
||||
$bylaws = BylawDocument::with(['category', 'approvalAuthority', 'promulgationAuthority', 'nodes'])
|
||||
// 1. Search Bylaw Documents (Including node_content subquery)
|
||||
$bylaws = BylawDocument::with(['category', 'approvalAuthority', 'promulgationAuthority'])
|
||||
->where('is_published', true)
|
||||
->where(function ($q) use ($searchTerm) {
|
||||
$q->where('title', 'LIKE', "%{$searchTerm}%")
|
||||
->orWhere('description', 'LIKE', "%{$searchTerm}%")
|
||||
->orWhere('promulgation_number', 'LIKE', "%{$searchTerm}%")
|
||||
->orWhere('official_gazette_number', 'LIKE', "%{$searchTerm}%")
|
||||
->orWhereHas('nodes', function ($nodeQuery) use ($searchTerm) {
|
||||
$nodeQuery->where('node_content', 'LIKE', "%{$searchTerm}%");
|
||||
->orWhereIn('id', function($subQuery) use ($searchTerm) {
|
||||
$subQuery->select('document_id')
|
||||
->from('bylaw_nodes')
|
||||
->where('node_content', 'LIKE', "%{$searchTerm}%");
|
||||
});
|
||||
})->take($limitPerTable)->get()->map(function($item) {
|
||||
$formatted = $this->formatBylaw($item);
|
||||
@@ -191,15 +194,17 @@ class GlobalSearchApiController extends Controller
|
||||
if (!empty($searchTerm)) {
|
||||
|
||||
// 1. Bylaw Documents
|
||||
$bylawQuery = BylawDocument::with(['category', 'approvalAuthority', 'promulgationAuthority', 'nodes'])
|
||||
$bylawQuery = BylawDocument::with(['category', 'approvalAuthority', 'promulgationAuthority'])
|
||||
->where('is_published', true)
|
||||
->where(function ($q) use ($searchTerm) {
|
||||
$q->where('title', 'LIKE', "%{$searchTerm}%")
|
||||
->orWhere('description', 'LIKE', "%{$searchTerm}%")
|
||||
->orWhere('promulgation_number', 'LIKE', "%{$searchTerm}%")
|
||||
->orWhere('official_gazette_number', 'LIKE', "%{$searchTerm}%")
|
||||
->orWhereHas('nodes', function ($nodeQuery) use ($searchTerm) {
|
||||
$nodeQuery->where('node_content', 'LIKE', "%{$searchTerm}%");
|
||||
->orWhereIn('id', function($subQuery) use ($searchTerm) {
|
||||
$subQuery->select('document_id')
|
||||
->from('bylaw_nodes')
|
||||
->where('node_content', 'LIKE', "%{$searchTerm}%");
|
||||
});
|
||||
});
|
||||
$totalCount += $bylawQuery->count();
|
||||
@@ -299,10 +304,15 @@ class GlobalSearchApiController extends Controller
|
||||
{
|
||||
$isLocked = $this->isLockedForCurrentUserGeneric($item);
|
||||
|
||||
// Fallback description to node_content if empty
|
||||
$description = $item->description;
|
||||
if (empty($description) && $item->relationLoaded('nodes')) {
|
||||
$description = $item->nodes->pluck('node_content')->filter()->implode("\n\n");
|
||||
|
||||
// Direct Query Fallback: If description is empty, fetch node_content manually
|
||||
if (empty($description)) {
|
||||
$description = BylawNode::where('document_id', $item->id)
|
||||
->orderBy('sort_order', 'asc')
|
||||
->pluck('node_content')
|
||||
->filter()
|
||||
->implode("\n\n");
|
||||
}
|
||||
|
||||
return [
|
||||
|
||||
Reference in New Issue
Block a user