SearchController
class SearchController extends Controller
Traits
Constants
| MIN_FILE_QUERY_LENGTH |
Minimum length of a search term that is matched against filenames. A substring match cannot use an index, so every term results in a full scan of the (very large) file tables. Terms this short match almost everything and are not a useful query, so they are rejected instead. |
| MAX_RESULT_COUNT |
Upper bound for the result counts of the project, label tree, volume and
file tabs. Determining the exact number of matches means scanning every matching row. The number is only shown as a tab badge and in the result heading, and nobody pages through more results than this, so counting stops once more than this many matches are known to exist. |
Methods
Determines if the request was done by an automated script (with API token or ajax).
Add label tree results to the search view.
Add project results to the search view.
Add volume results to the search view.
Turn a search term into a pattern for a substring match with (i)like.
Determine whether a search term is too short to be matched against filenames.
Count the results of a query, up to one more than MAX_RESULT_COUNT.
Paginate a query with a total that is capped at MAX_RESULT_COUNT.
Paginate a file query, ordered by descending ID.
Details
in
Controller at line 21
bool
isAutomatedRequest(Request|null $request = null)
Determines if the request was done by an automated script (with API token or ajax).
at line 52
index(Guard $auth, Request $request, Modules $modules)
Shows the search page.
at line 100
protected array
searchLabelTrees(User $user, string $query, string $type, bool $includeFederatedSearch)
Add label tree results to the search view.
at line 168
protected array
searchProjects(User $user, string $query, string $type, bool $includeFederatedSearch)
Add project results to the search view.
at line 240
protected array
searchVolumes(User $user, string $query, string $type, bool $includeFederatedSearch)
Add volume results to the search view.
at line 306
protected string
likePattern(string $query)
Turn a search term into a pattern for a substring match with (i)like.
Wildcards in the term are escaped, so they are matched literally. Else a term like "%%%" would get past the minimum length and match everything.
at line 321
protected bool
fileQueryTooShort(string $query)
Determine whether a search term is too short to be matched against filenames.
at line 336
protected int
cappedResultCount(Builder $queryBuilder)
Count the results of a query, up to one more than MAX_RESULT_COUNT.
The selected columns are kept, because all parts of a union (with federated search models) must select the same columns.
at line 356
protected LengthAwarePaginator
paginateCapped(Builder $queryBuilder, int $count, int $perPage)
Paginate a query with a total that is capped at MAX_RESULT_COUNT.
This bounds the number of pages as well. Later pages resolve to the last page, because the paginator would otherwise run the arbitrarily large offset of a hand-written URL.
at line 382
protected LengthAwarePaginator
paginateFiles(Builder $queryBuilder, int $count, int $perPage, bool $restricted)
Paginate a file query, ordered by descending ID.
A filename filter cannot use an index, so the query planner is free to assume that walking the primary key backwards will fill the page quickly. For users whose files have low IDs that assumption is wrong and the whole table gets scanned (observed: 74 s for one page of 12). For restricted users, "id + 0" prevents the primary key scan, so the matches are collected through the volume_id index and sorted afterwards.
at line 402
protected array
searchAnnotations(User $user, string $query, string $type)
Add image results to the search view.
at line 452
protected array
searchVideos(User $user, string $query, string $type)
Add video results to the search view.
at line 502
array
searchReports(User $user, string $query, string $type)
Add report results to the search view.