2012-01-29 19:32:33 +01:00
|
|
|
<?php
|
2014-11-25 22:43:48 +01:00
|
|
|
|
2012-01-29 19:32:33 +01:00
|
|
|
/**
|
|
|
|
* ownCloud - bookmarks plugin
|
|
|
|
*
|
|
|
|
* @author David Iwanowitsch
|
|
|
|
* @copyright 2012 David Iwanowitsch <david at unclouded dot de>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-11-25 22:43:48 +01:00
|
|
|
namespace OCA\Bookmarks\Controller\Lib;
|
|
|
|
|
|
|
|
use \OCA\Bookmarks\Controller\Lib\Bookmarks;
|
|
|
|
|
|
|
|
class Search extends \OCP\Search\Provider{
|
|
|
|
|
2012-09-07 15:21:03 +02:00
|
|
|
function search($query) {
|
2014-11-25 22:43:48 +01:00
|
|
|
$results = array();
|
2012-07-02 12:41:40 +02:00
|
|
|
|
2014-11-25 22:43:48 +01:00
|
|
|
if (substr_count($query, ' ') > 0) {
|
2012-07-02 12:41:40 +02:00
|
|
|
$search_words = explode(' ', $query);
|
2014-11-25 22:43:48 +01:00
|
|
|
} else {
|
2012-07-02 12:41:40 +02:00
|
|
|
$search_words = $query;
|
2012-01-29 19:32:33 +01:00
|
|
|
}
|
2013-10-12 18:09:49 +02:00
|
|
|
|
2014-11-25 22:43:48 +01:00
|
|
|
$db = \OC::$server->getDb();
|
|
|
|
$user = \OCP\User::getUser();
|
|
|
|
|
|
|
|
$bookmarks = Bookmarks::findBookmarks($user, $db, 0, 'id', $search_words, false);
|
|
|
|
$l = new \OC_l10n('bookmarks'); //resulttype can't be localized, javascript relies on that type
|
|
|
|
foreach ($bookmarks as $bookmark) {
|
|
|
|
$results[] = new \OC_Search_Result($bookmark['title'], $bookmark['title'], $bookmark['url'], (string) $l->t('Bookm.'));
|
2012-01-29 19:32:33 +01:00
|
|
|
}
|
2013-10-12 18:09:49 +02:00
|
|
|
|
2012-01-29 19:32:33 +01:00
|
|
|
return $results;
|
|
|
|
}
|
2014-11-25 22:43:48 +01:00
|
|
|
|
2012-01-29 19:32:33 +01:00
|
|
|
}
|