mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-30 07:32:39 +01:00
Enabled type search filter in book search
This commit is contained in:
parent
dcde599709
commit
73844b9eeb
@ -97,10 +97,16 @@ class SearchService
|
|||||||
public function searchBook($bookId, $searchString)
|
public function searchBook($bookId, $searchString)
|
||||||
{
|
{
|
||||||
$terms = $this->parseSearchString($searchString);
|
$terms = $this->parseSearchString($searchString);
|
||||||
|
$entityTypes = ['page', 'chapter'];
|
||||||
|
$entityTypesToSearch = isset($terms['filters']['type']) ? explode('|', $terms['filters']['type']) : $entityTypes;
|
||||||
|
|
||||||
$results = collect();
|
$results = collect();
|
||||||
$pages = $this->buildEntitySearchQuery($terms, 'page')->where('book_id', '=', $bookId)->take(20)->get();
|
foreach ($entityTypesToSearch as $entityType) {
|
||||||
$chapters = $this->buildEntitySearchQuery($terms, 'chapter')->where('book_id', '=', $bookId)->take(20)->get();
|
if (!in_array($entityType, $entityTypes)) continue;
|
||||||
return $results->merge($pages)->merge($chapters)->sortByDesc('score')->take(20);
|
$search = $this->buildEntitySearchQuery($terms, $entityType)->where('book_id', '=', $bookId)->take(20)->get();
|
||||||
|
$results = $results->merge($search);
|
||||||
|
}
|
||||||
|
return $results->sortByDesc('score')->take(20);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user