Merge "Less false positives for MEDIATYPE_VIDEO"
[lhc/web/wiklou.git] / includes / search / SearchSqlite.php
index ebff68e..8e820f3 100644 (file)
@@ -28,7 +28,7 @@
 class SearchSqlite extends SearchDatabase {
        /**
         * Whether fulltext search is supported by current schema
-        * @return Boolean
+        * @return bool
         */
        function fulltextSearchSupported() {
                return $this->db->checkForEnabledSearch();
@@ -42,7 +42,7 @@ class SearchSqlite extends SearchDatabase {
         */
        function parseQuery( $filteredText, $fulltext ) {
                global $wgContLang;
-               $lc = SearchEngine::legalSearchChars(); // Minus format chars
+               $lc = $this->legalSearchChars(); // Minus format chars
                $searchon = '';
                $this->searchTerms = array();
 
@@ -50,7 +50,9 @@ class SearchSqlite extends SearchDatabase {
                if ( preg_match_all( '/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/',
                                $filteredText, $m, PREG_SET_ORDER ) ) {
                        foreach ( $m as $bits ) {
-                               @list( /* all */, $modifier, $term, $nonQuoted, $wildcard ) = $bits;
+                               wfSuppressWarnings();
+                               list( /* all */, $modifier, $term, $nonQuoted, $wildcard ) = $bits;
+                               wfRestoreWarnings();
 
                                if ( $nonQuoted != '' ) {
                                        $term = $nonQuoted;
@@ -113,9 +115,9 @@ class SearchSqlite extends SearchDatabase {
                        wfDebug( __METHOD__ . ": Can't understand search query '{$filteredText}'\n" );
                }
 
-               $searchon = $this->db->strencode( $searchon );
+               $searchon = $this->db->addQuotes( $searchon );
                $field = $this->getIndexField( $fulltext );
-               return " $field MATCH '$searchon' ";
+               return " $field MATCH $searchon ";
        }
 
        function regexTerm( $string, $wildcard ) {
@@ -144,8 +146,8 @@ class SearchSqlite extends SearchDatabase {
        /**
         * Perform a full text search query and return a result set.
         *
-        * @param string $term raw search term
-        * @return SqliteSearchResultSet
+        * @param string $term Raw search term
+        * @return SqlSearchResultSet
         */
        function searchText( $term ) {
                return $this->searchInternal( $term, true );
@@ -154,8 +156,8 @@ class SearchSqlite extends SearchDatabase {
        /**
         * Perform a title-only search query and return a result set.
         *
-        * @param string $term raw search term
-        * @return SqliteSearchResultSet
+        * @param string $term Raw search term
+        * @return SqlSearchResultSet
         */
        function searchTitle( $term ) {
                return $this->searchInternal( $term, false );
@@ -181,24 +183,12 @@ class SearchSqlite extends SearchDatabase {
                        $totalResult->free();
                }
 
-               return new SqliteSearchResultSet( $resultSet, $this->searchTerms, $total );
-       }
-
-       /**
-        * Return a partial WHERE clause to exclude redirects, if so set
-        * @return String
-        */
-       function queryRedirect() {
-               if ( $this->showRedirects ) {
-                       return '';
-               } else {
-                       return 'AND page_is_redirect=0';
-               }
+               return new SqlSearchResultSet( $resultSet, $this->searchTerms, $total );
        }
 
        /**
         * Return a partial WHERE clause to limit the search to the given namespaces
-        * @return String
+        * @return string
         */
        function queryNamespaces() {
                if ( is_null( $this->namespaces ) ) {
@@ -214,8 +204,8 @@ class SearchSqlite extends SearchDatabase {
 
        /**
         * Returns a query with limit for number of results set.
-        * @param $sql String:
-        * @return String
+        * @param string $sql
+        * @return string
         */
        function limitResult( $sql ) {
                return $this->db->limitResult( $sql, $this->limit, $this->offset );
@@ -224,22 +214,21 @@ class SearchSqlite extends SearchDatabase {
        /**
         * Construct the full SQL query to do the search.
         * The guts shoulds be constructed in queryMain()
-        * @param $filteredTerm String
-        * @param $fulltext Boolean
-        * @return String
+        * @param string $filteredTerm
+        * @param bool $fulltext
+        * @return string
         */
        function getQuery( $filteredTerm, $fulltext ) {
                return $this->limitResult(
                        $this->queryMain( $filteredTerm, $fulltext ) . ' ' .
-                       $this->queryRedirect() . ' ' .
                        $this->queryNamespaces()
                );
        }
 
        /**
         * Picks which field to index on, depending on what type of query.
-        * @param $fulltext Boolean
-        * @return String
+        * @param bool $fulltext
+        * @return string
         */
        function getIndexField( $fulltext ) {
                return $fulltext ? 'si_text' : 'si_title';
@@ -248,9 +237,9 @@ class SearchSqlite extends SearchDatabase {
        /**
         * Get the base part of the search query.
         *
-        * @param $filteredTerm String
-        * @param $fulltext Boolean
-        * @return String
+        * @param string $filteredTerm
+        * @param bool $fulltext
+        * @return string
         */
        function queryMain( $filteredTerm, $fulltext ) {
                $match = $this->parseQuery( $filteredTerm, $fulltext );
@@ -267,8 +256,7 @@ class SearchSqlite extends SearchDatabase {
                $searchindex = $this->db->tableName( 'searchindex' );
                return "SELECT COUNT(*) AS c " .
                        "FROM $page,$searchindex " .
-                       "WHERE page_id=$searchindex.rowid AND $match" .
-                       $this->queryRedirect() . ' ' .
+                       "WHERE page_id=$searchindex.rowid AND $match " .
                        $this->queryNamespaces();
        }
 
@@ -276,9 +264,9 @@ class SearchSqlite extends SearchDatabase {
         * Create or update the search index record for the given page.
         * Title and text should be pre-processed.
         *
-        * @param $id Integer
-        * @param $title String
-        * @param $text String
+        * @param int $id
+        * @param string $title
+        * @param string $text
         */
        function update( $id, $title, $text ) {
                if ( !$this->fulltextSearchSupported() ) {
@@ -302,8 +290,8 @@ class SearchSqlite extends SearchDatabase {
         * Update a search index record's title only.
         * Title should be pre-processed.
         *
-        * @param $id Integer
-        * @param $title String
+        * @param int $id
+        * @param string $title
         */
        function updateTitle( $id, $title ) {
                if ( !$this->fulltextSearchSupported() ) {
@@ -317,17 +305,3 @@ class SearchSqlite extends SearchDatabase {
                        __METHOD__ );
        }
 }
-
-/**
- * @ingroup Search
- */
-class SqliteSearchResultSet extends SqlSearchResultSet {
-       function __construct( $resultSet, $terms, $totalHits = null ) {
-               parent::__construct( $resultSet, $terms );
-               $this->mTotalHits = $totalHits;
-       }
-
-       function getTotalHits() {
-               return $this->mTotalHits;
-       }
-}