$wgSearchHighlightBoundaries = version_compare("5.1", PHP_VERSION, "<")? '[\p{Z}\p{P}\p{C}]'
: '[ ,.;:!?~!@#$%\^&*\(\)+=\-\\|\[\]"\'<>\n\r\/{}]'; // PHP 5.0 workaround
+/**
+ * Set to true to have the default MySQL search engine count total
+ * search matches to present in the Special:Search UI.
+ *
+ * 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.
+ */
+$wgSearchMySQLTotalHits = false;
+
/**
* Template for OpenSearch suggestions, defaults to API action=opensearch
*
* @return MySQLSearchResultSet
*/
function searchText( $term ) {
- $resultSet = $this->db->resultObject( $this->db->query( $this->getQuery( $this->filter( $term ), true ) ) );
- return new MySQLSearchResultSet( $resultSet, $this->searchTerms );
+ global $wgSearchMySQLTotalHits;
+
+ $filteredTerm = $this->filter( $term );
+ $resultSet = $this->db->query( $this->getQuery( $filteredTerm, true ) );
+
+ $total = null;
+ if( $wgSearchMySQLTotalHits ) {
+ $totalResult = $this->db->query( $this->getCountQuery( $filteredTerm, true ) );
+ $row = $totalResult->fetchObject();
+ if( $row ) {
+ $total = $row->c;
+ }
+ $totalResult->free();
+ }
+
+ return new MySQLSearchResultSet( $resultSet, $this->searchTerms, $total );
}
/**
$this->queryRanking( $filteredTerm, $fulltext ) . ' ' .
$this->queryLimit();
}
-
-
+
/**
* Picks which field to index on, depending on what type of query.
* @param $fulltext Boolean
'WHERE page_id=si_page AND ' . $match;
}
+ function getCountQuery( $filteredTerm, $fulltext ) {
+ $match = $this->parseQuery( $filteredTerm, $fulltext );
+ $page = $this->db->tableName( 'page' );
+ $searchindex = $this->db->tableName( 'searchindex' );
+ return "SELECT COUNT(*) AS c " .
+ "FROM $page,$searchindex " .
+ 'WHERE page_id=si_page AND ' . $match .
+ $this->queryRedirect() . ' ' .
+ $this->queryNamespaces();
+ }
+
/**
* Create or update the search index record for the given page.
* Title and text should be pre-processed.
* @ingroup Search
*/
class MySQLSearchResultSet extends SearchResultSet {
- function MySQLSearchResultSet( $resultSet, $terms ) {
+ function MySQLSearchResultSet( $resultSet, $terms, $totalHits=null ) {
$this->mResultSet = $resultSet;
$this->mTerms = $terms;
+ $this->mTotalHits = $totalHits;
}
function termMatches() {
function free() {
$this->mResultSet->free();
}
+
+
+ function getTotalHits() {
+ return $this->mTotalHits;
+ }
}
\ No newline at end of file