Completed
Branch master (86dc85)
by
unknown
23:45
created

SqlSearchResultSet   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 13
c 1
b 0
f 1
lcom 1
cbo 4
dl 0
loc 61
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A termMatches() 0 3 1
A numRows() 0 7 2
A next() 0 14 3
A rewind() 0 5 2
A free() 0 7 2
A getTotalHits() 0 8 2
1
<?php
2
/**
3
 * This class is used for different SQL-based search engines shipped with MediaWiki
4
 * @ingroup Search
5
 */
6
class SqlSearchResultSet extends SearchResultSet {
7
	protected $resultSet;
8
	protected $terms;
9
	protected $totalHits;
10
11
	function __construct( ResultWrapper $resultSet, $terms, $total = null ) {
12
		$this->resultSet = $resultSet;
13
		$this->terms = $terms;
14
		$this->totalHits = $total;
15
	}
16
17
	function termMatches() {
18
		return $this->terms;
19
	}
20
21
	function numRows() {
22
		if ( $this->resultSet === false ) {
23
			return false;
24
		}
25
26
		return $this->resultSet->numRows();
27
	}
28
29
	function next() {
30
		if ( $this->resultSet === false ) {
31
			return false;
32
		}
33
34
		$row = $this->resultSet->fetchObject();
35
		if ( $row === false ) {
36
			return false;
37
		}
38
39
		return SearchResult::newFromTitle(
40
			Title::makeTitle( $row->page_namespace, $row->page_title )
41
		);
42
	}
43
44
	function rewind() {
45
		if ( $this->resultSet ) {
46
			$this->resultSet->rewind();
47
		}
48
	}
49
50
	function free() {
51
		if ( $this->resultSet === false ) {
52
			return false;
53
		}
54
55
		$this->resultSet->free();
56
	}
57
58
	function getTotalHits() {
59
		if ( !is_null( $this->totalHits ) ) {
60
			return $this->totalHits;
61
		} else {
62
			// Special:Search expects a number here.
63
			return $this->numRows();
64
		}
65
	}
66
}
67