From 8c953947ff2e19a1e15c33e29bb0b410ce56d343 Mon Sep 17 00:00:00 2001 From: Brian Wolff Date: Tue, 8 Jul 2014 03:35:56 -0300 Subject: [PATCH] rm $wgCountTotalSearchHits. It was broken. If $wgCountTotalSearchHits was set to true, then the total number of hits returned was zero, which caused Special:Search to display no results. I'm opting to remove the feature (although I don't have any strong opinions about removal vs changing Special:Search), since if someone both cares about performance and has a wiki where its big enough to matter, they are going to need to use Cirrus anyways. Change-Id: I1c3b908ae5423ce3dfbdc22b1a68dd81a85698aa --- RELEASE-NOTES-1.24 | 3 +++ includes/DefaultSettings.php | 12 ------------ includes/search/SearchMySQL.php | 24 ++++++++++-------------- includes/search/SearchResultSet.php | 7 ++++++- includes/search/SearchSqlite.php | 14 ++++++-------- 5 files changed, 25 insertions(+), 35 deletions(-) diff --git a/RELEASE-NOTES-1.24 b/RELEASE-NOTES-1.24 index 9c605d04e3..f684822611 100644 --- a/RELEASE-NOTES-1.24 +++ b/RELEASE-NOTES-1.24 @@ -27,6 +27,9 @@ production. prefixes (i.e. turned into interlanguage links when $wgInterwikiMagic is set to true). * $wgParserTestRemote has been removed. +* $wgCountTotalSearchHits has been removed. If you're concerned about efficiency + of search, you should use something like CirrusSearch instead of built in + search. === New features in 1.24 === * Added a new hook, "WhatLinksHereProps", to allow extensions to annotate diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 11196ae109..fb73eb3a0d 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -5278,18 +5278,6 @@ $wgAdvancedSearchHighlighting = false; */ $wgSearchHighlightBoundaries = '[\p{Z}\p{P}\p{C}]'; -/** - * Set to true to have the search engine count total - * search matches to present in the Special:Search UI. - * Not supported by every search engine shipped with MW. - * - * This could however be slow on larger wikis, and is pretty flaky - * with the current title vs content split. Recommend avoiding until - * that's been worked out cleanly; but this may aid in testing the - * search UI and API to confirm that the result count works. - */ -$wgCountTotalSearchHits = false; - /** * Template for OpenSearch suggestions, defaults to API action=opensearch * diff --git a/includes/search/SearchMySQL.php b/includes/search/SearchMySQL.php index 8ff2640c57..581d8bcaa4 100644 --- a/includes/search/SearchMySQL.php +++ b/includes/search/SearchMySQL.php @@ -174,8 +174,6 @@ class SearchMySQL extends SearchDatabase { } protected function searchInternal( $term, $fulltext ) { - global $wgCountTotalSearchHits; - // This seems out of place, why is this called with empty term? if ( trim( $term ) === '' ) { return null; @@ -189,19 +187,17 @@ class SearchMySQL extends SearchDatabase { ); $total = null; - if ( $wgCountTotalSearchHits ) { - $query = $this->getCountQuery( $filteredTerm, $fulltext ); - $totalResult = $this->db->select( - $query['tables'], $query['fields'], $query['conds'], - __METHOD__, $query['options'], $query['joins'] - ); - - $row = $totalResult->fetchObject(); - if ( $row ) { - $total = intval( $row->c ); - } - $totalResult->free(); + $query = $this->getCountQuery( $filteredTerm, $fulltext ); + $totalResult = $this->db->select( + $query['tables'], $query['fields'], $query['conds'], + __METHOD__, $query['options'], $query['joins'] + ); + + $row = $totalResult->fetchObject(); + if ( $row ) { + $total = intval( $row->c ); } + $totalResult->free(); return new SqlSearchResultSet( $resultSet, $this->searchTerms, $total ); } diff --git a/includes/search/SearchResultSet.php b/includes/search/SearchResultSet.php index f430dd0926..698f93c287 100644 --- a/includes/search/SearchResultSet.php +++ b/includes/search/SearchResultSet.php @@ -173,7 +173,12 @@ class SqlSearchResultSet extends SearchResultSet { } function getTotalHits() { - return $this->totalHits; + if ( !is_null( $this->totalHits ) ) { + return $this->totalHits; + } else { + // Special:Search expects a number here. + return $this->numRows(); + } } } diff --git a/includes/search/SearchSqlite.php b/includes/search/SearchSqlite.php index 8e820f373d..05d5ca0f0d 100644 --- a/includes/search/SearchSqlite.php +++ b/includes/search/SearchSqlite.php @@ -164,7 +164,7 @@ class SearchSqlite extends SearchDatabase { } protected function searchInternal( $term, $fulltext ) { - global $wgCountTotalSearchHits, $wgContLang; + global $wgContLang; if ( !$this->fulltextSearchSupported() ) { return null; @@ -174,14 +174,12 @@ class SearchSqlite extends SearchDatabase { $resultSet = $this->db->query( $this->getQuery( $filteredTerm, $fulltext ) ); $total = null; - if ( $wgCountTotalSearchHits ) { - $totalResult = $this->db->query( $this->getCountQuery( $filteredTerm, $fulltext ) ); - $row = $totalResult->fetchObject(); - if ( $row ) { - $total = intval( $row->c ); - } - $totalResult->free(); + $totalResult = $this->db->query( $this->getCountQuery( $filteredTerm, $fulltext ) ); + $row = $totalResult->fetchObject(); + if ( $row ) { + $total = intval( $row->c ); } + $totalResult->free(); return new SqlSearchResultSet( $resultSet, $this->searchTerms, $total ); } -- 2.20.1