mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-07-17 00:32:36 +00:00
Reduced data retreived from database on page search
This commit is contained in:
parent
9e0164f4f4
commit
b0b6f466c1
|
@ -6,6 +6,7 @@ use BookStack\Auth\Permissions\PermissionService;
|
||||||
use BookStack\Auth\User;
|
use BookStack\Auth\User;
|
||||||
use BookStack\Entities\EntityProvider;
|
use BookStack\Entities\EntityProvider;
|
||||||
use BookStack\Entities\Models\Entity;
|
use BookStack\Entities\Models\Entity;
|
||||||
|
use BookStack\Entities\Models\Page;
|
||||||
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
||||||
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
|
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
|
||||||
use Illuminate\Database\Query\Builder;
|
use Illuminate\Database\Query\Builder;
|
||||||
|
@ -135,6 +136,10 @@ class SearchRunner
|
||||||
$entity = $this->entityProvider->get($entityType);
|
$entity = $this->entityProvider->get($entityType);
|
||||||
$entityQuery = $entity->newQuery();
|
$entityQuery = $entity->newQuery();
|
||||||
|
|
||||||
|
if ($entity instanceof Page) {
|
||||||
|
$entityQuery->select($entity::$listAttributes);
|
||||||
|
}
|
||||||
|
|
||||||
// Handle normal search terms
|
// Handle normal search terms
|
||||||
$this->applyTermSearch($entityQuery, $searchOpts->searches, $entity);
|
$this->applyTermSearch($entityQuery, $searchOpts->searches, $entity);
|
||||||
|
|
||||||
|
@ -178,16 +183,19 @@ class SearchRunner
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$subQuery->where('entity_type', '=', $entity->getMorphClass());
|
$subQuery->where('entity_type', '=', $entity->getMorphClass());
|
||||||
|
|
||||||
$subQuery->where(function (Builder $query) use ($terms) {
|
$subQuery->where(function (Builder $query) use ($terms) {
|
||||||
foreach ($terms as $inputTerm) {
|
foreach ($terms as $inputTerm) {
|
||||||
$query->orWhere('term', 'like', $inputTerm . '%');
|
$query->orWhere('term', 'like', $inputTerm . '%');
|
||||||
}
|
}
|
||||||
})->groupBy('entity_type', 'entity_id');
|
})->groupBy('entity_type', 'entity_id');
|
||||||
|
|
||||||
$entityQuery->join(DB::raw('(' . $subQuery->toSql() . ') as s'), function (JoinClause $join) {
|
$entityQuery->join(DB::raw('(' . $subQuery->toSql() . ') as s'), function (JoinClause $join) {
|
||||||
$join->on('id', '=', 'entity_id');
|
$join->on('id', '=', 'entity_id');
|
||||||
})->addSelect($entity->getTable() . '.*')
|
})
|
||||||
->selectRaw('s.score')
|
->addSelect(DB::raw('s.score'))
|
||||||
->orderBy('score', 'desc');
|
->orderBy('score', 'desc');
|
||||||
|
|
||||||
$entityQuery->mergeBindings($subQuery);
|
$entityQuery->mergeBindings($subQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user