Skip to content

Commit

Permalink
Merge pull request #966 from faithcomesbyhearing/FCBHDBP-603
Browse files Browse the repository at this point in the history
FCBHDBP-603 Add feature to sort the verses according to the books in search endpoint
  • Loading branch information
bradflood authored Dec 20, 2023
2 parents 58ca69b + 0d26381 commit 0e7751a
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 25 deletions.
5 changes: 5 additions & 0 deletions .platform/hooks/prebuild/install_php_zip.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

sudo dnf install libzip libzip-devel -y
sudo pecl install zip
echo "extension=zip.so" | sudo tee /etc/php.d/20-zip.ini
19 changes: 17 additions & 2 deletions app/Http/Controllers/Bible/TextController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Illuminate\Database\Query\Expression;
use App\Models\Bible\BibleFileset;
use App\Models\Bible\Book;
use App\Models\Bible\BibleBook;
use App\Models\Language\AlphabetFont;
use App\Traits\AccessControlAPI;
use App\Traits\CheckProjectMembership;
Expand Down Expand Up @@ -165,6 +166,7 @@ public function fonts()
* @OA\Parameter(name="limit", in="query", description="The number of search results to return",
* @OA\Schema(type="integer",default=15)),
* @OA\Parameter(ref="#/components/parameters/page"),
* @OA\Parameter(ref="#/components/parameters/sort_by"),
* @OA\Parameter(name="books", in="query", description="The usfm book ids to search through separated by a comma",
* @OA\Schema(type="string",example="GEN,EXO,MAT")),
* @OA\Response(
Expand Down Expand Up @@ -196,6 +198,7 @@ public function search()
$book_id = checkParam('book|book_id|books');
$limit = checkParam('limit') ?? 15;
$page = checkParam('page');
$sort_by = checkParam('sort_by');

$fileset = BibleFileset::with('bible')->uniqueFileset($fileset_id, 'text_plain')->first();
if (!$fileset) {
Expand Down Expand Up @@ -226,6 +229,11 @@ public function search()
})
->where('bible_verses.verse_text', 'like', $search_text);

if ($sort_by === 'book_order') {
$select_columns[] = BibleBook::getBookOrderSelectColumnExpressionRaw($bible->versification, 'book_order');
$verses->orderBy('book_order');
}

if ($bible && $bible->numeral_system_id) {
$select_columns_extra = array_merge(
$select_columns,
Expand All @@ -242,10 +250,17 @@ public function search()

if ($page) {
$verses = $verses->paginate($limit);
return $this->reply(['audio_filesets' => $audio_filesets, 'verses' => fractal($verses->getCollection(), TextTransformer::class)->paginateWith(new IlluminatePaginatorAdapter($verses))]);
return $this->reply([
'audio_filesets' => $audio_filesets,
'verses' => fractal($verses->getCollection(), TextTransformer::class)
->paginateWith(new IlluminatePaginatorAdapter($verses))
]);
}
$verses = $verses->limit($limit)->get();
return $this->reply(['audio_filesets' => $audio_filesets, 'verses' => fractal($verses, new TextTransformer(), $this->serializer)]);
return $this->reply([
'audio_filesets' => $audio_filesets,
'verses' => fractal($verses, new TextTransformer(), $this->serializer)
]);
}
/**
*
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"bugsnag/bugsnag-laravel": "2.26.0",
"caneara/quest": "4.0.0",
"curl/curl": "2.5.0",
"doctrine/annotations": "2.0.1",
"doctrine/dbal": "3.7.2",
"geoip2/geoip2": "2.13.0",
"google/recaptcha": "1.3.0",
Expand Down
116 changes: 96 additions & 20 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions public/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,9 @@
{
"$ref": "#/components/parameters/page"
},
{
"$ref": "#/components/parameters/sort_by"
},
{
"name": "books",
"in": "query",
Expand Down Expand Up @@ -1744,7 +1747,8 @@
"total_days": {
"type": "integer"
}
}
},
"type": "object"
}
]
},
Expand Down Expand Up @@ -1809,7 +1813,8 @@
"$ref": "#/components/schemas/PlanDay"
}
}
}
},
"type": "object"
}
]
},
Expand Down Expand Up @@ -1903,7 +1908,8 @@
"$ref": "#/components/schemas/PlaylistItemDetail"
}
}
}
},
"type": "object"
}
]
},
Expand Down

0 comments on commit 0e7751a

Please sign in to comment.