Currently the Query text field in Search allows an arbitrary number of tokens (characters divided by whitespace) up to a total of 1024 bytes. This feels excessive and could decrease performance in public Phorge instances.
This patch mitigates T15831 by not allowing a huge amount of search tokens which would trigger a "Too many tables" MariaDB error (plus it displays a clearer error message).
This only applies to parsing the Query string and not to typeahead fields or such.
The threshold of 16 is entirely arbitrary and welcomes excessive bikeshedding before accepting this patch.
(For better understanding, note that a Query term like foo AND (bar OR meouw) counts as 5 tokens, not 3 tokens.)
See also rP72cb3d3c84905c0d75074e4ecf74c493e3a2d527 (though that older commit introduced analyzing search tokens while this very change just drops the query with an error, as I personally interpret too many search tokens as PEBKAC).
This patch should also decrease the likeliness of facing https://secure.phabricator.com/T12993 and https://phabricator.wikimedia.org/T383068 (extremely long running queries) leading to decreased DB performance.
Closes T15831