diff options
| author | Christian Weiske <cweiske@cweiske.de> | 2014-10-27 18:26:53 +0100 |
|---|---|---|
| committer | Christian Weiske <cweiske@cweiske.de> | 2014-10-27 18:26:53 +0100 |
| commit | 724cb02e3e7a98e58387e80c9360b420a09b3607 (patch) | |
| tree | 22585558d92d90624c666f81707c8c22a661a475 /lib/search/provider.php | |
| parent | 16bb2f544c636425ed9e6bff90654b8fa3c0f2e3 (diff) | |
| download | grauphel-724cb02e3e7a98e58387e80c9360b420a09b3607.tar.gz grauphel-724cb02e3e7a98e58387e80c9360b420a09b3607.zip | |
new search query parser; support for NOT
Diffstat (limited to 'lib/search/provider.php')
| -rw-r--r-- | lib/search/provider.php | 47 |
1 files changed, 3 insertions, 44 deletions
diff --git a/lib/search/provider.php b/lib/search/provider.php index 8b867bb..b395778 100644 --- a/lib/search/provider.php +++ b/lib/search/provider.php @@ -40,7 +40,9 @@ class Provider extends \OCP\Search\Provider $urlGen = \OC::$server->getURLGenerator(); $notes = new NoteStorage($urlGen); $notes->setUsername(\OC_User::getUser()); - $rows = $notes->search($this->parseQuery($query)); + + $qp = new QueryParser(); + $rows = $notes->search($qp->parse($query)); $results = array(); foreach ($rows as $row) { @@ -54,48 +56,5 @@ class Provider extends \OCP\Search\Provider } return $results; } - - /** - * Splits the user's query string up into several keywords - * that all have to be within the note (AND). - * - * Split by space, quotes are supported: - * - foo bar - * -> searches for notes that contain "foo" and "bar" - * - foo "bar baz" - * -> searches for notes that contain "foo" and "bar baz" - * - * @param string $query User-given query string - * - * @return array Array of keywords - */ - protected function parseQuery($query) - { - $keywords = explode(' ', $query); - array_map('trim', $keywords); - $loop = 0; - do { - $changed = false; - foreach ($keywords as $key => &$keyword) { - if ($keyword{0} != '"') { - continue; - } - if (substr($keyword, -1) == '"') { - // "foo" - $keyword = trim($keyword, '"'); - continue; - } - if ($key < count($keywords) -1) { - //not at the end - $keyword .= ' ' . $keywords[$key + 1]; - unset($keywords[$key + 1]); - $changed = true; - break; - } - } - } while ($changed && ++$loop < 20); - - return $keywords; - } } ?> |
