From 9f8b04d1b0b8011540201313e9ac8c510f9f8685 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Robert=20Stojni=C4=87?= Date: Wed, 6 May 2009 21:05:52 +0000 Subject: [PATCH] Follow-up for r50207: mysql won't estimate total number of hits, so don't show it - copied from SpecialSearchOld more or less. --- includes/specials/SpecialSearch.php | 54 ++++++++++++++++++----------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/includes/specials/SpecialSearch.php b/includes/specials/SpecialSearch.php index d842465105..6346113907 100644 --- a/includes/specials/SpecialSearch.php +++ b/includes/specials/SpecialSearch.php @@ -208,19 +208,26 @@ class SpecialSearch { // Get number of results - $titleMatchesSQL = $titleMatches ? $titleMatches->numRows() : 0; - $textMatchesSQL = $textMatches ? $textMatches->numRows() : 0; + $titleMatchesNum = $titleMatches ? $titleMatches->numRows() : 0; + $textMatchesNum = $textMatches ? $textMatches->numRows() : 0; // Total initial query matches (possible false positives) - $numSQL = $titleMatchesSQL + $textMatchesSQL; + $num = $titleMatchesNum + $textMatchesNum; + // Get total actual results (after second filtering, if any) $numTitleMatches = $titleMatches && !is_null( $titleMatches->getTotalHits() ) ? - $titleMatches->getTotalHits() : $titleMatchesSQL; + $titleMatches->getTotalHits() : $titleMatchesNum; $numTextMatches = $textMatches && !is_null( $textMatches->getTotalHits() ) ? - $textMatches->getTotalHits() : $textMatchesSQL; - $totalRes = $numTitleMatches + $numTextMatches; - + $textMatches->getTotalHits() : $textMatchesNum; + + // get total number of results if backend can calculate it + $totalRes = 0; + if($titleMatches && !is_null( $titleMatches->getTotalHits() ) ) + $totalRes += $titleMatches->getTotalHits(); + if($textMatches && !is_null( $textMatches->getTotalHits() )) + $totalRes += $textMatches->getTotalHits(); + // show number of results and current offset - $wgOut->addHTML( $this->formHeader($term, $numSQL, $totalRes)); + $wgOut->addHTML( $this->formHeader($term, $num, $totalRes)); $wgOut->addHtml( "
" ); @@ -234,11 +241,11 @@ class SpecialSearch { } // prev/next links - if( $numSQL || $this->offset ) { + if( $num || $this->offset ) { $prevnext = wfViewPrevNext( $this->offset, $this->limit, SpecialPage::getTitleFor( 'Search' ), wfArrayToCGI( $this->powerSearchOptions(), array( 'search' => $term ) ), - max( $titleMatchesSQL, $textMatchesSQL ) < $this->limit + max( $titleMatchesNum, $textMatchesNum ) < $this->limit ); //$wgOut->addHTML( "

{$prevnext}

\n" ); wfRunHooks( 'SpecialSearchResults', array( $term, &$titleMatches, &$textMatches ) ); @@ -274,15 +281,15 @@ class SpecialSearch { $textMatches->free(); } - if( $totalRes === 0 ) { + if( $num === 0 ) { $wgOut->addWikiMsg( 'search-nonefound' ); } $wgOut->addHtml( "
" ); - if( $totalRes === 0 ) { + if( $num === 0 ) { $wgOut->addHTML( $this->searchAdvanced ? $this->powerSearchFocus() : $this->searchFocus() ); } - if( $numSQL || $this->offset ) { + if( $num || $this->offset ) { $wgOut->addHTML( "

{$prevnext}

\n" ); } wfProfileOut( __METHOD__ ); @@ -663,7 +670,7 @@ class SpecialSearch { ""; } - protected function formHeader( $term, $resultsShown, $totalRes ) { + protected function formHeader( $term, $resultsShown, $totalNum ) { global $wgContLang, $wgCanonicalNamespaceNames, $wgLang; $sep = '   '; @@ -726,14 +733,19 @@ class SpecialSearch { } $out .= Xml::closeElement('div') ; - if( $totalRes > 0){ - $countHtml = wfMsgExt('showingresultsheader', array( 'parseinline' ), - $this->offset+1, $this->offset+$resultsShown, $totalRes, $term, $resultsShown ); - $out .= "

{$countHtml}

\n" ; - } else{ + if ( $resultsShown > 0 ) { + if ( $totalNum > 0 ){ + $top = wfMsgExt('showingresultsheader', array( 'parseinline' ), + $this->offset+1, $this->offset+$resultsShown, $totalNum, $term, $resultsShown ); + } elseif ( $resultsShown >= $this->limit ) { + $top = wfShowingResults( $this->offset, $this->limit ); + } else { + $top = wfShowingResultsNum( $this->offset, $this->limit, $resultsShown ); + } + $out .= "

{$top}

\n"; + } else $out .= "

 

\n"; - } - + $out .= Xml::closeElement('div') ; return $out; -- 2.20.1