MediaWiki  1.33.0
SqlSearchResultSet.php
Go to the documentation of this file.
1 <?php
2 
4 
11  protected $resultSet;
13  protected $terms;
15  protected $totalHits;
16 
17  function __construct( ResultWrapper $resultSet, $terms, $total = null ) {
18  $this->resultSet = $resultSet;
19  $this->terms = $terms;
20  $this->totalHits = $total;
21  }
22 
23  function termMatches() {
24  return $this->terms;
25  }
26 
27  function numRows() {
28  if ( $this->resultSet === false ) {
29  return false;
30  }
31 
32  return $this->resultSet->numRows();
33  }
34 
35  public function extractResults() {
36  if ( $this->resultSet === false ) {
37  return [];
38  }
39 
40  if ( $this->results === null ) {
41  $this->results = [];
42  $this->resultSet->rewind();
43  while ( ( $row = $this->resultSet->fetchObject() ) !== false ) {
44  $this->results[] = SearchResult::newFromTitle(
45  Title::makeTitle( $row->page_namespace, $row->page_title ), $this
46  );
47  }
48  }
49  return $this->results;
50  }
51 
52  function free() {
53  if ( $this->resultSet === false ) {
54  return false;
55  }
56 
57  $this->resultSet->free();
58  }
59 
60  function getTotalHits() {
61  if ( !is_null( $this->totalHits ) ) {
62  return $this->totalHits;
63  } else {
64  // Special:Search expects a number here.
65  return $this->numRows();
66  }
67  }
68 }
SqlSearchResultSet\free
free()
Frees the result set, if applicable.
Definition: SqlSearchResultSet.php:52
SqlSearchResultSet\$totalHits
int null $totalHits
Total number of hits for $terms.
Definition: SqlSearchResultSet.php:15
Wikimedia\Rdbms\ResultWrapper
Result wrapper for grabbing data queried from an IDatabase object.
Definition: ResultWrapper.php:24
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
SqlSearchResultSet\extractResults
extractResults()
Extract all the results in the result set as array.
Definition: SqlSearchResultSet.php:35
SqlSearchResultSet\$terms
string $terms
Requested search query.
Definition: SqlSearchResultSet.php:13
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:576
SearchResultSet
Definition: SearchResultSet.php:27
SqlSearchResultSet\$resultSet
ResultWrapper $resultSet
Result object from database.
Definition: SqlSearchResultSet.php:11
SqlSearchResultSet\__construct
__construct(ResultWrapper $resultSet, $terms, $total=null)
Definition: SqlSearchResultSet.php:17
SqlSearchResultSet
This class is used for different SQL-based search engines shipped with MediaWiki.
Definition: SqlSearchResultSet.php:9
terms
and give any other recipients of the Program a copy of this License along with the Program You may charge a fee for the physical act of transferring a and you may at your option offer warranty protection in exchange for a fee You may modify your copy or copies of the Program or any portion of thus forming a work based on the and copy and distribute such modifications or work under the terms of Section provided that you also meet all of these that in whole or in part contains or is derived from the Program or any part to be licensed as a whole at no charge to all third parties under the terms of this License c If the modified program normally reads commands interactively when you must cause when started running for such interactive use in the most ordinary to print or display an announcement including an appropriate copyright notice and a notice that there is no and telling the user how to view a copy of this and can be reasonably considered independent and separate works in then this and its terms
Definition: COPYING.txt:117
SqlSearchResultSet\termMatches
termMatches()
Fetch an array of regular expression fragments for matching the search terms as parsed by this engine...
Definition: SqlSearchResultSet.php:23
SqlSearchResultSet\numRows
numRows()
Definition: SqlSearchResultSet.php:27
SearchResult\newFromTitle
static newFromTitle( $title, SearchResultSet $parentSet=null)
Return a new SearchResult and initializes it with a title.
Definition: SearchResult.php:72
SearchResultSet\$results
SearchResult[] $results
Cache of results - serialization of the result iterator as an array.
Definition: SearchResultSet.php:56
SqlSearchResultSet\getTotalHits
getTotalHits()
Some search modes return a total hit count for the query in the entire article database.
Definition: SqlSearchResultSet.php:60