X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2FSearchTsearch2.php;h=655a48e514fa0d35ae9f150f9ca014fc12c837a0;hb=f7de33dc2cd3463fc8f57b14f0e419f797a9329a;hp=4db9dfbdeb0a674a1152ecc0ce62e0fc31a63b76;hpb=77a5b28598adff469c26db866c417a0a936a9f37;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/SearchTsearch2.php b/includes/SearchTsearch2.php index 4db9dfbdeb..655a48e514 100644 --- a/includes/SearchTsearch2.php +++ b/includes/SearchTsearch2.php @@ -23,14 +23,21 @@ * @subpackage Search */ +/** */ require_once( 'SearchEngine.php' ); +/** + * @todo document + * @package MediaWiki + * @subpackage Search + */ class SearchTsearch2 extends SearchEngine { var $strictMatching = false; function SearchTsearch2( &$db ) { $this->db =& $db; $this->db->setSchema('tsearch'); + $this->mRanking = true; } function getIndexField( $fulltext ) { @@ -68,17 +75,28 @@ class SearchTsearch2 extends SearchEngine { $searchon = preg_replace('/(\s+)/','&',$searchon); $searchon = $this->db->strencode( $searchon ); + return $searchon; + } + + function queryRanking($filteredTerm, $fulltext) { $field = $this->getIndexField( $fulltext ); - return " $field @@ to_tsquery('$searchon')"; + $searchon = $this->parseQuery($filteredTerm,$fulltext); + if ($this->mRanking) + return " ORDER BY rank($field,to_tsquery('$searchon')) DESC"; + else + return ""; } + function queryMain( $filteredTerm, $fulltext ) { $match = $this->parseQuery( $filteredTerm, $fulltext ); + $field = $this->getIndexField( $fulltext ); $cur = $this->db->tableName( 'cur' ); $searchindex = $this->db->tableName( 'searchindex' ); return 'SELECT cur_id, cur_namespace, cur_title, cur_text ' . "FROM $cur,$searchindex " . - 'WHERE cur_id=si_page AND ' . $match; + 'WHERE cur_id=si_page AND ' . + " $field @@ to_tsquery ('$match') " ; } function update( $id, $title, $text ) {