1
0
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:
Dan Brown 2017-04-15 19:31:11 +01:00
parent dcde599709
commit 73844b9eeb
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9

View File

@ -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);
} }
/** /**