MediaWiki  REL1_23
SearchResultSet.php
Go to the documentation of this file.
00001 <?php
00027 class SearchResultSet {
00035     function termMatches() {
00036         return array();
00037     }
00038 
00039     function numRows() {
00040         return 0;
00041     }
00042 
00049     function hasResults() {
00050         return false;
00051     }
00052 
00063     function getTotalHits() {
00064         return null;
00065     }
00066 
00073     function hasSuggestion() {
00074         return false;
00075     }
00076 
00080     function getSuggestionQuery() {
00081         return null;
00082     }
00083 
00087     function getSuggestionSnippet() {
00088         return '';
00089     }
00090 
00096     function getInterwikiResults() {
00097         return null;
00098     }
00099 
00105     function hasInterwikiResults() {
00106         return $this->getInterwikiResults() != null;
00107     }
00108 
00115     function next() {
00116         return false;
00117     }
00118 
00122     function free() {
00123         // ...
00124     }
00125 
00131     public function searchContainedSyntax() {
00132         return false;
00133     }
00134 }
00135 
00140 class SqlSearchResultSet extends SearchResultSet {
00141 
00142     protected $mResultSet;
00143 
00144     function __construct( $resultSet, $terms ) {
00145         $this->mResultSet = $resultSet;
00146         $this->mTerms = $terms;
00147     }
00148 
00149     function termMatches() {
00150         return $this->mTerms;
00151     }
00152 
00153     function numRows() {
00154         if ( $this->mResultSet === false ) {
00155             return false;
00156         }
00157 
00158         return $this->mResultSet->numRows();
00159     }
00160 
00161     function next() {
00162         if ( $this->mResultSet === false ) {
00163             return false;
00164         }
00165 
00166         $row = $this->mResultSet->fetchObject();
00167         if ( $row === false ) {
00168             return false;
00169         }
00170 
00171         return SearchResult::newFromRow( $row );
00172     }
00173 
00174     function free() {
00175         if ( $this->mResultSet === false ) {
00176             return false;
00177         }
00178 
00179         $this->mResultSet->free();
00180     }
00181 }
00182 
00186 class SearchNearMatchResultSet extends SearchResultSet {
00187     private $fetched = false;
00188 
00192     public function __construct( $match ) {
00193         $this->result = $match;
00194     }
00195 
00196     public function hasResult() {
00197         return (bool)$this->result;
00198     }
00199 
00200     public function numRows() {
00201         return $this->hasResults() ? 1 : 0;
00202     }
00203 
00204     public function next() {
00205         if ( $this->fetched || !$this->result ) {
00206             return false;
00207         }
00208         $this->fetched = true;
00209         return SearchResult::newFromTitle( $this->result );
00210     }
00211 }