mirror of
https://github.com/owncloud/bookmarks.git
synced 2025-02-18 15:54:28 +01:00
Re enable the search provider for Bookmarks
This commit is contained in:
parent
a1d17218f0
commit
94160cb421
@ -57,12 +57,14 @@ class OC_Bookmarks_Bookmarks{
|
||||
* @brief Finds all bookmarks, matching the filter
|
||||
* @param offset result offset
|
||||
* @param sqlSortColumn sort result with this column
|
||||
* @param filter can be: empty -> no filter, a string -> filter this, a string array -> filter for all strings
|
||||
* @param filters can be: empty -> no filter, a string -> filter this, a string array -> filter for all strings
|
||||
* @param filterTagOnly if true, filter affects only tags, else filter affects url, title and tags
|
||||
* @return void
|
||||
*/
|
||||
public static function findBookmarks($offset, $sqlSortColumn, $filter, $filterTagOnly){
|
||||
public static function findBookmarks($offset, $sqlSortColumn, $filters, $filterTagOnly){
|
||||
$CONFIG_DBTYPE = OCP\Config::getSystemValue( 'dbtype', 'sqlite' );
|
||||
if(is_string($filters)) $filters = array($filters);
|
||||
|
||||
$limit = 10;
|
||||
$params=array(OCP\USER::getUser());
|
||||
|
||||
@ -77,10 +79,13 @@ class OC_Bookmarks_Bookmarks{
|
||||
WHERE user_id = ? ";
|
||||
|
||||
if($filterTagOnly) {
|
||||
if(is_string($filter)) $filter = array($filter);
|
||||
|
||||
$sql .= str_repeat(" AND exists (select id from *PREFIX*bookmarks_tags t2 where t2.bookmark_id = b.id and tag = ?) ", count($filter));
|
||||
$params = array_merge($params, $filter);
|
||||
$sql .= str_repeat(" AND exists (select id from *PREFIX*bookmarks_tags t2 where t2.bookmark_id = b.id and tag = ?) ", count($filters));
|
||||
$params = array_merge($params, $filters);
|
||||
} else {
|
||||
foreach($filters as $filter) {
|
||||
$sql .= ' AND lower(url || title || description || tags ) like ? ';
|
||||
$params[] = '%' . strtolower($filter) . '%';
|
||||
}
|
||||
}
|
||||
$sql .= " ORDER BY ".$sqlSortColumn." DESC
|
||||
LIMIT $limit
|
||||
@ -295,4 +300,13 @@ class OC_Bookmarks_Bookmarks{
|
||||
$query->execute($params);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple function to search for bookmark. call findBookmarks
|
||||
* @param array $search_words Set of words to look for in bookmars fields
|
||||
* @return array An Array of bookmarks
|
||||
**/
|
||||
public static function searchBookmarks($search_words) {
|
||||
return self::findBookmarks(0, 'id', $search_words, false);
|
||||
}
|
||||
}
|
||||
|
@ -23,19 +23,16 @@
|
||||
class OC_Search_Provider_Bookmarks extends OC_Search_Provider{
|
||||
function search($query){
|
||||
$results=array();
|
||||
|
||||
$offset = 0;
|
||||
$sqlSortColumn = 'id';
|
||||
|
||||
$searchquery=array();
|
||||
|
||||
$search_words=array();
|
||||
if(substr_count($query, ' ') > 0){
|
||||
$searchquery = explode(' ', $query);
|
||||
$search_words = explode(' ', $query);
|
||||
}else{
|
||||
$searchquery = $query;
|
||||
$search_words = $query;
|
||||
}
|
||||
|
||||
// OCP\Util::writeLog('bookmarks', 'search ' .$query ,OCP\Util::DEBUG);
|
||||
$bookmarks = OC_Bookmarks_Bookmarks::findBookmarks($offset, $sqlSortColumn, $searchquery, false);
|
||||
$bookmarks = OC_Bookmarks_Bookmarks::searchBookmarks($search_words);
|
||||
// OCP\Util::writeLog('bookmarks', 'found ' .count($bookmarks) ,OCP\Util::DEBUG);
|
||||
//$l = new OC_l10n('bookmarks'); //resulttype can't be localized, javascript relies on that type
|
||||
foreach($bookmarks as $bookmark){
|
||||
|
Loading…
x
Reference in New Issue
Block a user