class ShowOpenSearchSuggestionsController implements RequestHandlerInterface

Discussions a browser suggests as someone types in its search box, in the OpenSearch suggestions format: the query, then titles, descriptions and addresses. Only discussions the visitor can see are suggested.

Titles are matched on the start of their words, so a word is completed as it is typed. The forum's search matches whole words on MySQL, MariaDB and PostgreSQL, so it can't suggest anything until a word is finished. A word starts after anything that isn't a letter or digit, as in "[Solved]" or "carbon-fibre", which LIKE can't express. The database finds words at the start of a title or after a space; when they are too few, it finds titles that contain the words, and where the words start is checked here.

Constants

MIN_LENGTH

LIMIT

MAX_WORDS

Words of the query that are matched; the rest are ignored, so a long query can't build an unbounded number of conditions.

CANDIDATES

Recently active titles containing the words that are checked for words starting after punctuation, when too few start after a space. Older matches after punctuation are missed when this many titles only contain the words inside other words.

Methods

__construct( SlugManager $slugs, UrlGenerator $url)

No description

ResponseInterface
handle( ServerRequestInterface $request)

No description

matching( User $actor, array $words, array $patterns)

Visible discussions whose title has every word in one of the patterns, most recently active first.

bool
startsWords(string $title, array $words)

Whether every word starts a word of the title, ignoring case and accents as MySQL, MariaDB and PostgreSQL do when finding the titles.

string
withoutAccents(string $text)

No description

array
cases(string $word)

The word as typed and, when it has letters beyond ASCII, as it would be written in lower, upper and title case: SQLite's LIKE ignores the case of ASCII letters only.

Details

__construct( SlugManager $slugs, UrlGenerator $url)

Parameters

SlugManager $slugs
UrlGenerator $url

ResponseInterface handle( ServerRequestInterface $request)

Parameters

ServerRequestInterface $request

Return Value

ResponseInterface

protected Builder matching( User $actor, array $words, array $patterns)

Visible discussions whose title has every word in one of the patterns, most recently active first.

Parameters

User $actor
array $words
array $patterns sprintf() patterns for LIKE, given the word

Return Value

Builder

protected bool startsWords(string $title, array $words)

Whether every word starts a word of the title, ignoring case and accents as MySQL, MariaDB and PostgreSQL do when finding the titles.

Parameters

string $title
array $words

Return Value

bool

protected string withoutAccents(string $text)

Parameters

string $text

Return Value

string

protected array cases(string $word)

The word as typed and, when it has letters beyond ASCII, as it would be written in lower, upper and title case: SQLite's LIKE ignores the case of ASCII letters only.

Parameters

string $word

Return Value

array