--- bookmarkservice.php.orig 2006-01-19 21:33:31.000000000 +0100 +++ bookmarkservice.php 2006-01-20 22:07:54.000000000 +0100 @@ -233,12 +233,12 @@ $tags[$i] = trim($tags[$i]); // Set up the SQL query. - $query_1 = 'SELECT '; + $query_1 = 'SELECT DISTINCT '; if (SQL_LAYER == 'mysql4') $query_1 .= 'SQL_CALC_FOUND_ROWS '; $query_1 .= 'scBookmarks.*, '. $userservice->getTableName() .'.'. $userservice->getFieldName('username'); - $query_2 = ' FROM scBookmarks, '. $userservice->getTableName(); + $query_2 = ' FROM '. $userservice->getTableName() .', scBookmarks' ; if (is_null($watched)) { if (is_null($user)) @@ -287,8 +287,29 @@ } // Search terms - if ($terms) - $query_4 .= " AND (scBookmarks.bTitle LIKE '%".$this->db->sql_escape($terms)."%' OR scBookmarks.bDescription LIKE '%".$this->db->sql_escape($terms)."%')"; + if ($terms){ + // multiple search terms okay + $aTerms = explode(' ',$terms); + $aTerms = array_map('trim',$aTerms); + + // search terms in tags as well when none given + if(!count($tags)){ + $query_2 .= " LEFT JOIN scCategories ON scBookmarks.bId = scCategories.bId"; + $dotags = true; + }else{ + $dotags = false; + } + + $query_4 = ''; + for ($i = 0; $i < count($aTerms); $i ++) { + $query_4 .= " AND (scBookmarks.bTitle LIKE '%".$this->db->sql_escape($aTerms[$i])."%'"; + $query_4 .= " OR scBookmarks.bDescription LIKE '%".$this->db->sql_escape($aTerms[$i])."%'"; + if($dotags){ + $query_4 .= " OR scCategories.category = '".$this->db->sql_escape($aTerms[$i])."'"; + } + $query_4 .= ')'; + } + } // Start and end dates if ($startdate) @@ -353,4 +374,4 @@ return $this->db->sql_fetchfield(0, 0) - 1; } } -?> \ No newline at end of file +?>