1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 05:50:55 +01:00

Support operators in highlighting search results

Summary: Supports ", +, |, * and -.

Test Plan:
Search for `"Quoted search"`.
Search for `Phabric*`.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran

Differential Revision: https://secure.phabricator.com/D2076
This commit is contained in:
vrana 2012-04-02 13:33:36 -07:00
parent ffb074424d
commit 778b6bb483

View file

@ -106,19 +106,26 @@ final class PhabricatorSearchResultView extends AphrontView {
$query = $this->query->getQuery();
$query = preg_split("/\s+/", $query);
$quoted_regexp = '/"([^"]*)"/';
$matches = array(1 => array());
preg_match_all($quoted_regexp, $query, $matches);
$quoted_queries = $matches[1];
$query = preg_replace($quoted_regexp, '', $query);
$query = preg_split('/\s+[+|]?/', $query);
$query = array_filter($query);
$query = array_merge($query, $quoted_queries);
$str = phutil_escape_html($str);
foreach ($query as $word) {
$word = phutil_escape_html($word);
$word = preg_quote($word, '/');
$word = preg_replace('/\\\\\*$/', '\w*', $word);
$str = preg_replace(
'/(?:^|\b)('.preg_quote($word, '/').')(?:\b|$)/i',
'/(?:^|\b)('.$word.')(?:\b|$)/i',
'<strong>\1</strong>',
$str);
}
return $str;
}
}