Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 50 |
|
0.00% |
0 / 13 |
CRAP | |
0.00% |
0 / 1 |
MathSearchTerm | |
0.00% |
0 / 50 |
|
0.00% |
0 / 13 |
506 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getKey | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setKey | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getRel | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setRel | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getExpr | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setExpr | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
doSearch | |
0.00% |
0 / 33 |
|
0.00% |
0 / 1 |
90 | |||
getResultSet | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getRelevanceMap | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getRevisionResult | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | use MediaWiki\MediaWikiServices; |
4 | |
5 | class MathSearchTerm { |
6 | |
7 | public const TYPE_TEXT = 0; |
8 | public const TYPE_MATH = 1; |
9 | public const TYPE_XMATH = 2; |
10 | public const REL_AND = 0; |
11 | public const REL_OR = 1; |
12 | public const REL_NAND = 2; |
13 | public const REL_NOR = 3; |
14 | |
15 | private $key = 0; |
16 | private $rel = 0; |
17 | private $type = 0; |
18 | private $expr = ''; |
19 | /** @var int[] */ |
20 | private $relevanceMap = []; |
21 | private $resultSet = []; |
22 | |
23 | /** |
24 | * @param int $i |
25 | * @param int $rel |
26 | * @param int $type |
27 | * @param string $expr |
28 | */ |
29 | function __construct( $i, $rel, $type, $expr ) { |
30 | $this->key = $i; |
31 | $this->rel = $rel; |
32 | $this->type = $type; |
33 | $this->expr = $expr; |
34 | } |
35 | |
36 | /** |
37 | * @return int |
38 | */ |
39 | public function getKey() { |
40 | return $this->key; |
41 | } |
42 | |
43 | /** |
44 | * @param int $key |
45 | */ |
46 | public function setKey( $key ) { |
47 | $this->key = $key; |
48 | } |
49 | |
50 | /** |
51 | * @return int |
52 | */ |
53 | public function getRel() { |
54 | return $this->rel; |
55 | } |
56 | |
57 | /** |
58 | * @param int $rel |
59 | */ |
60 | public function setRel( $rel ) { |
61 | $this->rel = $rel; |
62 | } |
63 | |
64 | /** |
65 | * @return int |
66 | */ |
67 | public function getType() { |
68 | return $this->type; |
69 | } |
70 | |
71 | /** |
72 | * @param int $type |
73 | */ |
74 | public function setType( $type ) { |
75 | $this->type = $type; |
76 | } |
77 | |
78 | /** |
79 | * @return string |
80 | */ |
81 | public function getExpr() { |
82 | return $this->expr; |
83 | } |
84 | |
85 | /** |
86 | * @param string $expr |
87 | */ |
88 | public function setExpr( $expr ) { |
89 | $this->expr = $expr; |
90 | } |
91 | |
92 | public function doSearch( MathEngineRest $backend ) { |
93 | $backend->resetResults(); |
94 | switch ( $this->getType() ) { |
95 | case self::TYPE_TEXT: |
96 | $search = MediaWikiServices::getInstance()->getSearchEngineFactory()->create( "CirrusSearch" ); |
97 | $search->setLimitOffset( 10000 ); |
98 | $sres = $search->searchText( $this->getExpr() ); |
99 | if ( $sres ) { |
100 | foreach ( $sres as $tres ) { |
101 | $revisionID = $tres->getTitle()->getLatestRevID(); |
102 | $this->resultSet[(string)$revisionID] = $tres; |
103 | $this->relevanceMap[] = $revisionID; |
104 | } |
105 | return true; |
106 | } |
107 | |
108 | return false; |
109 | |
110 | case self::TYPE_MATH: |
111 | $query = new MathQueryObject( $this->getExpr() ); |
112 | $cQuery = $query->getCQuery(); |
113 | if ( $cQuery ) { |
114 | $backend->setQuery( $query ); |
115 | if ( !$backend->postQuery() ) { |
116 | return false; |
117 | } |
118 | $this->relevanceMap = $backend->getRelevanceMap(); |
119 | $this->resultSet = $backend->getResultSet(); |
120 | } else { |
121 | return false; |
122 | } |
123 | break; |
124 | case self::TYPE_XMATH: |
125 | $query = new MathQueryObject( '' ); |
126 | $query->setXQuery( $this->getExpr() ); |
127 | $backend = new MathEngineBaseX( $query ); |
128 | $backend->setType( 'xquery' ); |
129 | if ( !$backend->postQuery() ) { |
130 | return false; |
131 | } |
132 | $this->relevanceMap = $backend->getRelevanceMap(); |
133 | $this->resultSet = $backend->getResultSet(); |
134 | } |
135 | } |
136 | |
137 | /** |
138 | * @return array |
139 | */ |
140 | public function getResultSet() { |
141 | return $this->resultSet; |
142 | } |
143 | |
144 | /** |
145 | * @return int[] |
146 | */ |
147 | public function getRelevanceMap() { |
148 | return $this->relevanceMap; |
149 | } |
150 | |
151 | public function getRevisionResult( $revisionId ) { |
152 | if ( array_key_exists( (string)$revisionId, $this->resultSet ) ) { |
153 | return $this->resultSet[(string)$revisionId]; |
154 | } |
155 | |
156 | return []; |
157 | } |
158 | |
159 | } |