mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 14:00:56 +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:
parent
ffb074424d
commit
778b6bb483
1 changed files with 11 additions and 4 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue