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/notestorage.php | |
| parent | 16bb2f544c636425ed9e6bff90654b8fa3c0f2e3 (diff) | |
| download | grauphel-724cb02e3e7a98e58387e80c9360b420a09b3607.tar.gz grauphel-724cb02e3e7a98e58387e80c9360b420a09b3607.zip | |
new search query parser; support for NOT
Diffstat (limited to 'lib/notestorage.php')
| -rw-r--r-- | lib/notestorage.php | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/lib/notestorage.php b/lib/notestorage.php index 67baa20..6802e2f 100644 --- a/lib/notestorage.php +++ b/lib/notestorage.php @@ -274,26 +274,39 @@ class NoteStorage /** * Search for a note * - * @param string $keywords AND-concatenated query strings + * @param array $keywords arrays of query strings within keys AND and NOT * * @return array Database rows with note_guid and note_title */ - public function search($keywords) + public function search($keywordGroups) { - $sqlWhere = ' AND (note_title LIKE ? OR note_tags LIKE ? OR note_content LIKE ?)'; + if (!isset($keywordGroups['AND'])) { + $keywordGroups['AND'] = array(); + } + if (!isset($keywordGroups['NOT'])) { + $keywordGroups['NOT'] = array(); + } + + $sqlTplAnd = ' AND (note_title LIKE ? OR note_tags LIKE ? OR note_content LIKE ?)'; + $sqlTplNot = ' AND NOT (note_title LIKE ? OR note_tags LIKE ? OR note_content LIKE ?)'; $arData = array( $this->username ); - foreach ($keywords as $keyword) { - $arData[] = '%' . $keyword . '%';//title - $arData[] = '%' . $keyword . '%';//tags - $arData[] = '%' . $keyword . '%';//content + foreach (array('AND', 'NOT') as $group) { + $keywords = $keywordGroups[$group]; + foreach ($keywords as $keyword) { + $arData[] = '%' . $keyword . '%';//title + $arData[] = '%' . $keyword . '%';//tags + $arData[] = '%' . $keyword . '%';//content + } } + $result = \OC_DB::executeAudited( 'SELECT `note_guid`, `note_title`' . ' FROM `*PREFIX*grauphel_notes`' . ' WHERE note_user = ?' - . str_repeat($sqlWhere, count($keywords)), + . str_repeat($sqlTplAnd, count($keywordGroups['AND'])) + . str_repeat($sqlTplNot, count($keywordGroups['NOT'])), $arData ); |
