Fixed incorrect search logic in last commit
Incorrect cross-entity pagination could lead to hidden entities.
This commit is contained in:
parent
f101c1a622
commit
1e015af3c9
|
@ -64,7 +64,7 @@ class SearchService
|
||||||
* @param string $searchString
|
* @param string $searchString
|
||||||
* @param string $entityType
|
* @param string $entityType
|
||||||
* @param int $page
|
* @param int $page
|
||||||
* @param int $count
|
* @param int $count - Count of each entity to search, Total returned could can be larger and not guaranteed.
|
||||||
* @return array[int, Collection];
|
* @return array[int, Collection];
|
||||||
*/
|
*/
|
||||||
public function searchEntities($searchString, $entityType = 'all', $page = 1, $count = 20)
|
public function searchEntities($searchString, $entityType = 'all', $page = 1, $count = 20)
|
||||||
|
@ -81,21 +81,26 @@ class SearchService
|
||||||
|
|
||||||
$results = collect();
|
$results = collect();
|
||||||
$total = 0;
|
$total = 0;
|
||||||
|
$hasMore = false;
|
||||||
|
|
||||||
foreach ($entityTypesToSearch as $entityType) {
|
foreach ($entityTypesToSearch as $entityType) {
|
||||||
if (!in_array($entityType, $entityTypes)) {
|
if (!in_array($entityType, $entityTypes)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$search = $this->searchEntityTable($terms, $entityType, $page, $count + 1);
|
$search = $this->searchEntityTable($terms, $entityType, $page, $count);
|
||||||
$total += $this->searchEntityTable($terms, $entityType, $page, $count + 1, true);
|
$entityTotal = $this->searchEntityTable($terms, $entityType, $page, $count, true);
|
||||||
|
if ($entityTotal > $page * $count) {
|
||||||
|
$hasMore = true;
|
||||||
|
}
|
||||||
|
$total += $entityTotal;
|
||||||
$results = $results->merge($search);
|
$results = $results->merge($search);
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'total' => $total,
|
'total' => $total,
|
||||||
'count' => count($results),
|
'count' => count($results),
|
||||||
'has_more' => $results->count() > $count,
|
'has_more' => $hasMore,
|
||||||
'results' => $results->sortByDesc('score')->slice(0, $count)->values()
|
'results' => $results->sortByDesc('score')->values()
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue