Allow search to filter by book_id and chapter_id

This commit is contained in:
Helder Magalhaes 2025-01-10 10:36:29 +01:00
parent 33b46882f3
commit 5e2bff8132
2 changed files with 33 additions and 0 deletions

View File

@ -454,6 +454,20 @@ class SearchRunner
}
}
protected function filterBookId(EloquentBuilder $query, Entity $model, string $input, bool $negated)
{
if ($model instanceof Page || $model instanceof Chapter) {
$this->applyNegatableWhere($query, $negated, 'book_id', '=', $input);
}
}
protected function filterChapterId(EloquentBuilder $query, Entity $model, string $input, bool $negated)
{
if ($model instanceof Page) {
$this->applyNegatableWhere($query, $negated, 'chapter_id', '=', $input);
}
}
/**
* Sorting filter options.
*/

View File

@ -30,6 +30,25 @@ class EntitySearchTest extends TestCase
$search->assertSeeText($shelf->name, true);
}
public function test_book_id_search()
{
$book = Book::first();
$search = $this->asEditor()->get('/search?query={type:page}{book_id:' . $book->id . '}');
$search->assertSee('Search Results');
$search->assertSeeText($book->id, true);
}
public function test_chapter_id_search()
{
$book = Book::first();
$chapter = $book->chapters->last();
$search = $this->asEditor()->get('/search?query={type:page}{chapter_id:' . $chapter->id . '}');
$search->assertSee('Search Results');
$search->assertSeeText($chapter->id, true);
}
public function test_invalid_page_search()
{
$resp = $this->asEditor()->get('/search?term=' . urlencode('<p>test</p>'));