Fixed issue 62, crash when searching in the issues.

The issue search is now correctly limiting the search to the issues.
dev
Loic d'Anterroches 2008-11-22 14:17:26 +01:00
parent d8870e6df0
commit c86cf6e5f1
2 changed files with 10 additions and 7 deletions

View File

@ -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);
}

View File

@ -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);