X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fsearch%2FSearchSqlite.php;h=e52e4fe3919db9de3c15f38b8d11727f6ca6e4e2;hb=b23188b8adc15c477b1cecc138af2f35c95d82e8;hp=be5d10ac1093323783aba0a5ab0874a0d5d869d9;hpb=5280fbe9490b637a7230683f55bb7bec63bb2eb9;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/search/SearchSqlite.php b/includes/search/SearchSqlite.php index be5d10ac10..e52e4fe391 100644 --- a/includes/search/SearchSqlite.php +++ b/includes/search/SearchSqlite.php @@ -1,22 +1,22 @@ db = $db; + parent::__construct( $db ); } /** @@ -42,19 +45,14 @@ class SearchSqlite extends SearchEngine { * @return Boolean */ function fulltextSearchSupported() { - if ( self::$fulltextSupported === null ) { - self::$fulltextSupported = $this->db->selectField( - 'updatelog', - 'ul_key', - array( 'ul_key' => 'fts3' ), - __METHOD__ ) !== false; - } - return self::$fulltextSupported; + return $this->db->checkForEnabledSearch(); } - /** - * Parse the user's query and transform it into an SQL fragment which will + /** + * Parse the user's query and transform it into an SQL fragment which will * become part of a WHERE clause + * + * @return string */ function parseQuery( $filteredText, $fulltext ) { global $wgContLang; @@ -67,7 +65,7 @@ class SearchSqlite extends SearchEngine { $filteredText, $m, PREG_SET_ORDER ) ) { foreach( $m as $bits ) { @list( /* all */, $modifier, $term, $nonQuoted, $wildcard ) = $bits; - + if( $nonQuoted != '' ) { $term = $nonQuoted; $quote = ''; @@ -76,7 +74,9 @@ class SearchSqlite extends SearchEngine { $quote = '"'; } - if( $searchon !== '' ) $searchon .= ' '; + if( $searchon !== '' ) { + $searchon .= ' '; + } // Some languages such as Serbian store the input form in the search index, // so we may need to search for matches in multiple writing system variants. @@ -86,27 +86,27 @@ class SearchSqlite extends SearchEngine { } else { $variants = array( $term ); } - + // The low-level search index does some processing on input to work // around problems with minimum lengths and encoding in MySQL's // fulltext engine. // For Chinese this also inserts spaces between adjacent Han characters. $strippedVariants = array_map( - array( $wgContLang, 'stripForSearch' ), + array( $wgContLang, 'normalizeForSearch' ), $variants ); - + // Some languages such as Chinese force all variants to a canonical // form when stripping to the low-level search index, so to be sure // let's check our variants list for unique items after stripping. $strippedVariants = array_unique( $strippedVariants ); - + $searchon .= $modifier; if( count( $strippedVariants) > 1 ) $searchon .= '('; foreach( $strippedVariants as $stripped ) { if( $nonQuoted && strpos( $stripped, ' ' ) !== false ) { // Hack for Chinese: we need to toss in quotes for - // multiple-character phrases since stripForSearch() + // multiple-character phrases since normalizeForSearch() // added spaces between them to make word breaks. $stripped = '"' . trim( $stripped ) . '"'; } @@ -114,7 +114,7 @@ class SearchSqlite extends SearchEngine { } if( count( $strippedVariants) > 1 ) $searchon .= ')'; - + // Match individual terms or quoted phrase in result highlighting... // Note that variants will be introduced in a later stage for highlighting! $regexp = $this->regexTerm( $term, $wildcard ); @@ -129,10 +129,10 @@ class SearchSqlite extends SearchEngine { $field = $this->getIndexField( $fulltext ); return " $field MATCH '$searchon' "; } - + function regexTerm( $string, $wildcard ) { global $wgContLang; - + $regex = preg_quote( $string, '/' ); if( $wgContLang->hasWordBreaks() ) { if( $wildcard ) { @@ -172,7 +172,7 @@ class SearchSqlite extends SearchEngine { function searchTitle( $term ) { return $this->searchInternal( $term, false ); } - + protected function searchInternal( $term, $fulltext ) { global $wgCountTotalSearchHits, $wgContLang; @@ -182,7 +182,7 @@ class SearchSqlite extends SearchEngine { $filteredTerm = $this->filter( $wgContLang->lc( $term ) ); $resultSet = $this->db->query( $this->getQuery( $filteredTerm, $fulltext ) ); - + $total = null; if( $wgCountTotalSearchHits ) { $totalResult = $this->db->query( $this->getCountQuery( $filteredTerm, $fulltext ) ); @@ -192,7 +192,7 @@ class SearchSqlite extends SearchEngine { } $totalResult->free(); } - + return new SqliteSearchResultSet( $resultSet, $this->searchTerms, $total ); } @@ -226,37 +226,28 @@ class SearchSqlite extends SearchEngine { /** * Returns a query with limit for number of results set. - * @param $sql String: + * @param $sql String: * @return String */ function limitResult( $sql ) { return $this->db->limitResult( $sql, $this->limit, $this->offset ); } - /** - * Does not do anything for generic search engine - * subclasses may define this though - * @return String - */ - function queryRanking( $filteredTerm, $fulltext ) { - return ''; - } - /** * Construct the full SQL query to do the search. * The guts shoulds be constructed in queryMain() * @param $filteredTerm String * @param $fulltext Boolean + * @return String */ function getQuery( $filteredTerm, $fulltext ) { return $this->limitResult( $this->queryMain( $filteredTerm, $fulltext ) . ' ' . $this->queryRedirect() . ' ' . - $this->queryNamespaces() . ' ' . - $this->queryRanking( $filteredTerm, $fulltext ) + $this->queryNamespaces() ); } - + /** * Picks which field to index on, depending on what type of query. * @param $fulltext Boolean @@ -310,7 +301,7 @@ class SearchSqlite extends SearchEngine { $dbw = wfGetDB( DB_MASTER ); $dbw->delete( 'searchindex', array( 'rowid' => $id ), __METHOD__ ); - + $dbw->insert( 'searchindex', array( 'rowid' => $id, @@ -333,8 +324,8 @@ class SearchSqlite extends SearchEngine { $dbw = wfGetDB( DB_MASTER ); $dbw->update( 'searchindex', - array( 'rowid' => $id ), array( 'si_title' => $title ), + array( 'rowid' => $id ), __METHOD__ ); } } @@ -343,7 +334,7 @@ class SearchSqlite extends SearchEngine { * @ingroup Search */ class SqliteSearchResultSet extends SqlSearchResultSet { - function SqliteSearchResultSet( $resultSet, $terms, $totalHits=null ) { + function __construct( $resultSet, $terms, $totalHits=null ) { parent::__construct( $resultSet, $terms ); $this->mTotalHits = $totalHits; } @@ -351,4 +342,4 @@ class SqliteSearchResultSet extends SqlSearchResultSet { function getTotalHits() { return $this->mTotalHits; } -} \ No newline at end of file +}