mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-01-19 08:42:48 +08:00
Allow search to filter by book_id and chapter_id
This commit is contained in:
parent
33b46882f3
commit
5e2bff8132
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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>'));
|
||||
|
|
Loading…
Reference in New Issue
Block a user