class SearchController extends Controller

Traits

AuthorizesRequests
ValidatesRequests

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

bool
isAutomatedRequest(Request|null $request = null)

Determines if the request was done by an automated script (with API token or ajax).

index(Guard $auth, Request $request, Modules $modules)

Shows the search page.

array
searchLabelTrees(User $user, string $query, string $type, bool $includeFederatedSearch)

Add label tree results to the search view.

array
searchProjects(User $user, string $query, string $type, bool $includeFederatedSearch)

Add project results to the search view.

array
searchVolumes(User $user, string $query, string $type, bool $includeFederatedSearch)

Add volume results to the search view.

string
likePattern(string $query)

Turn a search term into a pattern for a substring match with (i)like.

bool
fileQueryTooShort(string $query)

Determine whether a search term is too short to be matched against filenames.

int
cappedResultCount(Builder $queryBuilder)

Count the results of a query, up to one more than MAX_RESULT_COUNT.

LengthAwarePaginator
paginateCapped(Builder $queryBuilder, int $count, int $perPage)

Paginate a query with a total that is capped at MAX_RESULT_COUNT.

LengthAwarePaginator
paginateFiles(Builder $queryBuilder, int $count, int $perPage, bool $restricted)

Paginate a file query, ordered by descending ID.

array
searchAnnotations(User $user, string $query, string $type)

Add image results to the search view.

array
searchVideos(User $user, string $query, string $type)

Add video results to the search view.

array
searchReports(User $user, string $query, string $type)

Add report results to the search view.

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).

Parameters

Request|null $request

Return Value

bool

at line 52
index(Guard $auth, Request $request, Modules $modules)

Shows the search page.

Parameters

Guard $auth
Request $request
Modules $modules

at line 100
protected array searchLabelTrees(User $user, string $query, string $type, bool $includeFederatedSearch)

Add label tree results to the search view.

Parameters

User $user
string $query
string $type
bool $includeFederatedSearch

Return Value

array

at line 168
protected array searchProjects(User $user, string $query, string $type, bool $includeFederatedSearch)

Add project results to the search view.

Parameters

User $user
string $query
string $type
bool $includeFederatedSearch

Return Value

array

at line 240
protected array searchVolumes(User $user, string $query, string $type, bool $includeFederatedSearch)

Add volume results to the search view.

Parameters

User $user
string $query
string $type
bool $includeFederatedSearch

Return Value

array

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.

Parameters

string $query

Return Value

string

at line 321
protected bool fileQueryTooShort(string $query)

Determine whether a search term is too short to be matched against filenames.

Parameters

string $query

Return Value

bool

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.

Parameters

Builder $queryBuilder

Return Value

int

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.

Parameters

Builder $queryBuilder
int $count

Result of cappedResultCount()

int $perPage

Return Value

LengthAwarePaginator

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.

Parameters

Builder $queryBuilder
int $count

Result of cappedResultCount()

int $perPage
bool $restricted

Whether the query is restricted to some volumes

Return Value

LengthAwarePaginator

at line 402
protected array searchAnnotations(User $user, string $query, string $type)

Add image results to the search view.

Parameters

User $user
string $query
string $type

Return Value

array

at line 452
protected array searchVideos(User $user, string $query, string $type)

Add video results to the search view.

Parameters

User $user
string $query
string $type

Return Value

array

at line 502
array searchReports(User $user, string $query, string $type)

Add report results to the search view.

Parameters

User $user
string $query
string $type

Return Value

array