Improvements when searching long strings

This cuts down the php side overhead of searching long strings and adds
some profiling calls in the process.  The performance fixes are:
1.  Don't use a regex for balanced quote detection.  This would actually
crash long queries when they exhaused the pcre backtracking.
2.  Limit the number of character that can make up a query prefix.  This
cuts 500 millis off of a query for a big big string.

Bug: 55798
Change-Id: I50830441b0ba637c15a5aba028f0415ddbbdcd8b