From 4903efa4a3064aa090d1511a73b1cbe6b0a24861 Mon Sep 17 00:00:00 2001 From: Domas Mituzas Date: Sat, 11 Dec 2004 09:55:56 +0000 Subject: [PATCH] * move away SQL guts from parseQuery to queryMain * add ranking --- includes/SearchTsearch2.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/includes/SearchTsearch2.php b/includes/SearchTsearch2.php index 4db9dfbdeb..db303a6777 100644 --- a/includes/SearchTsearch2.php +++ b/includes/SearchTsearch2.php @@ -31,6 +31,7 @@ class SearchTsearch2 extends SearchEngine { function SearchTsearch2( &$db ) { $this->db =& $db; $this->db->setSchema('tsearch'); + $this->mRanking = true; } function getIndexField( $fulltext ) { @@ -68,17 +69,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 ) { -- 2.20.1