doc/lib: Fix search criteria not splitting "complex" search strings correctly

refs #6630
This commit is contained in:
Eric Lippmann 2015-02-11 15:52:08 +01:00
parent 310201eb5b
commit 53af279ec2

View File

@ -32,20 +32,24 @@ class DocSearch
$this->input = $search = (string) $search; $this->input = $search = (string) $search;
$criteria = array(); $criteria = array();
if (preg_match_all('/"(?P<search>[^"]*)"/', $search, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) { if (preg_match_all('/"(?P<search>[^"]*)"/', $search, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) {
$unquoted = ''; $unquoted = array();
$offset = 0; $offset = 0;
foreach ($matches as $match) { foreach ($matches as $match) {
$fullMatch = $match[0]; $fullMatch = $match[0];
$searchMatch = $match['search']; $searchMatch = $match['search'];
$unquoted .= substr($search, $offset, $fullMatch[1] - $offset); $unquoted[] = substr($search, $offset, $fullMatch[1] - $offset);
$offset += $fullMatch[1] + strlen($fullMatch[0]); $offset = $fullMatch[1] + strlen($fullMatch[0]);
if (strlen($searchMatch[0]) > 0) { if (strlen($searchMatch[0]) > 0) {
$criteria[] = $searchMatch[0]; $criteria[] = $searchMatch[0];
} }
} }
$search = $unquoted . substr($search, $offset); $unquoted[] = substr($search, $offset);
$search = implode(' ', $unquoted);
} }
$this->search = array_unique(array_merge($criteria, array_filter(explode(' ', trim($search))))); $this->search = array_map(
'strtolower',
array_unique(array_merge($criteria, array_filter(explode(' ', trim($search)))))
);
} }
/** /**