From 2b5ff5d48b4ec80e0e0e18188689edefaeefe91d Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 24 Oct 2014 08:54:35 +0200 Subject: Implement note search --- lib/search/provider.php | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 lib/search/provider.php (limited to 'lib/search/provider.php') diff --git a/lib/search/provider.php b/lib/search/provider.php new file mode 100644 index 0000000..5b42bb7 --- /dev/null +++ b/lib/search/provider.php @@ -0,0 +1,58 @@ + + * @copyright 2014 Christian Weiske + * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3 + * @link http://cweiske.de/grauphel.htm + */ +namespace OCA\Grauphel\Search; + +use \OCA\Grauphel\Lib\NoteStorage; + +/** + * Hook for the site-wide owncloud search. + * + * @category Tools + * @package Grauphel + * @author Christian Weiske + * @copyright 2014 Christian Weiske + * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3 + * @version Release: @package_version@ + * @link http://cweiske.de/grauphel.htm + */ +class Provider extends \OCP\Search\Provider +{ + /** + * Search for notes + * + * @param string $query + * + * @return array list of \OCA\Grauphel\Search\Note + */ + public function search($query) + { + $urlGen = \OC::$server->getURLGenerator(); + $notes = new NoteStorage($urlGen); + $notes->setUsername(\OC_User::getUser()); + $rows = $notes->search($query); + + $results = array(); + foreach ($rows as $row) { + $res = new Note(); + $res->id = $row['note_guid']; + $res->name = $row['note_title']; + $res->link = $urlGen->linkToRoute( + 'grauphel.gui.note', array('guid' => $row['note_guid']) + ); + $results[] = $res; + } + return $results; + } +} +?> -- cgit v1.2.3