From c86cf6e5f1bc94aa457fe9d5eaa61eb95cb8f9b0 Mon Sep 17 00:00:00 2001 From: Loic d'Anterroches Date: Sat, 22 Nov 2008 14:17:26 +0100 Subject: [PATCH] Fixed issue 62, crash when searching in the issues. The issue search is now correctly limiting the search to the issues. --- src/IDF/Search.php | 15 +++++++++------ src/IDF/Views/Issue.php | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/IDF/Search.php b/src/IDF/Search.php index d32bd39..d36588e 100644 --- a/src/IDF/Search.php +++ b/src/IDF/Search.php @@ -43,10 +43,11 @@ class IDF_Search extends Pluf_Search * * @param string Query string. * @param int Project id to limit the results (null) - * @param string Stemmer class. - * @return array Results. + * @param string Model class (null) + * @param string Stemmer class ('Pluf_Text_Stemmer_Porter') + * @return array Results */ - public static function mySearch($query, $project=null, $stemmer='Pluf_Text_Stemmer_Porter') + public static function mySearch($query, $project=null, $model=null, $stemmer='Pluf_Text_Stemmer_Porter') { $query = Pluf_Text::cleanString(html_entity_decode($query, ENT_QUOTES, 'UTF-8')); $words = Pluf_Text::tokenize($query); @@ -61,7 +62,7 @@ class IDF_Search extends Pluf_Search if (in_array(null, $word_ids)) { return array(); } - return self::mySearchDocuments($word_ids, $project); + return self::mySearchDocuments($word_ids, $project, $model); } /** @@ -72,9 +73,10 @@ class IDF_Search extends Pluf_Search * * @param array Ids. * @param IDF_Project Project to limit the search. + * @param string Model class to limit the search. * @return array Sorted by score, returns model_class, model_id and score. */ - public static function mySearchDocuments($wids, $project) + public static function mySearchDocuments($wids, $project, $model) { $db =& Pluf::db(); $gocc = new IDF_Search_Occ(); @@ -83,7 +85,8 @@ class IDF_Search extends Pluf_Search $where[] = $db->qn('word').'='.(int)$id; } $prj = (is_null($project)) ? '' : ' AND project='.(int)$project->id; - $select = 'SELECT model_class, model_id, SUM(pondocc) AS score FROM '.$gocc->getSqlTable().' WHERE '.implode(' OR ', $where).$prj.' GROUP BY model_class, model_id HAVING COUNT(*)='.count($wids).' ORDER BY score DESC'; + $md = (is_null($model)) ? '' : ' AND model_class='.$db->esc($model); + $select = 'SELECT model_class, model_id, SUM(pondocc) AS score FROM '.$gocc->getSqlTable().' WHERE '.implode(' OR ', $where).$prj.$md.' GROUP BY model_class, model_id HAVING COUNT(*)='.count($wids).' ORDER BY score DESC'; return $db->select($select); } diff --git a/src/IDF/Views/Issue.php b/src/IDF/Views/Issue.php index 8a7b783..03f3fec 100644 --- a/src/IDF/Views/Issue.php +++ b/src/IDF/Views/Issue.php @@ -198,7 +198,7 @@ class IDF_Views_Issue } $q = $request->REQUEST['q']; $title = sprintf(__('Search Issues - %s'), Pluf_esc($q)); - $issues = new Pluf_Search_ResultSet(IDF_Search::mySearch($q, $prj)); + $issues = new Pluf_Search_ResultSet(IDF_Search::mySearch($q, $prj, 'IDF_Issue')); if (count($issues) > 100) { // no more than 100 results as we do not care $issues->results = array_slice($issues->results, 0, 100);