r107203 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107202‎ | r107203 | r107204 >
Date:14:43, 24 December 2011
Author:ashley
Status:ok
Tags:
Comment:
SolrStore: follow-up to r106682: convert spaces to tabs
Modified paths:
  • /trunk/extensions/SolrStore/SolrConnectorStore.php (modified) (history)
  • /trunk/extensions/SolrStore/SolrDoc.php (modified) (history)
  • /trunk/extensions/SolrStore/SolrSearch.php (modified) (history)
  • /trunk/extensions/SolrStore/SolrSearchFieldSet.php (modified) (history)
  • /trunk/extensions/SolrStore/SolrTalker.php (modified) (history)
  • /trunk/extensions/SolrStore/SpecialSolrSearch.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SolrStore/SolrTalker.php
@@ -14,211 +14,211 @@
1515 */
1616 class SolrTalker {
1717
18 - private $header = array( "Content-type:text/xml; charset=utf-8" );
19 - private $schema;
 18+ private $header = array( "Content-type:text/xml; charset=utf-8" );
 19+ private $schema;
2020
21 - /**
22 - * Get the Schema from SOLR as XML
23 - * This Includes all Dynamic Fields
24 - *
25 - * @return type $xml schema
26 - */
27 - public function getSchema() {
28 - global $wgSolrUrl;
29 - $xml = $this->solrSend( $wgSolrUrl . '/admin/luke?numTerms=0' );
 21+ /**
 22+ * Get the Schema from SOLR as XML
 23+ * This Includes all Dynamic Fields
 24+ *
 25+ * @return type $xml schema
 26+ */
 27+ public function getSchema() {
 28+ global $wgSolrUrl;
 29+ $xml = $this->solrSend( $wgSolrUrl . '/admin/luke?numTerms=0' );
3030
31 - try {
32 - $this->schema = $xml;
33 - } catch ( Exception $exc ) {
34 - return false;
35 - }
 31+ try {
 32+ $this->schema = $xml;
 33+ } catch ( Exception $exc ) {
 34+ return false;
 35+ }
3636
37 - return $this->schema;
38 - }
 37+ return $this->schema;
 38+ }
3939
40 - public function encodeSolr( $query ) {
41 - // Using the urlencode from php doenst work!?, so we need to do it our self
42 - $query = str_replace( '"', '%22', trim( $query ) );
43 - $query = str_replace( ' ', '+', $query );
44 - $query = str_replace( 'ü', '%FC', $query );
45 - $query = str_replace( 'Ü', '%DC', $query );
46 - $query = str_replace( 'ö', '%F6', $query );
47 - $query = str_replace( 'Ö', '%D6', $query );
48 - $query = str_replace( 'ä', '%E4', $query );
49 - $query = str_replace( 'ä', '%C4', $query );
50 - return $query;
51 - }
 40+ public function encodeSolr( $query ) {
 41+ // Using the urlencode from php doenst work!?, so we need to do it our self
 42+ $query = str_replace( '"', '%22', trim( $query ) );
 43+ $query = str_replace( ' ', '+', $query );
 44+ $query = str_replace( 'ü', '%FC', $query );
 45+ $query = str_replace( 'Ü', '%DC', $query );
 46+ $query = str_replace( 'ö', '%F6', $query );
 47+ $query = str_replace( 'Ö', '%D6', $query );
 48+ $query = str_replace( 'ä', '%E4', $query );
 49+ $query = str_replace( 'ä', '%C4', $query );
 50+ return $query;
 51+ }
5252
53 - /**
54 - * Perform a SolrSearch
55 - *
56 - * @global type $wgSolrUrl
57 - * @param type $query - Search Term
58 - * @param type $start - Offset
59 - * @param type $end - Limit
60 - * @return type $xml - Solr Result as XML
61 - *
62 - */
63 - public function solrQuery( $query, $start, $end, $highlight = false, $score = false ) {
64 - global $wgSolrUrl;
65 - $query = trim( $query );
66 - if ( empty( $query ) ) {
67 - $query = '*';
68 - }
69 - $url = $wgSolrUrl . '/select?q=' . $query . '&start=' . $start . '&rows=' . $end; // . '&fl=*%2Cscore'; No Score for now, ther seems to be a BUG
70 - if ( $highlight ) {
71 - $url .= '&hl=on&hl.fl=*';
72 - }
73 - if ( $score ) {
74 - $url .= '&fl=*%2Cscore';
75 - }
76 - return $this->solrSend( $url );
77 - }
 53+ /**
 54+ * Perform a SolrSearch
 55+ *
 56+ * @global type $wgSolrUrl
 57+ * @param type $query - Search Term
 58+ * @param type $start - Offset
 59+ * @param type $end - Limit
 60+ * @return type $xml - Solr Result as XML
 61+ *
 62+ */
 63+ public function solrQuery( $query, $start, $end, $highlight = false, $score = false ) {
 64+ global $wgSolrUrl;
 65+ $query = trim( $query );
 66+ if ( empty( $query ) ) {
 67+ $query = '*';
 68+ }
 69+ $url = $wgSolrUrl . '/select?q=' . $query . '&start=' . $start . '&rows=' . $end; // . '&fl=*%2Cscore'; No Score for now, ther seems to be a BUG
 70+ if ( $highlight ) {
 71+ $url .= '&hl=on&hl.fl=*';
 72+ }
 73+ if ( $score ) {
 74+ $url .= '&fl=*%2Cscore';
 75+ }
 76+ return $this->solrSend( $url );
 77+ }
7878
79 - /**
80 - * Find the real name of the Field in the SOlr schema
81 - *
82 - * @param type $searchField
83 - * @param type $sort = ASC or DESC
84 - * @return type Name of the Field you are searching for
85 - */
86 - public function findField( $searchField, $sort = 'ASC' ) {
87 - $xml = $this->getSchema();
88 - // $searchField = trim($searchField);
89 - $searchField = str_replace( ' ', '_', trim( $searchField ) ); // Trim and Replace all Spaces with underscore for better matching
90 - $result = false;
91 - $stop = false;
 79+ /**
 80+ * Find the real name of the Field in the SOlr schema
 81+ *
 82+ * @param type $searchField
 83+ * @param type $sort = ASC or DESC
 84+ * @return type Name of the Field you are searching for
 85+ */
 86+ public function findField( $searchField, $sort = 'ASC' ) {
 87+ $xml = $this->getSchema();
 88+ // $searchField = trim($searchField);
 89+ $searchField = str_replace( ' ', '_', trim( $searchField ) ); // Trim and Replace all Spaces with underscore for better matching
 90+ $result = false;
 91+ $stop = false;
9292
93 - // TODO: Decide on ASC + DESC parameter for Max or Min Sort Field
94 - foreach ( $xml->lst as $item ) {
95 - if ( $item['name'] == 'fields' ) {
96 - foreach ( $item->lst as $field ) {
97 - if ( count( $field ) > 2 ) {
98 - $dynamicBase = substr( $field->str[2], 1 ); // Get The dynamicbase of the Field eg. "*_dtmax"
99 - $newField = str_replace( $dynamicBase, '', $field['name'] ); // Get the Fieldname without the dynamicbase
100 - if ( strcasecmp( str_replace( ' ', '_', $newField ), $searchField ) == 0 ) { // Replace all Spaces with underscore for better matching
101 - if ( stripos( $dynamicBase, 'max' ) && stripos( $sort, 'desc' ) ) {
102 - // For Descending Sorting use the MaX value Field
103 - continue 2; // we got the right Field Stop it!
104 - } else if ( stripos( $dynamicBase, 'min' ) && stripos( $sort, 'asc' ) ) {
105 - // For Ascending Sorting use the MIN value Field
106 - continue 2; // we got the right Field Stop it!
107 - }
108 - } else if ( strcasecmp( str_replace( ' ', '_', $field['name'] ), $searchField ) == 0 ) { // Replace all Spaces with underscore for better matching
109 - $result = trim( $searchField );
110 - }
111 - } else {
112 - if ( strcasecmp( trim( $field['name'] ), trim( $searchField ) ) == 0 ) {
113 - $result = trim( $field['name'] );
114 - }
115 - }
116 - }
117 - }
118 - }
119 - return $result;
120 - }
 93+ // TODO: Decide on ASC + DESC parameter for Max or Min Sort Field
 94+ foreach ( $xml->lst as $item ) {
 95+ if ( $item['name'] == 'fields' ) {
 96+ foreach ( $item->lst as $field ) {
 97+ if ( count( $field ) > 2 ) {
 98+ $dynamicBase = substr( $field->str[2], 1 ); // Get The dynamicbase of the Field eg. "*_dtmax"
 99+ $newField = str_replace( $dynamicBase, '', $field['name'] ); // Get the Fieldname without the dynamicbase
 100+ if ( strcasecmp( str_replace( ' ', '_', $newField ), $searchField ) == 0 ) { // Replace all Spaces with underscore for better matching
 101+ if ( stripos( $dynamicBase, 'max' ) && stripos( $sort, 'desc' ) ) {
 102+ // For Descending Sorting use the MaX value Field
 103+ continue 2; // we got the right Field Stop it!
 104+ } else if ( stripos( $dynamicBase, 'min' ) && stripos( $sort, 'asc' ) ) {
 105+ // For Ascending Sorting use the MIN value Field
 106+ continue 2; // we got the right Field Stop it!
 107+ }
 108+ } else if ( strcasecmp( str_replace( ' ', '_', $field['name'] ), $searchField ) == 0 ) { // Replace all Spaces with underscore for better matching
 109+ $result = trim( $searchField );
 110+ }
 111+ } else {
 112+ if ( strcasecmp( trim( $field['name'] ), trim( $searchField ) ) == 0 ) {
 113+ $result = trim( $field['name'] );
 114+ }
 115+ }
 116+ }
 117+ }
 118+ }
 119+ return $result;
 120+ }
121121
122 - /**
123 - * Check the Query for existing fields
124 - *
125 - * @param type $queryStr - Wiki QueryString
126 - * @return type $queryStr - Solr QueryString
127 - */
128 - public function queryChecker( $queryStr ) {
129 - $queryStr = str_replace( '=', ':', $queryStr ); // Now you can use = insted : for querying Fields
130 - if ( strpos( $queryStr, ':' ) !== false ) {
131 - $queryParts = explode( " ", $queryStr ); // Split on Spaces and Search for Fields
132 - $queryStr = '';
133 - foreach ( $queryParts as $value ) {
134 - if ( strpos( $value, ':' ) !== false ) { // Value conatins a ":" ?
135 - $parts = explode( ':', $value ); // Split the Query part in Key (Parts[0]) and Value (Parts[1])
136 - $solrField = $this->findField( $parts[0] ); // Search for a Solr Field for the Key
137 - if ( $solrField ) {
138 - $queryStr = $queryStr . ' ' . $solrField . ':' . $parts[1];
139 - } else {
140 - $queryStr = $queryStr . ' ' . $parts[0] . ' ' . $parts[1];
141 - }
142 - } else {
143 - $queryStr = $queryStr . ' ' . $value;
144 - }
145 - }
146 - }
 122+ /**
 123+ * Check the Query for existing fields
 124+ *
 125+ * @param type $queryStr - Wiki QueryString
 126+ * @return type $queryStr - Solr QueryString
 127+ */
 128+ public function queryChecker( $queryStr ) {
 129+ $queryStr = str_replace( '=', ':', $queryStr ); // Now you can use = insted : for querying Fields
 130+ if ( strpos( $queryStr, ':' ) !== false ) {
 131+ $queryParts = explode( " ", $queryStr ); // Split on Spaces and Search for Fields
 132+ $queryStr = '';
 133+ foreach ( $queryParts as $value ) {
 134+ if ( strpos( $value, ':' ) !== false ) { // Value conatins a ":" ?
 135+ $parts = explode( ':', $value ); // Split the Query part in Key (Parts[0]) and Value (Parts[1])
 136+ $solrField = $this->findField( $parts[0] ); // Search for a Solr Field for the Key
 137+ if ( $solrField ) {
 138+ $queryStr = $queryStr . ' ' . $solrField . ':' . $parts[1];
 139+ } else {
 140+ $queryStr = $queryStr . ' ' . $parts[0] . ' ' . $parts[1];
 141+ }
 142+ } else {
 143+ $queryStr = $queryStr . ' ' . $value;
 144+ }
 145+ }
 146+ }
147147
148 - return $queryStr = $this->encodeSolr( $queryStr );
149 - }
 148+ return $queryStr = $this->encodeSolr( $queryStr );
 149+ }
150150
151 - /**
152 - * Transform a Wiki Query to a Solr Query
153 - * TODO: Do more Wiki2Solr transformation
154 - *
155 - * @param type $queryStr - Wiki QueryString
156 - * @return type $queryStr - Solr QueryString
157 - */
158 - public function parseSolrQuery( $queryStr ) {
159 - // TODO: Parse the QueryString to make it work in Solr
160 - $queryParts = explode( "[[", $queryStr );
 151+ /**
 152+ * Transform a Wiki Query to a Solr Query
 153+ * TODO: Do more Wiki2Solr transformation
 154+ *
 155+ * @param type $queryStr - Wiki QueryString
 156+ * @return type $queryStr - Solr QueryString
 157+ */
 158+ public function parseSolrQuery( $queryStr ) {
 159+ // TODO: Parse the QueryString to make it work in Solr
 160+ $queryParts = explode( "[[", $queryStr );
161161
162 - // Clean the queryStr
163 - $queryStr = '';
164 - foreach ( $queryParts as $part ) {
165 - if ( stripos( $part, '::' ) ) {
166 - $parts = split( '::', $part ); // Split the Query part in Key (Parts[0]) and Value (Parts[1])
167 - $parts[0] = $this->findField( $parts[0] ); // Search for a Solr Field for the Key
168 - $queryStr = $queryStr . ' ' . $parts[0] . ':' . $parts[1]; // Build Querystring
169 - } elseif ( stripos( $part, ':' ) ) {
170 - $queryStr = $queryStr . ' category' . substr( $part, stripos( $part, ':' ) );
171 - } else {
172 - $queryStr = $queryStr . $part;
173 - }
174 - }
175 - $queryStr = str_replace( '[', '', $queryStr );
176 - $queryStr = str_replace( ']', '', $queryStr );
 162+ // Clean the queryStr
 163+ $queryStr = '';
 164+ foreach ( $queryParts as $part ) {
 165+ if ( stripos( $part, '::' ) ) {
 166+ $parts = split( '::', $part ); // Split the Query part in Key (Parts[0]) and Value (Parts[1])
 167+ $parts[0] = $this->findField( $parts[0] ); // Search for a Solr Field for the Key
 168+ $queryStr = $queryStr . ' ' . $parts[0] . ':' . $parts[1]; // Build Querystring
 169+ } elseif ( stripos( $part, ':' ) ) {
 170+ $queryStr = $queryStr . ' category' . substr( $part, stripos( $part, ':' ) );
 171+ } else {
 172+ $queryStr = $queryStr . $part;
 173+ }
 174+ }
 175+ $queryStr = str_replace( '[', '', $queryStr );
 176+ $queryStr = str_replace( ']', '', $queryStr );
177177
178 - return $queryStr;
179 - }
 178+ return $queryStr;
 179+ }
180180
181 - /**
182 - * Add an XML Document to the Solr Index
183 - *
184 - * @param $xmlcontent - Solr XML Document
185 - */
186 - public function solrAdd( $xmlcontent ) {
187 - global $wgSolrUrl;
 181+ /**
 182+ * Add an XML Document to the Solr Index
 183+ *
 184+ * @param $xmlcontent - Solr XML Document
 185+ */
 186+ public function solrAdd( $xmlcontent ) {
 187+ global $wgSolrUrl;
188188
189 - $url = $wgSolrUrl . '/update?commit=true';
190 - $xmlcontent = str_replace( '&', '+', $xmlcontent );
191 - $xmlcontent = str_replace( ' ', ' ', $xmlcontent );
192 - $xmlcontent = str_replace( '&nbsp', ' ', $xmlcontent );
193 - $xmlcontent = str_replace( '&', ' ', $xmlcontent );
194 - $xmlcontent = str_replace( '&amp', ' ', $xmlcontent );
 189+ $url = $wgSolrUrl . '/update?commit=true';
 190+ $xmlcontent = str_replace( '&', '+', $xmlcontent );
 191+ $xmlcontent = str_replace( ' ', ' ', $xmlcontent );
 192+ $xmlcontent = str_replace( '&nbsp', ' ', $xmlcontent );
 193+ $xmlcontent = str_replace( '&', ' ', $xmlcontent );
 194+ $xmlcontent = str_replace( '&amp', ' ', $xmlcontent );
195195
196 - return $this->solrSend( $url, $xmlcontent );
197 - }
 196+ return $this->solrSend( $url, $xmlcontent );
 197+ }
198198
199 - /**
200 - * Private Function for interactinig with Solr.
201 - *
202 - * @param type $url
203 - * @param type $xmlcontent
204 - * @return SimpleXMLElement
205 - */
206 - private function solrSend( $url, $xmlcontent = false ) {
207 - $ch = curl_init();
 199+ /**
 200+ * Private Function for interactinig with Solr.
 201+ *
 202+ * @param type $url
 203+ * @param type $xmlcontent
 204+ * @return SimpleXMLElement
 205+ */
 206+ private function solrSend( $url, $xmlcontent = false ) {
 207+ $ch = curl_init();
208208
209 - $url = str_replace( ' ', '+', $url );
 209+ $url = str_replace( ' ', '+', $url );
210210
211 - curl_setopt( $ch, CURLOPT_URL, $url );
212 - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
213 - curl_setopt( $ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 );
214 - curl_setopt( $ch, CURLINFO_HEADER_OUT, 1 );
 211+ curl_setopt( $ch, CURLOPT_URL, $url );
 212+ curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
 213+ curl_setopt( $ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 );
 214+ curl_setopt( $ch, CURLINFO_HEADER_OUT, 1 );
215215
216 - if ( $xmlcontent ) {
217 - curl_setopt( $ch, CURLOPT_POST, 1 );
218 - curl_setopt( $ch, CURLOPT_HTTPHEADER, $this->header );
219 - curl_setopt( $ch, CURLOPT_POSTFIELDS, $xmlcontent );
220 - }
 216+ if ( $xmlcontent ) {
 217+ curl_setopt( $ch, CURLOPT_POST, 1 );
 218+ curl_setopt( $ch, CURLOPT_HTTPHEADER, $this->header );
 219+ curl_setopt( $ch, CURLOPT_POSTFIELDS, $xmlcontent );
 220+ }
221221
222 - $data = curl_exec( $ch );
 222+ $data = curl_exec( $ch );
223223
224224 if ( curl_errno( $ch ) != 0 ) {
225225 throw new MWException( curl_error( $ch ) );
@@ -249,179 +249,179 @@
250250 throw new MWException( $errmsg );
251251 }
252252
253 - return $xml;
254 - }
 253+ return $xml;
 254+ }
255255
256 - // SOLR Functions
 256+ // SOLR Functions
257257
258 - /**
259 - * Add a Document to the SolrIndex
260 - * @param SolrDoc $file
261 - */
262 - public function addDoc( SolrDoc $file ) {
263 - $filekopf = "<add><doc>";
264 - $filefuss = "</doc></add>";
265 - $xmlcontent = $filekopf . $file->printFields() . $filefuss;
266 - return $this->solrAdd( $xmlcontent );
267 - }
 258+ /**
 259+ * Add a Document to the SolrIndex
 260+ * @param SolrDoc $file
 261+ */
 262+ public function addDoc( SolrDoc $file ) {
 263+ $filekopf = "<add><doc>";
 264+ $filefuss = "</doc></add>";
 265+ $xmlcontent = $filekopf . $file->printFields() . $filefuss;
 266+ return $this->solrAdd( $xmlcontent );
 267+ }
268268
269 - /**
270 - * Remove a Document with the $id from the SolrIndex
271 - * @param type $id
272 - * @return type $xml - Response from Solr
273 - */
274 - public function deleteDocId( $id ) {
275 - $filekopf = "<delte><id>";
276 - $filefuss = "</id></delte>";
277 - $xmlcontent = $filekopf . $id . $filefuss;
278 - return $this->solrAdd( $xmlcontent );
279 - }
 269+ /**
 270+ * Remove a Document with the $id from the SolrIndex
 271+ * @param type $id
 272+ * @return type $xml - Response from Solr
 273+ */
 274+ public function deleteDocId( $id ) {
 275+ $filekopf = "<delte><id>";
 276+ $filefuss = "</id></delte>";
 277+ $xmlcontent = $filekopf . $id . $filefuss;
 278+ return $this->solrAdd( $xmlcontent );
 279+ }
280280
281 - /**
282 - * Delete all Documents found by this Query
283 - * @param type $query
284 - * @return type $xml - Response from Solr
285 - */
286 - public function deleteDocQuery( $query ) {
287 - $filekopf = "<delte><query>";
288 - $filefuss = "</query></delte>";
289 - $xmlcontent = $filekopf . $query . $filefuss;
290 - return $this->solrAdd( $xmlcontent );
291 - }
 281+ /**
 282+ * Delete all Documents found by this Query
 283+ * @param type $query
 284+ * @return type $xml - Response from Solr
 285+ */
 286+ public function deleteDocQuery( $query ) {
 287+ $filekopf = "<delte><query>";
 288+ $filefuss = "</query></delte>";
 289+ $xmlcontent = $filekopf . $query . $filefuss;
 290+ return $this->solrAdd( $xmlcontent );
 291+ }
292292
293 - /**
294 - * DELETE ALL DOCS FROM SOLR INDEX!!!
295 - * @return type $xml - Response from Solr
296 - */
297 - public function deleteAllDocs() {
298 - $xmlcontent = '<delete><query>*:*</query></delete>';
299 - return $this->solrAdd( $xmlcontent );
300 - }
 293+ /**
 294+ * DELETE ALL DOCS FROM SOLR INDEX!!!
 295+ * @return type $xml - Response from Solr
 296+ */
 297+ public function deleteAllDocs() {
 298+ $xmlcontent = '<delete><query>*:*</query></delete>';
 299+ return $this->solrAdd( $xmlcontent );
 300+ }
301301
302 - /**
303 - * This Function is used for Storing an SMWSemanticData Item in the Solr Index
304 - *
305 - * @param SMWSemanticData $data
306 - */
307 - public function parseSemanticData( SMWSemanticData $data ) {
308 - $solritem = new SolrDoc ();
 302+ /**
 303+ * This Function is used for Storing an SMWSemanticData Item in the Solr Index
 304+ *
 305+ * @param SMWSemanticData $data
 306+ */
 307+ public function parseSemanticData( SMWSemanticData $data ) {
 308+ $solritem = new SolrDoc ();
309309
310 - $solritem->addField( "pagetitle", $data->getSubject()->getTitle()->getText() );
311 - $solritem->addField( "namespace", $data->getSubject()->getNamespace() );
312 - $solritem->addField( "dbkey", $data->getSubject()->getDBkey() );
313 - $solritem->addField( "interwiki", $data->getSubject()->getInterwiki() );
314 - $solritem->addField( "subobjectname", $data->getSubject()->getSubobjectName() );
 310+ $solritem->addField( "pagetitle", $data->getSubject()->getTitle()->getText() );
 311+ $solritem->addField( "namespace", $data->getSubject()->getNamespace() );
 312+ $solritem->addField( "dbkey", $data->getSubject()->getDBkey() );
 313+ $solritem->addField( "interwiki", $data->getSubject()->getInterwiki() );
 314+ $solritem->addField( "subobjectname", $data->getSubject()->getSubobjectName() );
315315
316 - foreach ( $data->getProperties() as $property ) {
317 - if ( ( $property->getKey() == '_SKEY' ) || ( $property->getKey() == '_REDI' ) ) {
318 - continue; // skip these here, we store them differently
319 - }
 316+ foreach ( $data->getProperties() as $property ) {
 317+ if ( ( $property->getKey() == '_SKEY' ) || ( $property->getKey() == '_REDI' ) ) {
 318+ continue; // skip these here, we store them differently
 319+ }
320320
321 - $propertyName = $property->getLabel();
 321+ $propertyName = $property->getLabel();
322322
323 - foreach ( $data->getPropertyValues( $property ) as $di ) {
324 - if ( $di instanceof SMWDIError ) { // error values, ignore
325 - continue;
326 - }
327 - switch ( $di->getDIType() ) {
328 - case 0:
329 -// /// Data item ID that can be used to indicate that no data item class is appropriate
330 -// const TYPE_NOTYPE = 0;
331 - break;
 323+ foreach ( $data->getPropertyValues( $property ) as $di ) {
 324+ if ( $di instanceof SMWDIError ) { // error values, ignore
 325+ continue;
 326+ }
 327+ switch ( $di->getDIType() ) {
 328+ case 0:
 329+// /// Data item ID that can be used to indicate that no data item class is appropriate
 330+// const TYPE_NOTYPE = 0;
 331+ break;
332332
333 - case 1:
 333+ case 1:
334334 // /// Data item ID for SMWDINumber
335 -// const TYPE_NUMBER = 1;
336 - $solritem->addField( $propertyName . '_i', $di->getNumber() );
337 - $solritem->addSortField( $propertyName . '_i', $di->getNumber() );
338 - break;
 335+// const TYPE_NUMBER = 1;
 336+ $solritem->addField( $propertyName . '_i', $di->getNumber() );
 337+ $solritem->addSortField( $propertyName . '_i', $di->getNumber() );
 338+ break;
339339
340 - case 2:
 340+ case 2:
341341 // /// Data item ID for SMWDIString
342 -// const TYPE_STRING = 2;
343 - $solritem->addField( $propertyName . '_t', $di->getString() );
344 - $solritem->addSortField( $propertyName . '_t', $di->getString() );
345 - break;
 342+// const TYPE_STRING = 2;
 343+ $solritem->addField( $propertyName . '_t', $di->getString() );
 344+ $solritem->addSortField( $propertyName . '_t', $di->getString() );
 345+ break;
346346
347 - case 3:
 347+ case 3:
348348 // /// Data item ID for SMWDIBlob
349 -// const TYPE_BLOB = 3;
350 - $solritem->addField( $propertyName . '_t', $di->getString() );
351 - $solritem->addSortField( $propertyName . '_t', $di->getString() );
352 - break;
 349+// const TYPE_BLOB = 3;
 350+ $solritem->addField( $propertyName . '_t', $di->getString() );
 351+ $solritem->addSortField( $propertyName . '_t', $di->getString() );
 352+ break;
353353
354 - case 4:
 354+ case 4:
355355 // /// Data item ID for SMWDIBoolean
356 -// const TYPE_BOOLEAN = 4;
357 - $solritem->addField( $propertyName . '_b', $di->getBoolean() );
358 - $solritem->addSortField( $propertyName . '_b', $di->getBoolean() );
359 - break;
 356+// const TYPE_BOOLEAN = 4;
 357+ $solritem->addField( $propertyName . '_b', $di->getBoolean() );
 358+ $solritem->addSortField( $propertyName . '_b', $di->getBoolean() );
 359+ break;
360360
361 - case 5:
 361+ case 5:
362362 // /// Data item ID for SMWDIUri
363 -// const TYPE_URI = 5;
364 - $solritem->addField( $propertyName . '_t', $di->getURI() );
365 - $solritem->addSortField( $propertyName . '_t', $di->getURI() );
366 - break;
 363+// const TYPE_URI = 5;
 364+ $solritem->addField( $propertyName . '_t', $di->getURI() );
 365+ $solritem->addSortField( $propertyName . '_t', $di->getURI() );
 366+ break;
367367
368 - case 6:
 368+ case 6:
369369 // /// Data item ID for SMWDITimePoint
370 -// const TYPE_TIME = 6;
371 - $date = $di->getYear() . '-' . $di->getMonth() . '-' . $di->getDay() . 'T' . $di->getHour() . ':' . $di->getMinute() . ':' . $di->getSecond() . 'Z';
372 - $solritem->addField( $propertyName . '_dt', $date );
373 - $solritem->addSortField( $propertyName . '_dt', $date );
374 - break;
 370+// const TYPE_TIME = 6;
 371+ $date = $di->getYear() . '-' . $di->getMonth() . '-' . $di->getDay() . 'T' . $di->getHour() . ':' . $di->getMinute() . ':' . $di->getSecond() . 'Z';
 372+ $solritem->addField( $propertyName . '_dt', $date );
 373+ $solritem->addSortField( $propertyName . '_dt', $date );
 374+ break;
375375
376 - case 7:
 376+ case 7:
377377 // /// Data item ID for SMWDIGeoCoord
378 -// const TYPE_GEO = 7;
379 - // TODO: Implement range Search in SOLR
380 - $solritem->addField( $propertyName . '_lat', $di->getLatitude() );
381 - $solritem->addField( $propertyName . '_lng', $di->getLongitude() );
382 - break;
 378+// const TYPE_GEO = 7;
 379+ // TODO: Implement range Search in SOLR
 380+ $solritem->addField( $propertyName . '_lat', $di->getLatitude() );
 381+ $solritem->addField( $propertyName . '_lng', $di->getLongitude() );
 382+ break;
383383
384 - case 8:
 384+ case 8:
385385 // /// Data item ID for SMWDIContainer
386386 // const TYPE_CONTAINER = 8
387 - // TODO: What the Hell is this used for ???
388 - $data->getSubject()->getTitle()->getText() . " : ";
389 - break;
 387+ // TODO: What the Hell is this used for ???
 388+ $data->getSubject()->getTitle()->getText() . " : ";
 389+ break;
390390
391 - case 9:
 391+ case 9:
392392 // /// Data item ID for SMWDIWikiPage
393 -// const TYPE_WIKIPAGE = 9;
394 - $ns = $di->getNamespace();
395 - if ( $ns == 0 ) {
396 - $solritem->addField( $propertyName . '_s', $di->getTitle() );
397 - } elseif ( $ns == 14 ) {
398 - $title = $di->getTitle();
399 - $solritem->addField( 'category', substr( $title, stripos( $title, ':' ) + 1 ) );
400 - }
401 - break;
 393+// const TYPE_WIKIPAGE = 9;
 394+ $ns = $di->getNamespace();
 395+ if ( $ns == 0 ) {
 396+ $solritem->addField( $propertyName . '_s', $di->getTitle() );
 397+ } elseif ( $ns == 14 ) {
 398+ $title = $di->getTitle();
 399+ $solritem->addField( 'category', substr( $title, stripos( $title, ':' ) + 1 ) );
 400+ }
 401+ break;
402402
403 - case 10:
 403+ case 10:
404404 // /// Data item ID for SMWDIConcept
405 -// const TYPE_CONCEPT = 10;
406 - $data->getSubject()->getTitle()->getText() . " : ";
407 - break;
 405+// const TYPE_CONCEPT = 10;
 406+ $data->getSubject()->getTitle()->getText() . " : ";
 407+ break;
408408
409 - case 11:
 409+ case 11:
410410 // /// Data item ID for SMWDIProperty
411 -// const TYPE_PROPERTY = 11;
412 - $data->getSubject()->getTitle()->getText() . " : ";
413 - break;
 411+// const TYPE_PROPERTY = 11;
 412+ $data->getSubject()->getTitle()->getText() . " : ";
 413+ break;
414414
415 - case 12:
 415+ case 12:
416416 // /// Data item ID for SMWDIError
417 -// const TYPE_ERROR = 12;
418 - $data->getSubject()->getTitle()->getText() . " : ";
419 - break;
420 - default:
421 - break;
422 - }
423 - }
424 - }
425 - $this->addDoc( $solritem );
426 - }
 417+// const TYPE_ERROR = 12;
 418+ $data->getSubject()->getTitle()->getText() . " : ";
 419+ break;
 420+ default:
 421+ break;
 422+ }
 423+ }
 424+ }
 425+ $this->addDoc( $solritem );
 426+ }
427427
428428 }
Index: trunk/extensions/SolrStore/SolrDoc.php
@@ -13,53 +13,53 @@
1414 * @ingroup SolrStore
1515 */
1616 class SolrDoc {
17 - private $output;
18 - private $min = array ();
19 - private $max = array ();
 17+ private $output;
 18+ private $min = array ();
 19+ private $max = array ();
2020
21 - /**
22 - * Add a Field to the SolrDoc
23 - *
24 - * @param type $name of the Field
25 - * @param type $value of the Field
26 - */
27 - public function addField( $name, $value ) {
28 - $this->output .= '<field name="' . $name . '">' . $value . '</field>' ;
29 - }
 21+ /**
 22+ * Add a Field to the SolrDoc
 23+ *
 24+ * @param type $name of the Field
 25+ * @param type $value of the Field
 26+ */
 27+ public function addField( $name, $value ) {
 28+ $this->output .= '<field name="' . $name . '">' . $value . '</field>' ;
 29+ }
3030
31 - /**
32 - * This Function gets a Multivalued Field and splits it into a max and a min value for Sorting
33 - *
34 - * @param type $name of the Field
35 - * @param type $value of the Field
36 - */
37 - public function addSortField( $name, $value ) {
38 - // Does a min/max Field with this name exist ?
39 - if ( isset ( $this->min[$name] ) && isset ( $this->max[$name] ) ) {
40 - if ( strcasecmp( $this->min[$name], $value ) > 0 ) {
41 - // If the new String is Less the Old one replace them
42 - $this->min[$name] = $value;
43 - }
44 - if ( strcasecmp( $this->max[$name], $value ) < 0 ) {
45 - // If the new String is Bigger than Old one replace them
46 - $this->max[$name] = $value;
47 - }
48 - } else {
49 - $this->min[$name] = $value;
50 - $this->max[$name] = $value;
51 - }
52 - }
 31+ /**
 32+ * This Function gets a Multivalued Field and splits it into a max and a min value for Sorting
 33+ *
 34+ * @param type $name of the Field
 35+ * @param type $value of the Field
 36+ */
 37+ public function addSortField( $name, $value ) {
 38+ // Does a min/max Field with this name exist ?
 39+ if ( isset ( $this->min[$name] ) && isset ( $this->max[$name] ) ) {
 40+ if ( strcasecmp( $this->min[$name], $value ) > 0 ) {
 41+ // If the new String is Less the Old one replace them
 42+ $this->min[$name] = $value;
 43+ }
 44+ if ( strcasecmp( $this->max[$name], $value ) < 0 ) {
 45+ // If the new String is Bigger than Old one replace them
 46+ $this->max[$name] = $value;
 47+ }
 48+ } else {
 49+ $this->min[$name] = $value;
 50+ $this->max[$name] = $value;
 51+ }
 52+ }
5353
54 - public function printFields() {
55 - $all = $this->output;
 54+ public function printFields() {
 55+ $all = $this->output;
5656
57 - foreach ( $this->min as $name => $value ) {
58 - $all .= '<field name="' . $name . 'min">' . $value . '</field>' ;
59 - }
60 - foreach ( $this->max as $name => $value ) {
61 - $all .= '<field name="' . $name . 'max">' . $value . '</field>' ;
62 - }
 57+ foreach ( $this->min as $name => $value ) {
 58+ $all .= '<field name="' . $name . 'min">' . $value . '</field>' ;
 59+ }
 60+ foreach ( $this->max as $name => $value ) {
 61+ $all .= '<field name="' . $name . 'max">' . $value . '</field>' ;
 62+ }
6363
64 - return $all;
65 - }
 64+ return $all;
 65+ }
6666 }
Index: trunk/extensions/SolrStore/SolrSearch.php
@@ -14,721 +14,721 @@
1515 */
1616 class SolrSearch extends SearchEngine {
1717
18 - var $limit = 10;
19 - var $offset = 0;
20 - var $prefix = '';
21 - var $searchTerms = array();
22 - var $namespaces = array( NS_MAIN );
23 - var $showRedirects = false;
24 - var $solrTalker;
 18+ var $limit = 10;
 19+ var $offset = 0;
 20+ var $prefix = '';
 21+ var $searchTerms = array();
 22+ var $namespaces = array( NS_MAIN );
 23+ var $showRedirects = false;
 24+ var $solrTalker;
2525
26 - function __construct( $db = null ) {
27 - global $wgSolrTalker;
28 - }
 26+ function __construct( $db = null ) {
 27+ global $wgSolrTalker;
 28+ }
2929
30 - /**
31 - * Perform a full text search query and return a result set.
32 - * If title searches are not supported or disabled, return null.
33 - *
34 - * @param string $term - Raw search term
35 - * @return SolrSearchSet
36 - * @access public
37 - */
38 - function searchText( $term ) {
39 - return SolrSearchSet::newFromQuery( isset( $this->related ) ? 'related' : 'search', $term, $this->namespaces, $this->limit, $this->offset, $this->searchingEverything() );
40 - }
 30+ /**
 31+ * Perform a full text search query and return a result set.
 32+ * If title searches are not supported or disabled, return null.
 33+ *
 34+ * @param string $term - Raw search term
 35+ * @return SolrSearchSet
 36+ * @access public
 37+ */
 38+ function searchText( $term ) {
 39+ return SolrSearchSet::newFromQuery( isset( $this->related ) ? 'related' : 'search', $term, $this->namespaces, $this->limit, $this->offset, $this->searchingEverything() );
 40+ }
4141
42 - /**
43 - * Perform a title-only search query and return a result set.
44 - *
45 - * @param string $term - Raw search term
46 - * @return SolrSearchSet
47 - * @access public
48 - */
49 - function searchTitle( $term ) {
50 - return null;
51 - }
 42+ /**
 43+ * Perform a title-only search query and return a result set.
 44+ *
 45+ * @param string $term - Raw search term
 46+ * @return SolrSearchSet
 47+ * @access public
 48+ */
 49+ function searchTitle( $term ) {
 50+ return null;
 51+ }
5252
53 - /**
54 - * PrefixSearchBackend override for OpenSearch results
55 - */
56 - static function prefixSearch( $ns, $search, $limit, &$results ) {
57 - echo "Prefix Search!<br/>";
58 - $it = SolrSearchSet::newFromQuery( 'prefix', $search, $ns, $limit, 0 );
59 - $results = array();
60 - if ( $it ) { // $it can be null
61 - while ( $res = $it->next() ) {
62 - $results[] = $res->getTitle()->getPrefixedText();
63 - }
64 - }
65 - return false;
66 - }
 53+ /**
 54+ * PrefixSearchBackend override for OpenSearch results
 55+ */
 56+ static function prefixSearch( $ns, $search, $limit, &$results ) {
 57+ echo "Prefix Search!<br/>";
 58+ $it = SolrSearchSet::newFromQuery( 'prefix', $search, $ns, $limit, 0 );
 59+ $results = array();
 60+ if ( $it ) { // $it can be null
 61+ while ( $res = $it->next() ) {
 62+ $results[] = $res->getTitle()->getPrefixedText();
 63+ }
 64+ }
 65+ return false;
 66+ }
6767
68 - /**
69 - * Check if we are searching all the namespaces on this wiki
70 - *
71 - * @return boolean
72 - */
73 - function searchingEverything() {
74 - return $this->namespaces == array_keys( SearchEngine::searchableNamespaces() );
75 - }
 68+ /**
 69+ * Check if we are searching all the namespaces on this wiki
 70+ *
 71+ * @return boolean
 72+ */
 73+ function searchingEverything() {
 74+ return $this->namespaces == array_keys( SearchEngine::searchableNamespaces() );
 75+ }
7676
77 - /**
78 - * Prepare query for the Solr-search daemon:
79 - *
80 - * 1) rewrite namespaces into standardized form
81 - * e.g. image:clouds -> [6]:clouds
82 - *
83 - * 2) rewrite localizations of "search everything" keyword
84 - * e.g. alle:heidegger -> all:heidegger
85 - *
86 - * @param string query
87 - * @return string rewritten query
88 - * @access private
89 - */
90 - function replacePrefixes( $query ) {
91 - global $wgContLang, $wgSolrUseRelated;
92 - $fname = 'SolrSearch::replacePrefixes';
93 - wfProfileIn( $fname );
94 - $start = 0;
95 - $len = 0; // token start pos and length
96 - $rewritten = ''; // rewritten query
97 - $rindex = 0; // point to last rewritten character
98 - $inquotes = false;
 77+ /**
 78+ * Prepare query for the Solr-search daemon:
 79+ *
 80+ * 1) rewrite namespaces into standardized form
 81+ * e.g. image:clouds -> [6]:clouds
 82+ *
 83+ * 2) rewrite localizations of "search everything" keyword
 84+ * e.g. alle:heidegger -> all:heidegger
 85+ *
 86+ * @param string query
 87+ * @return string rewritten query
 88+ * @access private
 89+ */
 90+ function replacePrefixes( $query ) {
 91+ global $wgContLang, $wgSolrUseRelated;
 92+ $fname = 'SolrSearch::replacePrefixes';
 93+ wfProfileIn( $fname );
 94+ $start = 0;
 95+ $len = 0; // token start pos and length
 96+ $rewritten = ''; // rewritten query
 97+ $rindex = 0; // point to last rewritten character
 98+ $inquotes = false;
9999
100100 // "search everything" keyword
101 - $allkeyword = wfMsgForContent( 'searchall' );
 101+ $allkeyword = wfMsgForContent( 'searchall' );
102102
103 - $qlen = strlen( $query );
 103+ $qlen = strlen( $query );
104104
105105 // quick check, most of the time we don't need any rewriting
106 - if ( strpos( $query, ':' ) === false ) {
107 - wfProfileOut( $fname );
108 - return $query;
109 - }
 106+ if ( strpos( $query, ':' ) === false ) {
 107+ wfProfileOut( $fname );
 108+ return $query;
 109+ }
110110
111111 // check if this is query for related articles
112 - $relatedkey = wfMsgForContent( 'searchrelated' ) . ':';
113 - if ( $wgSolrUseRelated && strncmp( $query, $relatedkey, strlen( $relatedkey ) ) == 0 ) {
114 - $this->related = true;
115 - list( $dummy, $ret ) = explode( ":", $query, 2 );
116 - wfProfileOut( $fname );
117 - return trim( $ret );
118 - }
 112+ $relatedkey = wfMsgForContent( 'searchrelated' ) . ':';
 113+ if ( $wgSolrUseRelated && strncmp( $query, $relatedkey, strlen( $relatedkey ) ) == 0 ) {
 114+ $this->related = true;
 115+ list( $dummy, $ret ) = explode( ":", $query, 2 );
 116+ wfProfileOut( $fname );
 117+ return trim( $ret );
 118+ }
119119
120 - global $wgCanonicalNamespaceNames, $wgNamespaceAliases;
121 - $nsNamesRaw = array_merge( $wgContLang->getNamespaces(), $wgCanonicalNamespaceNames, array_keys( array_merge( $wgNamespaceAliases, $wgContLang->getNamespaceAliases() ) ) );
 120+ global $wgCanonicalNamespaceNames, $wgNamespaceAliases;
 121+ $nsNamesRaw = array_merge( $wgContLang->getNamespaces(), $wgCanonicalNamespaceNames, array_keys( array_merge( $wgNamespaceAliases, $wgContLang->getNamespaceAliases() ) ) );
122122
123123 # add all namespace names w/o spaces
124 - $nsNames = array();
125 - foreach ( $nsNamesRaw as $ns ) {
126 - if ( $ns != '' ) {
127 - $nsNames[] = $ns;
128 - $nsNames[] = str_replace( '_', ' ', $ns );
129 - }
130 - }
 124+ $nsNames = array();
 125+ foreach ( $nsNamesRaw as $ns ) {
 126+ if ( $ns != '' ) {
 127+ $nsNames[] = $ns;
 128+ $nsNames[] = str_replace( '_', ' ', $ns );
 129+ }
 130+ }
131131
132 - $regexp = implode( '|', array_unique( $nsNames ) );
 132+ $regexp = implode( '|', array_unique( $nsNames ) );
133133
134134 # rewrite the query by replacing valid namespace names
135 - $parts = preg_split( '/(")/', $query, -1, PREG_SPLIT_DELIM_CAPTURE );
136 - $inquotes = false;
137 - $rewritten = '';
138 - foreach ( $parts as $part ) {
139 - if ( $part == '"' ) { # stuff in quote doesnt get rewritten
140 - $rewritten .= $part;
141 - $inquotes = !$inquotes;
142 - } elseif ( $inquotes ) {
143 - $rewritten .= $part;
144 - } else {
 135+ $parts = preg_split( '/(")/', $query, -1, PREG_SPLIT_DELIM_CAPTURE );
 136+ $inquotes = false;
 137+ $rewritten = '';
 138+ foreach ( $parts as $part ) {
 139+ if ( $part == '"' ) { # stuff in quote doesnt get rewritten
 140+ $rewritten .= $part;
 141+ $inquotes = !$inquotes;
 142+ } elseif ( $inquotes ) {
 143+ $rewritten .= $part;
 144+ } else {
145145 # replace namespaces
146 - $r = preg_replace_callback( '/(^|[| :])(' . $regexp . '):/i', array( $this, 'replaceNamespace' ), $part );
 146+ $r = preg_replace_callback( '/(^|[| :])(' . $regexp . '):/i', array( $this, 'replaceNamespace' ), $part );
147147 # replace to backend all: notation
148 - $rewritten .= str_replace( $allkeyword . ':', 'all:', $r );
149 - }
150 - }
151 - wfProfileOut( $fname );
152 - return $rewritten;
153 - }
 148+ $rewritten .= str_replace( $allkeyword . ':', 'all:', $r );
 149+ }
 150+ }
 151+ wfProfileOut( $fname );
 152+ return $rewritten;
 153+ }
154154
155 - /** callback to replace namespace names to internal notation, e.g. User: -> [2]: */
156 - function replaceNamespace( $matches ) {
157 - global $wgContLang;
158 - $inx = $wgContLang->getNsIndex( str_replace( ' ', '_', $matches[2] ) );
159 - if ( $inx === false )
160 - return $matches[0];
161 - else
162 - return $matches[1] . "[$inx]:";
163 - }
 155+ /** callback to replace namespace names to internal notation, e.g. User: -> [2]: */
 156+ function replaceNamespace( $matches ) {
 157+ global $wgContLang;
 158+ $inx = $wgContLang->getNsIndex( str_replace( ' ', '_', $matches[2] ) );
 159+ if ( $inx === false )
 160+ return $matches[0];
 161+ else
 162+ return $matches[1] . "[$inx]:";
 163+ }
164164
165 - function acceptListRedirects() {
166 - return false;
167 - }
 165+ function acceptListRedirects() {
 166+ return false;
 167+ }
168168
169 - /** Merge the prefix into the query (if any) */
170 - function transformSearchTerm( $term ) {
171 - global $wgSolrSearchVersion;
 169+ /** Merge the prefix into the query (if any) */
 170+ function transformSearchTerm( $term ) {
 171+ global $wgSolrSearchVersion;
172172
173 - if ( $wgSolrSearchVersion >= 2.1 && $this->prefix != '' ) {
 173+ if ( $wgSolrSearchVersion >= 2.1 && $this->prefix != '' ) {
174174 # convert to internal backend prefix notation
175 - $term = $term . ' prefix:' . $this->prefix;
176 - }
177 - return $term;
178 - }
 175+ $term = $term . ' prefix:' . $this->prefix;
 176+ }
 177+ return $term;
 178+ }
179179
180180 }
181181
182182 class SolrResult extends SearchResult {
183183
184 - /**
185 - * Construct a result object from single result line
186 - *
187 - * @param array $lines
188 - * @param string $method - method used to fetch these results
189 - * @return array (float, Title)
190 - * @access private
191 - */
192 - function isMissingRevision() {
193 - return false;
194 - }
 184+ /**
 185+ * Construct a result object from single result line
 186+ *
 187+ * @param array $lines
 188+ * @param string $method - method used to fetch these results
 189+ * @return array (float, Title)
 190+ * @access private
 191+ */
 192+ function isMissingRevision() {
 193+ return false;
 194+ }
195195
196 - function SolrResult( $result, $method ) {
197 - global $wgContLang;
 196+ function SolrResult( $result, $method ) {
 197+ global $wgContLang;
198198
199 - $score = null;
200 - $interwiki = null;
201 - $namespace = null;
202 - $title = null;
 199+ $score = null;
 200+ $interwiki = null;
 201+ $namespace = null;
 202+ $title = null;
203203
204 - $xml = $result;
205 - wfDebug( "Solr line: '$result'\n" );
 204+ $xml = $result;
 205+ wfDebug( "Solr line: '$result'\n" );
206206
207 - // Defining Results
 207+ // Defining Results
208208
209 - $this->mDate = null;
210 - $score = $xml->float;
211 - $this->mScore = $score;
 209+ $this->mDate = null;
 210+ $score = $xml->float;
 211+ $this->mScore = $score;
212212
213213
214 - // -------------------------------------
215 - // Get The Shit out of da XML
216 - // -------------------------------------
217 - foreach ( $xml->arr as $doc ) {
218 - switch ( $doc['name'] ) {
219 - case 'text':
220 - $nsText = $doc->str;
 214+ // -------------------------------------
 215+ // Get The Shit out of da XML
 216+ // -------------------------------------
 217+ foreach ( $xml->arr as $doc ) {
 218+ switch ( $doc['name'] ) {
 219+ case 'text':
 220+ $nsText = $doc->str;
221221
222 - $this->mSize = "";
223 - $this->mWordCount = count( $doc->str );
224 - $snipmax = 10;
225 - $textsnip = "";
226 - $textsnipvar = 0;
227 - foreach ( $doc->str as $inner ) {
228 - $textsnipvar++;
229 - if ( $textsnipvar >= 4 && $textsnipvar <= $snipmax ) {
230 - $textsnip .= " " . $inner;
231 - }
232 - $this->mSize = $this->mSize + strlen( $inner );
233 - }
234 - $textsnip .= "...";
235 - $this->mSize = ( $this->mSize / 3 );
236 - // $this->mSize=$size;
237 - break;
238 - case 'Zuletzt geändert_dt':
239 - $this->mDate = $doc->date;
240 - break;
241 - }
242 - }
 222+ $this->mSize = "";
 223+ $this->mWordCount = count( $doc->str );
 224+ $snipmax = 10;
 225+ $textsnip = "";
 226+ $textsnipvar = 0;
 227+ foreach ( $doc->str as $inner ) {
 228+ $textsnipvar++;
 229+ if ( $textsnipvar >= 4 && $textsnipvar <= $snipmax ) {
 230+ $textsnip .= " " . $inner;
 231+ }
 232+ $this->mSize = $this->mSize + strlen( $inner );
 233+ }
 234+ $textsnip .= "...";
 235+ $this->mSize = ( $this->mSize / 3 );
 236+ // $this->mSize=$size;
 237+ break;
 238+ case 'Zuletzt geändert_dt':
 239+ $this->mDate = $doc->date;
 240+ break;
 241+ }
 242+ }
243243
244 - foreach ( $xml->str as $docs ) {
245 - switch ( $docs['name'] ) {
246 - case 'pagetitle':
247 - $this->mTitle = $doc->str;
248 - break;
249 - case 'dbkey':
250 - $title = $doc->str;
251 - break;
252 - case 'interwiki':
253 - $this->mInterwiki = $doc->str;
254 - break;
255 - }
256 - }
257 - foreach ( $xml->int as $doci ) {
258 - switch ( $doci['name'] ) {
259 - case 'namespace':
260 - $namespace = $doc->str;
261 - break;
262 - }
263 - }
 244+ foreach ( $xml->str as $docs ) {
 245+ switch ( $docs['name'] ) {
 246+ case 'pagetitle':
 247+ $this->mTitle = $doc->str;
 248+ break;
 249+ case 'dbkey':
 250+ $title = $doc->str;
 251+ break;
 252+ case 'interwiki':
 253+ $this->mInterwiki = $doc->str;
 254+ break;
 255+ }
 256+ }
 257+ foreach ( $xml->int as $doci ) {
 258+ switch ( $doci['name'] ) {
 259+ case 'namespace':
 260+ $namespace = $doc->str;
 261+ break;
 262+ }
 263+ }
264264
265 - $title = urldecode( $title );
266 - if ( !isset( $nsText ) )
267 - $nsText = $wgContLang->getNsText( $namespace );
268 - else
269 - $nsText = urldecode( $nsText );
 265+ $title = urldecode( $title );
 266+ if ( !isset( $nsText ) )
 267+ $nsText = $wgContLang->getNsText( $namespace );
 268+ else
 269+ $nsText = urldecode( $nsText );
270270
271 - // make title
272 - $this->mTitle = Title::makeTitle( $namespace, $title );
 271+ // make title
 272+ $this->mTitle = Title::makeTitle( $namespace, $title );
273273
274 - // HIGHLIHT
275 - // <em> & </em> Fix to <b> // if not, no highlighting !!
276 - // TITLE (LINK)
277 - if ( $xml->highlight->title != '' ) {
278 - $this->mHighlightTitle = str_replace( "<em>", "<b>", $xml->highlight->title );
279 - $this->mHighlightTitle = str_replace( "</em>", "</b>", $this->mHighlightTitle );
280 - } else {
281 - $this->mHighlightTitle = '';
282 - }
283 - // TEXT (under Link)
284 - // $this->mHighlightText=$xml->highlight->title;
285 - if ( $xml->highlight->Inhalt != '' ) {
286 - $this->mHighlightText = str_replace( "<em>", "<b>", $xml->highlight->Inhalt );
287 - $this->mHighlightText = str_replace( "</em>", "</b>", $this->mHighlightText );
288 - $this->mHighlightText .= "...";
289 - } else {// $this->mHighlightText=textsnip;
290 - if ( isset( $_REQUEST['search'] ) != '' && isset( $textsnip ) != '' ) {
291 - if ( strpos( strtolower( $textsnip ), strtolower( $_REQUEST['search'] ) ) ) {
292 - $tempc = strlen( $_REQUEST['search'] );
293 - $pos1 = strpos( strtolower( $textsnip ), strtolower( $_REQUEST['search'] ) );
294 - $tmpa = substr( $textsnip, 0, $pos1 );
295 - $tmpb = substr( $textsnip, ( $pos1 + $tempc ) );
296 - $this->mHighlightText = $tmpa . "<b>" . substr( $textsnip, $pos1, $tempc ) . "</b>" . $tmpb;
297 - // str_replace($_REQUEST['search'],"<b>".$_REQUEST['search']."</b>",$textsnip);
298 - } else {
299 - $this->mHighlightText = $textsnip;
300 - }
301 - } else {
302 - $this->mHighlightText = $textsnip;
303 - }
304 - }
305 - $this->mRedirectTitle = null;
306 - $this->mHighlightSection = null;
307 - $this->mSectionTitle = null;
308 - }
 274+ // HIGHLIHT
 275+ // <em> & </em> Fix to <b> // if not, no highlighting !!
 276+ // TITLE (LINK)
 277+ if ( $xml->highlight->title != '' ) {
 278+ $this->mHighlightTitle = str_replace( "<em>", "<b>", $xml->highlight->title );
 279+ $this->mHighlightTitle = str_replace( "</em>", "</b>", $this->mHighlightTitle );
 280+ } else {
 281+ $this->mHighlightTitle = '';
 282+ }
 283+ // TEXT (under Link)
 284+ // $this->mHighlightText=$xml->highlight->title;
 285+ if ( $xml->highlight->Inhalt != '' ) {
 286+ $this->mHighlightText = str_replace( "<em>", "<b>", $xml->highlight->Inhalt );
 287+ $this->mHighlightText = str_replace( "</em>", "</b>", $this->mHighlightText );
 288+ $this->mHighlightText .= "...";
 289+ } else {// $this->mHighlightText=textsnip;
 290+ if ( isset( $_REQUEST['search'] ) != '' && isset( $textsnip ) != '' ) {
 291+ if ( strpos( strtolower( $textsnip ), strtolower( $_REQUEST['search'] ) ) ) {
 292+ $tempc = strlen( $_REQUEST['search'] );
 293+ $pos1 = strpos( strtolower( $textsnip ), strtolower( $_REQUEST['search'] ) );
 294+ $tmpa = substr( $textsnip, 0, $pos1 );
 295+ $tmpb = substr( $textsnip, ( $pos1 + $tempc ) );
 296+ $this->mHighlightText = $tmpa . "<b>" . substr( $textsnip, $pos1, $tempc ) . "</b>" . $tmpb;
 297+ // str_replace($_REQUEST['search'],"<b>".$_REQUEST['search']."</b>",$textsnip);
 298+ } else {
 299+ $this->mHighlightText = $textsnip;
 300+ }
 301+ } else {
 302+ $this->mHighlightText = $textsnip;
 303+ }
 304+ }
 305+ $this->mRedirectTitle = null;
 306+ $this->mHighlightSection = null;
 307+ $this->mSectionTitle = null;
 308+ }
309309
310 - /**
311 - * Get the pair [highlighted snippet, unmodified text] for highlighted text
312 - *
313 - * @param string $lines
314 - * @param string $nsText textual form of namespace
315 - * @param string $type
316 - * @param boolean $useFinalSeparator
317 - * @return array (highlighted, unmodified text)
318 - */
319 - function extractSnippet( $lines, $nsText, $type, $useFinalSeparator = false ) {
320 - if ( !array_key_exists( $type, $lines ) )
321 - return array( null, null );
322 - $ret = "";
323 - $original = null;
324 - foreach ( $lines[$type] as $h ) {
325 - list( $s, $o ) = $this->extractSnippetLine( $h, $useFinalSeparator );
326 - $ret .= $s;
327 - $original = $o;
328 - }
329 - if ( $nsText != '' )
330 - $ret = $nsText . ':' . $ret;
331 - return array( $ret, $original );
332 - }
 310+ /**
 311+ * Get the pair [highlighted snippet, unmodified text] for highlighted text
 312+ *
 313+ * @param string $lines
 314+ * @param string $nsText textual form of namespace
 315+ * @param string $type
 316+ * @param boolean $useFinalSeparator
 317+ * @return array (highlighted, unmodified text)
 318+ */
 319+ function extractSnippet( $lines, $nsText, $type, $useFinalSeparator = false ) {
 320+ if ( !array_key_exists( $type, $lines ) )
 321+ return array( null, null );
 322+ $ret = "";
 323+ $original = null;
 324+ foreach ( $lines[$type] as $h ) {
 325+ list( $s, $o ) = $this->extractSnippetLine( $h, $useFinalSeparator );
 326+ $ret .= $s;
 327+ $original = $o;
 328+ }
 329+ if ( $nsText != '' )
 330+ $ret = $nsText . ':' . $ret;
 331+ return array( $ret, $original );
 332+ }
333333
334 - /**
335 - * Parse one line of a snippet
336 - *
337 - * @param string $line
338 - * @param boolean $useFinalSeparator if "..." is to be appended to the end of snippet
339 - * @access protected
340 - * @return array(snippet,unmodified text)
341 - */
342 - function extractSnippetLine( $line, $useFinalSeparator ) {
343 - $parts = explode( " ", $line );
344 - if ( count( $parts ) != 4 && count( $parts ) != 5 ) {
345 - wfDebug( "Bad result line:" . $line . "\n" );
346 - return "";
347 - }
348 - $splits = $this->stripBracketsSplit( $parts[0] );
349 - $highlight = $this->stripBracketsSplit( $parts[1] );
350 - $suffix = urldecode( $this->stripBrackets( $parts[2] ) );
351 - $text = urldecode( $parts[3] );
352 - $original = null;
353 - if ( count( $parts ) > 4 )
354 - $original = urldecode( $parts[4] );
 334+ /**
 335+ * Parse one line of a snippet
 336+ *
 337+ * @param string $line
 338+ * @param boolean $useFinalSeparator if "..." is to be appended to the end of snippet
 339+ * @access protected
 340+ * @return array(snippet,unmodified text)
 341+ */
 342+ function extractSnippetLine( $line, $useFinalSeparator ) {
 343+ $parts = explode( " ", $line );
 344+ if ( count( $parts ) != 4 && count( $parts ) != 5 ) {
 345+ wfDebug( "Bad result line:" . $line . "\n" );
 346+ return "";
 347+ }
 348+ $splits = $this->stripBracketsSplit( $parts[0] );
 349+ $highlight = $this->stripBracketsSplit( $parts[1] );
 350+ $suffix = urldecode( $this->stripBrackets( $parts[2] ) );
 351+ $text = urldecode( $parts[3] );
 352+ $original = null;
 353+ if ( count( $parts ) > 4 )
 354+ $original = urldecode( $parts[4] );
355355
356 - $splits[] = strlen( $text );
357 - $start = 0;
358 - $snippet = "";
359 - $hi = 0;
360 - $ellipsis = wfMsgForContent( 'ellipsis' );
 356+ $splits[] = strlen( $text );
 357+ $start = 0;
 358+ $snippet = "";
 359+ $hi = 0;
 360+ $ellipsis = wfMsgForContent( 'ellipsis' );
361361
362 - foreach ( $splits as $sp ) {
363 - $sp = intval( $sp );
 362+ foreach ( $splits as $sp ) {
 363+ $sp = intval( $sp );
364364 // highlight words!
365 - while ( $hi < count( $highlight ) && intval( $highlight[$hi] ) < $sp ) {
366 - $s = intval( $highlight[$hi] );
367 - $e = intval( $highlight[$hi + 1] );
368 - $snippet .= substr( $text, $start, $s - $start ) . "<span class='searchmatch'>" . substr( $text, $s, $e - $s ) . "</span>";
369 - $start = $e;
370 - $hi += 2;
371 - }
 365+ while ( $hi < count( $highlight ) && intval( $highlight[$hi] ) < $sp ) {
 366+ $s = intval( $highlight[$hi] );
 367+ $e = intval( $highlight[$hi + 1] );
 368+ $snippet .= substr( $text, $start, $s - $start ) . "<span class='searchmatch'>" . substr( $text, $s, $e - $s ) . "</span>";
 369+ $start = $e;
 370+ $hi += 2;
 371+ }
372372 // copy till split point
373 - $snippet .= substr( $text, $start, $sp - $start );
374 - if ( $sp == strlen( $text ) && $suffix != '' )
375 - $snippet .= $suffix;
376 - else if ( $useFinalSeparator )
377 - $snippet .= " <b>" . $ellipsis . "</b> ";
 373+ $snippet .= substr( $text, $start, $sp - $start );
 374+ if ( $sp == strlen( $text ) && $suffix != '' )
 375+ $snippet .= $suffix;
 376+ else if ( $useFinalSeparator )
 377+ $snippet .= " <b>" . $ellipsis . "</b> ";
378378
379 - $start = $sp;
380 - }
381 - return array( $snippet, $original );
382 - }
 379+ $start = $sp;
 380+ }
 381+ return array( $snippet, $original );
 382+ }
383383
384 - /**
385 - * @access private
386 - */
387 - function stripBrackets( $str ) {
388 - if ( $str == '[]' )
389 - return '';
390 - return substr( $str, 1, strlen( $str ) - 2 );
391 - }
 384+ /**
 385+ * @access private
 386+ */
 387+ function stripBrackets( $str ) {
 388+ if ( $str == '[]' )
 389+ return '';
 390+ return substr( $str, 1, strlen( $str ) - 2 );
 391+ }
392392
393 - /**
394 - * @access private
395 - * @return array
396 - */
397 - function stripBracketsSplit( $str ) {
398 - $strip = $this->stripBrackets( $str );
399 - if ( $strip == '' )
400 - return array();
401 - else
402 - return explode( ",", $strip );
403 - }
 393+ /**
 394+ * @access private
 395+ * @return array
 396+ */
 397+ function stripBracketsSplit( $str ) {
 398+ $strip = $this->stripBrackets( $str );
 399+ if ( $strip == '' )
 400+ return array();
 401+ else
 402+ return explode( ",", $strip );
 403+ }
404404
405 - function getTitle() {
406 - return $this->mTitle;
407 - }
 405+ function getTitle() {
 406+ return $this->mTitle;
 407+ }
408408
409 - function getScore() {
410 - if ( is_null( $this->mScore ) )
411 - return null; // Solr scores are meaningless to the user...
 409+ function getScore() {
 410+ if ( is_null( $this->mScore ) )
 411+ return null; // Solr scores are meaningless to the user...
412412
413413 // echo($this->mScore." ");
414 - return floatval( $this->mScore );
415 - }
 414+ return floatval( $this->mScore );
 415+ }
416416
417 - function getTitleSnippet( $terms ) {
418 - if ( is_null( $this->mHighlightTitle ) )
419 - return '';
420 - return $this->mHighlightTitle;
421 - }
 417+ function getTitleSnippet( $terms ) {
 418+ if ( is_null( $this->mHighlightTitle ) )
 419+ return '';
 420+ return $this->mHighlightTitle;
 421+ }
422422
423 - function getTextSnippet( $terms ) {
424 - if ( is_null( $this->mHighlightText ) )
425 - return parent::getTextSnippet( $terms );
426 - return $this->mHighlightText;
427 - }
 423+ function getTextSnippet( $terms ) {
 424+ if ( is_null( $this->mHighlightText ) )
 425+ return parent::getTextSnippet( $terms );
 426+ return $this->mHighlightText;
 427+ }
428428
429 - function getRedirectSnippet( $terms ) {
430 - /* if (isset($this->mHighlightRedirect))
431 - if (is_null($this->mHighlightRedirect))
432 - return '';
433 - return $this->mHighlightRedirect;
434 - */
435 - return null;
436 - }
 429+ function getRedirectSnippet( $terms ) {
 430+ /* if (isset($this->mHighlightRedirect))
 431+ if (is_null($this->mHighlightRedirect))
 432+ return '';
 433+ return $this->mHighlightRedirect;
 434+ */
 435+ return null;
 436+ }
437437
438 - function getRedirectTitle() {
439 - return $this->mRedirectTitle;
440 - }
 438+ function getRedirectTitle() {
 439+ return $this->mRedirectTitle;
 440+ }
441441
442 - function getSectionSnippet() {
443 - if ( is_null( $this->mHighlightSection ) )
444 - return null;
445 - return $this->mHighlightSection;
446 - }
 442+ function getSectionSnippet() {
 443+ if ( is_null( $this->mHighlightSection ) )
 444+ return null;
 445+ return $this->mHighlightSection;
 446+ }
447447
448 - function getSectionTitle() {
449 - if ( is_null( $this->mSectionTitle ) )
450 - return null;
451 - return $this->mSectionTitle;
452 - }
 448+ function getSectionTitle() {
 449+ if ( is_null( $this->mSectionTitle ) )
 450+ return null;
 451+ return $this->mSectionTitle;
 452+ }
453453
454 - function getInterwikiPrefix() {
455 - return $this->mInterwiki;
456 - }
 454+ function getInterwikiPrefix() {
 455+ return $this->mInterwiki;
 456+ }
457457
458 - function isInterwiki() {
459 - return $this->mInterwiki != '';
460 - }
 458+ function isInterwiki() {
 459+ return $this->mInterwiki != '';
 460+ }
461461
462 - function getTimestamp() {
463 - if ( is_null( $this->mDate ) )
464 - return parent::getTimestamp();
465 - return $this->mDate;
466 - }
 462+ function getTimestamp() {
 463+ if ( is_null( $this->mDate ) )
 464+ return parent::getTimestamp();
 465+ return $this->mDate;
 466+ }
467467
468 - function getWordCount() {
469 - if ( is_null( $this->mWordCount ) )
470 - return parent::getWordCount();
471 - return $this->mWordCount;
472 - }
 468+ function getWordCount() {
 469+ if ( is_null( $this->mWordCount ) )
 470+ return parent::getWordCount();
 471+ return $this->mWordCount;
 472+ }
473473
474 - function getByteSize() {
475 - if ( is_null( $this->mSize ) )
476 - return parent::getByteSize();
477 - return $this->mSize;
478 - }
 474+ function getByteSize() {
 475+ if ( is_null( $this->mSize ) )
 476+ return parent::getByteSize();
 477+ return $this->mSize;
 478+ }
479479
480 - function hasRelated() {
481 - global $wgSolrSearchVersion, $wgSolrUseRelated;
482 - return $wgSolrSearchVersion >= 2.1 && $wgSolrUseRelated;
483 - }
 480+ function hasRelated() {
 481+ global $wgSolrSearchVersion, $wgSolrUseRelated;
 482+ return $wgSolrSearchVersion >= 2.1 && $wgSolrUseRelated;
 483+ }
484484
485485 }
486486
487487 class SolrSearchSet extends SearchResultSet {
488488
489 - /**
490 - * Contact the MWDaemon search server and return a wrapper
491 - * object with the set of results. Results may be cached.
492 - *
493 - * @param string $method The protocol verb to use
494 - * @param string $query
495 - * @param int $limit
496 - * @param int $offset
497 - * @param bool $searchAll
498 - * @return array
499 - * @access public
500 - */
501 - static function newFromQuery( $method, $query, $namespaces = array(), $limit = 20, $offset = 0, $searchAll = False ) {
502 - $fname = 'SolrSearchSet::newFromQuery';
503 - wfProfileIn( $fname );
 489+ /**
 490+ * Contact the MWDaemon search server and return a wrapper
 491+ * object with the set of results. Results may be cached.
 492+ *
 493+ * @param string $method The protocol verb to use
 494+ * @param string $query
 495+ * @param int $limit
 496+ * @param int $offset
 497+ * @param bool $searchAll
 498+ * @return array
 499+ * @access public
 500+ */
 501+ static function newFromQuery( $method, $query, $namespaces = array(), $limit = 20, $offset = 0, $searchAll = False ) {
 502+ $fname = 'SolrSearchSet::newFromQuery';
 503+ wfProfileIn( $fname );
504504
505 - $wgSolrTalker = new SolrTalker();
 505+ $wgSolrTalker = new SolrTalker();
506506
507 - $query = $wgSolrTalker->queryChecker( $query );
508 - $xml = $wgSolrTalker->solrQuery( $query, $offset, $limit, true, true ); // Abfrage ok, ergebniss in XML
509 - $totalHits = $xml->result['numFound'];
 507+ $query = $wgSolrTalker->queryChecker( $query );
 508+ $xml = $wgSolrTalker->solrQuery( $query, $offset, $limit, true, true ); // Abfrage ok, ergebniss in XML
 509+ $totalHits = $xml->result['numFound'];
510510
511 - $resultLines = array(); ;
 511+ $resultLines = array(); ;
512512
513 - $highl = $xml->xpath( '//lst[@name="highlighting"]/lst' );
 513+ $highl = $xml->xpath( '//lst[@name="highlighting"]/lst' );
514514
515 - $hli = 0;
 515+ $hli = 0;
516516
517 - foreach ( $xml->result->doc as $doc ) {
 517+ foreach ( $xml->result->doc as $doc ) {
518518
519 - if ( isset( $highl[$hli]->arr ) ) {
 519+ if ( isset( $highl[$hli]->arr ) ) {
520520
521 - foreach ( $highl[$hli]->arr as $feld ) {
522 - if ( isset( $feld['name'] ) ) {
 521+ foreach ( $highl[$hli]->arr as $feld ) {
 522+ if ( isset( $feld['name'] ) ) {
523523
524 - switch ( $feld['name'] ) {
 524+ switch ( $feld['name'] ) {
525525
526 - case 'title':
527 - $doc[]->highlight->title = $feld->str;
528 - break;
529 - case 'Inhalt de_t':
530 - $doc[]->highlight->Inhalt = $feld->str;
531 - break;
532 - }
533 - }
534 - }
535 - }
536 - $hli++;
537 - $resultLines[] = $doc;
538 - }
 526+ case 'title':
 527+ $doc[]->highlight->title = $feld->str;
 528+ break;
 529+ case 'Inhalt de_t':
 530+ $doc[]->highlight->Inhalt = $feld->str;
 531+ break;
 532+ }
 533+ }
 534+ }
 535+ }
 536+ $hli++;
 537+ $resultLines[] = $doc;
 538+ }
539539
540540
541 - $suggestion = null;
542 - $info = null;
543 - $interwiki = null;
 541+ $suggestion = null;
 542+ $info = null;
 543+ $interwiki = null;
544544
545545
546 - $resultSet = new SolrSearchSet( $method, $query, $resultLines, count( $resultLines ), $totalHits,
547 - $suggestion, $info, $interwiki );
 546+ $resultSet = new SolrSearchSet( $method, $query, $resultLines, count( $resultLines ), $totalHits,
 547+ $suggestion, $info, $interwiki );
548548
549 - wfProfileOut( $fname );
550 - return $resultSet;
551 - }
 549+ wfProfileOut( $fname );
 550+ return $resultSet;
 551+ }
552552
553 - static function startsWith( $source, $prefix ) {
554 - return strncmp( $source, $prefix, strlen( $prefix ) ) == 0;
555 - }
 553+ static function startsWith( $source, $prefix ) {
 554+ return strncmp( $source, $prefix, strlen( $prefix ) ) == 0;
 555+ }
556556
557 - /**
558 - * Private constructor. Use SolrSearchSet::newFromQuery().
559 - *
560 - * @param string $method
561 - * @param string $query
562 - * @param array $lines
563 - * @param int $resultCount
564 - * @param int $totalHits
565 - * @param string $suggestion
566 - * @param string $info
567 - * @access private
568 - */
569 - function SolrSearchSet( $method, $query, $lines, $resultCount, $totalHits = null, $suggestion = null, $info = null, $interwiki = null ) {
570 - $this->mMethod = $method;
571 - $this->mQuery = $query;
572 - $this->mTotalHits = $totalHits;
573 - $this->mResults = $lines;
574 - $this->mResultCount = $resultCount;
575 - $this->mPos = 0;
576 - $this->mSuggestionQuery = null;
577 - $this->mSuggestionSnippet = '';
578 - $this->parseSuggestion( $suggestion );
579 - $this->mInfo = $info;
580 - $this->mInterwiki = $interwiki;
581 - }
 557+ /**
 558+ * Private constructor. Use SolrSearchSet::newFromQuery().
 559+ *
 560+ * @param string $method
 561+ * @param string $query
 562+ * @param array $lines
 563+ * @param int $resultCount
 564+ * @param int $totalHits
 565+ * @param string $suggestion
 566+ * @param string $info
 567+ * @access private
 568+ */
 569+ function SolrSearchSet( $method, $query, $lines, $resultCount, $totalHits = null, $suggestion = null, $info = null, $interwiki = null ) {
 570+ $this->mMethod = $method;
 571+ $this->mQuery = $query;
 572+ $this->mTotalHits = $totalHits;
 573+ $this->mResults = $lines;
 574+ $this->mResultCount = $resultCount;
 575+ $this->mPos = 0;
 576+ $this->mSuggestionQuery = null;
 577+ $this->mSuggestionSnippet = '';
 578+ $this->parseSuggestion( $suggestion );
 579+ $this->mInfo = $info;
 580+ $this->mInterwiki = $interwiki;
 581+ }
582582
583 - /** Get suggestions from a suggestion result line */
584 - function parseSuggestion( $suggestion ) {
585 - if ( is_null( $suggestion ) )
586 - return;
 583+ /** Get suggestions from a suggestion result line */
 584+ function parseSuggestion( $suggestion ) {
 585+ if ( is_null( $suggestion ) )
 586+ return;
587587 // parse split points and highlight changes
588 - list( $dummy, $points, $sug ) = explode( " ", $suggestion );
589 - $sug = urldecode( $sug );
590 - $points = explode( ",", substr( $points, 1, -1 ) );
591 - array_unshift( $points, 0 );
592 - $suggestText = "";
593 - for ( $i = 1; $i < count( $points ); $i += 2 ) {
594 - $suggestText .= htmlspecialchars( substr( $sug, $points[$i - 1], $points[$i] - $points[$i - 1] ) );
595 - $suggestText .= '<em>' . htmlspecialchars( substr( $sug, $points[$i], $points[$i + 1] - $points[$i] ) ) . "</em>";
596 - }
597 - $suggestText .= htmlspecialchars( substr( $sug, end( $points ) ) );
 588+ list( $dummy, $points, $sug ) = explode( " ", $suggestion );
 589+ $sug = urldecode( $sug );
 590+ $points = explode( ",", substr( $points, 1, -1 ) );
 591+ array_unshift( $points, 0 );
 592+ $suggestText = "";
 593+ for ( $i = 1; $i < count( $points ); $i += 2 ) {
 594+ $suggestText .= htmlspecialchars( substr( $sug, $points[$i - 1], $points[$i] - $points[$i - 1] ) );
 595+ $suggestText .= '<em>' . htmlspecialchars( substr( $sug, $points[$i], $points[$i + 1] - $points[$i] ) ) . "</em>";
 596+ }
 597+ $suggestText .= htmlspecialchars( substr( $sug, end( $points ) ) );
598598
599 - $this->mSuggestionQuery = $this->replaceGenericPrefixes( $sug );
600 - $this->mSuggestionSnippet = $this->replaceGenericPrefixes( $suggestText );
601 - }
 599+ $this->mSuggestionQuery = $this->replaceGenericPrefixes( $sug );
 600+ $this->mSuggestionSnippet = $this->replaceGenericPrefixes( $suggestText );
 601+ }
602602
603 - /** replace prefixes like [2]: that are not in phrases */
604 - function replaceGenericPrefixes( $text ) {
605 - $out = "";
606 - $phrases = explode( '"', $text );
607 - for ( $i = 0; $i < count( $phrases ); $i += 2 ) {
608 - $out .= preg_replace_callback( '/\[([0-9]+)\]:/', array( $this, 'genericPrefixCallback' ), $phrases[$i] );
609 - if ( $i + 1 < count( $phrases ) )
610 - $out .= '"' . $phrases[$i + 1] . '"'; // phrase text
611 - }
612 - return $out;
613 - }
 603+ /** replace prefixes like [2]: that are not in phrases */
 604+ function replaceGenericPrefixes( $text ) {
 605+ $out = "";
 606+ $phrases = explode( '"', $text );
 607+ for ( $i = 0; $i < count( $phrases ); $i += 2 ) {
 608+ $out .= preg_replace_callback( '/\[([0-9]+)\]:/', array( $this, 'genericPrefixCallback' ), $phrases[$i] );
 609+ if ( $i + 1 < count( $phrases ) )
 610+ $out .= '"' . $phrases[$i + 1] . '"'; // phrase text
 611+ }
 612+ return $out;
 613+ }
614614
615 - function genericPrefixCallback( $matches ) {
616 - global $wgContLang;
617 - return $wgContLang->getFormattedNsText( $matches[1] ) . ":";
618 - }
 615+ function genericPrefixCallback( $matches ) {
 616+ global $wgContLang;
 617+ return $wgContLang->getFormattedNsText( $matches[1] ) . ":";
 618+ }
619619
620 - function numRows() {
621 - return $this->mResultCount;
622 - }
 620+ function numRows() {
 621+ return $this->mResultCount;
 622+ }
623623
624 - function termMatches() {
625 - $resq = preg_replace( "/\\[.*?\\]:/", " ", $this->mQuery ); # generic prefixes
626 - $resq = preg_replace( "/all:/", " ", $resq );
 624+ function termMatches() {
 625+ $resq = preg_replace( "/\\[.*?\\]:/", " ", $this->mQuery ); # generic prefixes
 626+ $resq = preg_replace( "/all:/", " ", $resq );
627627
628628 // Fixme: this is ripped from SearchMySQL and probably kind of sucks,
629629 // but it handles quoted phrase searches more or less correctly.
630630 // Should encapsulate this stuff better.
631631 // FIXME: This doesn't handle parenthetical expressions.
632 - $regexes = array();
633 - $m = array();
634 - $lc = SearchEngine::legalSearchChars();
635 - if ( preg_match_all( '/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/', $resq, $m, PREG_SET_ORDER ) ) {
636 - foreach ( $m as $terms ) {
637 - if ( !empty( $terms[3] ) ) {
 632+ $regexes = array();
 633+ $m = array();
 634+ $lc = SearchEngine::legalSearchChars();
 635+ if ( preg_match_all( '/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/', $resq, $m, PREG_SET_ORDER ) ) {
 636+ foreach ( $m as $terms ) {
 637+ if ( !empty( $terms[3] ) ) {
638638 // Match individual terms in result highlighting...
639 - $regexp = preg_quote( $terms[3], '/' );
640 - if ( $terms[4] )
641 - $regexp .= "[0-9A-Za-z_]+";
642 - } else {
 639+ $regexp = preg_quote( $terms[3], '/' );
 640+ if ( $terms[4] )
 641+ $regexp .= "[0-9A-Za-z_]+";
 642+ } else {
643643 // Match the quoted term in result highlighting...
644 - $regexp = preg_quote( str_replace( '"', '', $terms[2] ), '/' );
645 - }
646 - $regexes[] = $regexp;
647 - }
648 - wfDebug( __METHOD__ . ': Match with /' . implode( '|', $regexes ) . "/\n" );
649 - } else {
650 - wfDebug( "Can't understand search query '{$resq}'\n" );
651 - }
652 - return $regexes;
653 - }
 644+ $regexp = preg_quote( str_replace( '"', '', $terms[2] ), '/' );
 645+ }
 646+ $regexes[] = $regexp;
 647+ }
 648+ wfDebug( __METHOD__ . ': Match with /' . implode( '|', $regexes ) . "/\n" );
 649+ } else {
 650+ wfDebug( "Can't understand search query '{$resq}'\n" );
 651+ }
 652+ return $regexes;
 653+ }
654654
655 - /**
656 - * Stupid hack around PHP's limited lambda support
657 - * @access private
658 - */
659 - function regexQuote( $term ) {
660 - return preg_quote( $term, '/' );
661 - }
 655+ /**
 656+ * Stupid hack around PHP's limited lambda support
 657+ * @access private
 658+ */
 659+ function regexQuote( $term ) {
 660+ return preg_quote( $term, '/' );
 661+ }
662662
663 - function hasResults() {
664 - return count( $this->mResults ) > 0;
665 - }
 663+ function hasResults() {
 664+ return count( $this->mResults ) > 0;
 665+ }
666666
667 - /**
668 - * Some search modes return a total hit count for the query
669 - * in the entire article database. This may include pages
670 - * in namespaces that would not be matched on the given
671 - * settings.
672 - *
673 - * @return int
674 - * @access public
675 - */
676 - function getTotalHits() {
677 - return $this->mTotalHits;
678 - }
 667+ /**
 668+ * Some search modes return a total hit count for the query
 669+ * in the entire article database. This may include pages
 670+ * in namespaces that would not be matched on the given
 671+ * settings.
 672+ *
 673+ * @return int
 674+ * @access public
 675+ */
 676+ function getTotalHits() {
 677+ return $this->mTotalHits;
 678+ }
679679
680 - /**
681 - * Return information about how and from where the results were fetched,
682 - * should be useful for diagnostics and debugging
683 - *
684 - * @return string
685 - */
686 - function getInfo() {
687 - if ( is_null( $this->mInfo ) )
688 - return null;
689 - return "Search results fetched via " . $this->mInfo;
690 - }
 680+ /**
 681+ * Return information about how and from where the results were fetched,
 682+ * should be useful for diagnostics and debugging
 683+ *
 684+ * @return string
 685+ */
 686+ function getInfo() {
 687+ if ( is_null( $this->mInfo ) )
 688+ return null;
 689+ return "Search results fetched via " . $this->mInfo;
 690+ }
691691
692 - /**
693 - * Return a result set of hits on other (multiple) wikis associated with this one
694 - *
695 - * @return SearchResultSet
696 - */
697 - function getInterwikiResults() {
698 - return $this->mInterwiki;
699 - }
 692+ /**
 693+ * Return a result set of hits on other (multiple) wikis associated with this one
 694+ *
 695+ * @return SearchResultSet
 696+ */
 697+ function getInterwikiResults() {
 698+ return $this->mInterwiki;
 699+ }
700700
701 - /**
702 - * Some search modes return a suggested alternate term if there are
703 - * no exact hits. Returns true if there is one on this set.
704 - *
705 - * @return bool
706 - * @access public
707 - */
708 - function hasSuggestion() {
709 - return is_string( $this->mSuggestionQuery ) && $this->mSuggestionQuery != '';
710 - }
 701+ /**
 702+ * Some search modes return a suggested alternate term if there are
 703+ * no exact hits. Returns true if there is one on this set.
 704+ *
 705+ * @return bool
 706+ * @access public
 707+ */
 708+ function hasSuggestion() {
 709+ return is_string( $this->mSuggestionQuery ) && $this->mSuggestionQuery != '';
 710+ }
711711
712 - function getSuggestionQuery() {
713 - return $this->mSuggestionQuery;
714 - }
 712+ function getSuggestionQuery() {
 713+ return $this->mSuggestionQuery;
 714+ }
715715
716 - function getSuggestionSnippet() {
717 - return $this->mSuggestionSnippet;
718 - }
 716+ function getSuggestionSnippet() {
 717+ return $this->mSuggestionSnippet;
 718+ }
719719
720 - /**
721 - * Fetches next search result, or false.
722 - * @return SolrResult
723 - * @access public
724 - * @abstract
725 - */
726 - function next() {
727 - if ( $this->mPos < $this->mResultCount ) {
728 - $this->mPos++;
729 - return new SolrResult( $this->mResults[$this->mPos - 1], $this->mMethod );
730 - } else {
731 - return null;
732 - }
733 - }
 720+ /**
 721+ * Fetches next search result, or false.
 722+ * @return SolrResult
 723+ * @access public
 724+ * @abstract
 725+ */
 726+ function next() {
 727+ if ( $this->mPos < $this->mResultCount ) {
 728+ $this->mPos++;
 729+ return new SolrResult( $this->mResults[$this->mPos - 1], $this->mMethod );
 730+ } else {
 731+ return null;
 732+ }
 733+ }
734734
735735 }
Index: trunk/extensions/SolrStore/SolrSearchFieldSet.php
@@ -20,48 +20,48 @@
2121 */
2222 class SolrSearchFieldSet {
2323
24 - var $mName;
25 - var $mFields;
26 - var $mLable;
27 - var $mQuery;
 24+ var $mName;
 25+ var $mFields;
 26+ var $mLable;
 27+ var $mQuery;
2828
29 - public function __construct( $name, $fields = 'search', $lable = 'Alles', $query = null ) {
30 - $this->mName = $name;
31 - $this->mFields = explode( ';', $fields );
32 - $this->mLable = explode( ';', $lable );
33 - $this->mQuery = $query;
34 - }
 29+ public function __construct( $name, $fields = 'search', $lable = 'Alles', $query = null ) {
 30+ $this->mName = $name;
 31+ $this->mFields = explode( ';', $fields );
 32+ $this->mLable = explode( ';', $lable );
 33+ $this->mQuery = $query;
 34+ }
3535
36 - public function getName() {
37 - return $this->mName;
38 - }
 36+ public function getName() {
 37+ return $this->mName;
 38+ }
3939
40 - public function getFields() {
41 - return $this->mFields;
42 - }
 40+ public function getFields() {
 41+ return $this->mFields;
 42+ }
4343
44 - public function getLable() {
45 - return $this->mLable;
46 - }
 44+ public function getLable() {
 45+ return $this->mLable;
 46+ }
4747
48 - public function getQuery() {
49 - return $this->mQuery;
50 - }
 48+ public function getQuery() {
 49+ return $this->mQuery;
 50+ }
5151
52 - public function setName( $value ) {
53 - $this->mName = $value;
54 - }
 52+ public function setName( $value ) {
 53+ $this->mName = $value;
 54+ }
5555
56 - public function setFields( $value ) {
57 - $this->mFields = $value;
58 - }
 56+ public function setFields( $value ) {
 57+ $this->mFields = $value;
 58+ }
5959
60 - public function setLable( $value ) {
61 - $this->mLable = $value;
62 - }
 60+ public function setLable( $value ) {
 61+ $this->mLable = $value;
 62+ }
6363
64 - public function setQuery( $value ) {
65 - $this->mQuery = $value;
66 - }
 64+ public function setQuery( $value ) {
 65+ $this->mQuery = $value;
 66+ }
6767
6868 }
Index: trunk/extensions/SolrStore/SpecialSolrSearch.php
@@ -16,533 +16,533 @@
1717 */
1818 class SpecialSolrSearch extends SpecialPage {
1919
20 - /**
21 - * Set up basic search parameters from the request and user settings.
22 - * Typically you'll pass $wgRequest and $wgUser.
23 - *
24 - * @param $request WebRequest
25 - * @param $user User
26 - */
27 - public function __construct() {
28 - parent::__construct( "SolrSearch" );
29 - global $wgRequest, $wgUser, $wgOut, $wgSolrFields;
30 - $user = $wgUser;
31 - $request = $wgRequest;
32 - list( $this->limit, $this->offset ) = $request->getLimitOffset( 20, 'searchlimit' );
 20+ /**
 21+ * Set up basic search parameters from the request and user settings.
 22+ * Typically you'll pass $wgRequest and $wgUser.
 23+ *
 24+ * @param $request WebRequest
 25+ * @param $user User
 26+ */
 27+ public function __construct() {
 28+ parent::__construct( "SolrSearch" );
 29+ global $wgRequest, $wgUser, $wgOut, $wgSolrFields;
 30+ $user = $wgUser;
 31+ $request = $wgRequest;
 32+ list( $this->limit, $this->offset ) = $request->getLimitOffset( 20, 'searchlimit' );
3333
34 - $this->sk = $user->getSkin();
35 - $this->didYouMeanHtml = ''; # html of did you mean... link
36 - }
 34+ $this->sk = $user->getSkin();
 35+ $this->didYouMeanHtml = ''; # html of did you mean... link
 36+ }
3737
38 - function execute( $par ) {
39 - global $wgRequest, $wgUser, $wgOut, $wgSolrFields;
 38+ function execute( $par ) {
 39+ global $wgRequest, $wgUser, $wgOut, $wgSolrFields;
4040
41 - $this->setHeaders();
42 - $SpecialSolrSearch = new SpecialSolrSearch( $wgRequest, $wgUser );
 41+ $this->setHeaders();
 42+ $SpecialSolrSearch = new SpecialSolrSearch( $wgRequest, $wgUser );
4343
44 - # Get request data from, e.g.
45 - $param = $wgRequest->getText( 'param' );
 44+ # Get request data from, e.g.
 45+ $param = $wgRequest->getText( 'param' );
4646
47 - foreach ( $wgSolrFields as $set ) {
48 - if ( $par == $set->getName() ) {
49 - $fieldSet = $set;
50 - }
51 - }
52 - # Do stuff
53 - # ...
54 - // Strip underscores from title parameter; most of the time we'll want
55 - // text form here. But don't strip underscores from actual text params!
56 - $titleParam = str_replace( '_', ' ', $par );
57 - // Fetch the search term
58 -// $search = str_replace("\n", " ", $wgRequest->getText('solrsearch', $titleParam));
 47+ foreach ( $wgSolrFields as $set ) {
 48+ if ( $par == $set->getName() ) {
 49+ $fieldSet = $set;
 50+ }
 51+ }
 52+ # Do stuff
 53+ # ...
 54+ // Strip underscores from title parameter; most of the time we'll want
 55+ // text form here. But don't strip underscores from actual text params!
 56+ $titleParam = str_replace( '_', ' ', $par );
 57+ // Fetch the search term
 58+// $search = str_replace("\n", " ", $wgRequest->getText('solrsearch', $titleParam));
5959
60 - if ( !isset( $fieldSet ) ) {
61 - $SpecialSolrSearch->showFieldSets();
62 - } else {
63 - $lable = $fieldSet->getLable();
64 - $firstTimeHere = true;
65 - foreach ( $fieldSet->getFields() as $field ) {
66 - if ( $firstTimeHere ) {
67 - $newLable ['solr' . trim( $field )] = trim( $lable[0] );
68 - $firstTimeHere = false;
69 - } else {
70 - $newLable ['solr' . trim( $field )] = trim( next( $lable ) );
71 - }
 60+ if ( !isset( $fieldSet ) ) {
 61+ $SpecialSolrSearch->showFieldSets();
 62+ } else {
 63+ $lable = $fieldSet->getLable();
 64+ $firstTimeHere = true;
 65+ foreach ( $fieldSet->getFields() as $field ) {
 66+ if ( $firstTimeHere ) {
 67+ $newLable ['solr' . trim( $field )] = trim( $lable[0] );
 68+ $firstTimeHere = false;
 69+ } else {
 70+ $newLable ['solr' . trim( $field )] = trim( next( $lable ) );
 71+ }
7272
73 - $newFields ['solr' . trim( $field )] = $wgRequest->getText( 'solr' . trim( $field ) );
74 - }
75 - $fieldSet->setFields( $newFields );
76 - $fieldSet->setLable( $newLable );
 73+ $newFields ['solr' . trim( $field )] = $wgRequest->getText( 'solr' . trim( $field ) );
 74+ }
 75+ $fieldSet->setFields( $newFields );
 76+ $fieldSet->setLable( $newLable );
7777
78 - $SpecialSolrSearch->showResults( $fieldSet );
79 - }
80 - }
 78+ $SpecialSolrSearch->showResults( $fieldSet );
 79+ }
 80+ }
8181
82 - /**
83 - * @param $fieldSet String
84 - */
85 - public function showFieldSets() {
86 - global $wgOut, $wgUser, $wgDisableTextSearch, $wgContLang, $wgScript, $wgSolrFields;
87 - wfProfileIn( __METHOD__ );
 82+ /**
 83+ * @param $fieldSet String
 84+ */
 85+ public function showFieldSets() {
 86+ global $wgOut, $wgUser, $wgDisableTextSearch, $wgContLang, $wgScript, $wgSolrFields;
 87+ wfProfileIn( __METHOD__ );
8888
89 - $sk = $wgUser->getSkin();
 89+ $sk = $wgUser->getSkin();
9090
9191
92 - $wgOut->setPageTitle( wfMsg( 'solrstore-searchFieldSets' ) );
93 - $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'solrstore-searchFieldSets-title', 'SolrSearch: Select FieldSet' ) ) );
 92+ $wgOut->setPageTitle( wfMsg( 'solrstore-searchFieldSets' ) );
 93+ $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'solrstore-searchFieldSets-title', 'SolrSearch: Select FieldSet' ) ) );
9494
95 - $wgOut->setArticleRelated( false );
96 - $wgOut->addHtml( '<div class="solrsearch-fieldset">' );
97 - $wgOut->addHtml( wfMsg( 'solrstore-searchFieldSets-select' ) );
98 - $wgOut->addHtml( '<ul>' );
 95+ $wgOut->setArticleRelated( false );
 96+ $wgOut->addHtml( '<div class="solrsearch-fieldset">' );
 97+ $wgOut->addHtml( wfMsg( 'solrstore-searchFieldSets-select' ) );
 98+ $wgOut->addHtml( '<ul>' );
9999
100 - // TODO: If no SearchSets exist, provide a shot Manual how to create some!
101 - foreach ( $wgSolrFields as $set ) {
102 - $name = $set->getName();
103 - $wgOut->addHtml( "<li><a href=\"$wgScript/Special:SolrSearch/$name\">$name</a></li>" );
104 - }
105 - $wgOut->addHtml( '</ul>' );
106 - $wgOut->addHtml( "</div>" );
 100+ // TODO: If no SearchSets exist, provide a shot Manual how to create some!
 101+ foreach ( $wgSolrFields as $set ) {
 102+ $name = $set->getName();
 103+ $wgOut->addHtml( "<li><a href=\"$wgScript/Special:SolrSearch/$name\">$name</a></li>" );
 104+ }
 105+ $wgOut->addHtml( '</ul>' );
 106+ $wgOut->addHtml( "</div>" );
107107
108 - wfProfileOut( __METHOD__ );
109 - }
 108+ wfProfileOut( __METHOD__ );
 109+ }
110110
111 - /**
112 - * @param $fieldSet String
113 - */
114 - public function showResults( $fieldSet ) {
115 - global $wgOut, $wgUser, $wgDisableTextSearch, $wgContLang, $wgScript;
116 - wfProfileIn( __METHOD__ );
 111+ /**
 112+ * @param $fieldSet String
 113+ */
 114+ public function showResults( $fieldSet ) {
 115+ global $wgOut, $wgUser, $wgDisableTextSearch, $wgContLang, $wgScript;
 116+ wfProfileIn( __METHOD__ );
117117
118 - $sk = $wgUser->getSkin();
 118+ $sk = $wgUser->getSkin();
119119
120 - $this->searchEngine = SearchEngine::create();
121 - $search = & $this->searchEngine;
122 - $search->setLimitOffset( $this->limit, $this->offset );
 120+ $this->searchEngine = SearchEngine::create();
 121+ $search = & $this->searchEngine;
 122+ $search->setLimitOffset( $this->limit, $this->offset );
123123
124 - $this->setupPage( $fieldSet );
 124+ $this->setupPage( $fieldSet );
125125
126 - $t = Title::newFromText( $fieldSet->getName() );
 126+ $t = Title::newFromText( $fieldSet->getName() );
127127
128 - // DO we have Title matches
129 - $fields = $fieldSet->getFields();
 128+ // DO we have Title matches
 129+ $fields = $fieldSet->getFields();
130130
131 - // BUILD SOLR QUERY STRING FROM DA FIELDS
132 - if ( isset( $fields['solrsearch'] ) ) {
133 - $query = $fields['solrsearch'];
134 - } else {
135 - $query = '';
136 - }
 131+ // BUILD SOLR QUERY STRING FROM DA FIELDS
 132+ if ( isset( $fields['solrsearch'] ) ) {
 133+ $query = $fields['solrsearch'];
 134+ } else {
 135+ $query = '';
 136+ }
137137
138138
139 - foreach ( $fields as $key => $value ) {
140 - if ( $key != 'solrsearch' && !empty( $value ) ) {
141 - $query = trim( $query ) . ' ' . trim( substr( $key, 4 ) ) . ':' . '(' . ( $value ) . ')';
142 - }
143 - }
 139+ foreach ( $fields as $key => $value ) {
 140+ if ( $key != 'solrsearch' && !empty( $value ) ) {
 141+ $query = trim( $query ) . ' ' . trim( substr( $key, 4 ) ) . ':' . '(' . ( $value ) . ')';
 142+ }
 143+ }
144144
145 - if ( !empty( $query ) ) {
146 - $query .= $fieldSet->getQuery();
147 - }
 145+ if ( !empty( $query ) ) {
 146+ $query .= $fieldSet->getQuery();
 147+ }
148148
149 - $titleMatches = $search->searchTitle( $query );
 149+ $titleMatches = $search->searchTitle( $query );
150150
151 - if ( !( $titleMatches instanceof SearchResultTooMany ) )
152 - $textMatches = $search->searchText( $query );
 151+ if ( !( $titleMatches instanceof SearchResultTooMany ) )
 152+ $textMatches = $search->searchText( $query );
153153
154 - // did you mean... suggestions
155 - if ( $textMatches && $textMatches->hasSuggestion() ) {
156 - $st = SpecialPage::getTitleFor( 'SolrSearch' );
 154+ // did you mean... suggestions
 155+ if ( $textMatches && $textMatches->hasSuggestion() ) {
 156+ $st = SpecialPage::getTitleFor( 'SolrSearch' );
157157
158 - # mirror Go/Search behaviour of original request ..
159 - $didYouMeanParams = array( 'solrsearch' => $textMatches->getSuggestionQuery() );
 158+ # mirror Go/Search behaviour of original request ..
 159+ $didYouMeanParams = array( 'solrsearch' => $textMatches->getSuggestionQuery() );
160160
161 - $stParams = $didYouMeanParams;
 161+ $stParams = $didYouMeanParams;
162162
163 - $suggestionSnippet = $textMatches->getSuggestionSnippet();
 163+ $suggestionSnippet = $textMatches->getSuggestionSnippet();
164164
165 - if ( $suggestionSnippet == '' )
166 - $suggestionSnippet = null;
 165+ if ( $suggestionSnippet == '' )
 166+ $suggestionSnippet = null;
167167
168 - $suggestLink = $sk->linkKnown(
169 - $st, $suggestionSnippet, array(), $stParams
170 - );
 168+ $suggestLink = $sk->linkKnown(
 169+ $st, $suggestionSnippet, array(), $stParams
 170+ );
171171
172 - $this->didYouMeanHtml = '<div class="searchdidyoumean">' . wfMsg( 'search-suggest', $suggestLink ) . '</div>';
173 - }
174 - // start rendering the page
175 - $wgOut->addHtml(
176 - Xml::openElement(
177 - 'form', array(
178 - 'id' => 'solrsearch',
179 - 'method' => 'get',
180 - 'action' => $wgScript
181 - )
182 - )
183 - );
184 - $wgOut->addHtml(
185 - Xml::openElement( 'table', array( 'id' => 'mw-search-top-table', 'border' => 0, 'cellpadding' => 0, 'cellspacing' => 0 ) ) .
186 - Xml::openElement( 'tr' ) .
187 - Xml::openElement( 'td' ) . "\n" .
188 - $this->shortDialog( $fieldSet ) .
189 - Xml::closeElement( 'td' ) .
190 - Xml::closeElement( 'tr' ) .
191 - Xml::closeElement( 'table' )
192 - );
 172+ $this->didYouMeanHtml = '<div class="searchdidyoumean">' . wfMsg( 'search-suggest', $suggestLink ) . '</div>';
 173+ }
 174+ // start rendering the page
 175+ $wgOut->addHtml(
 176+ Xml::openElement(
 177+ 'form', array(
 178+ 'id' => 'solrsearch',
 179+ 'method' => 'get',
 180+ 'action' => $wgScript
 181+ )
 182+ )
 183+ );
 184+ $wgOut->addHtml(
 185+ Xml::openElement( 'table', array( 'id' => 'mw-search-top-table', 'border' => 0, 'cellpadding' => 0, 'cellspacing' => 0 ) ) .
 186+ Xml::openElement( 'tr' ) .
 187+ Xml::openElement( 'td' ) . "\n" .
 188+ $this->shortDialog( $fieldSet ) .
 189+ Xml::closeElement( 'td' ) .
 190+ Xml::closeElement( 'tr' ) .
 191+ Xml::closeElement( 'table' )
 192+ );
193193
194 - // Sometimes the search engine knows there are too many hits
195 - if ( $titleMatches instanceof SearchResultTooMany ) {
196 - $wgOut->addWikiText( '==' . wfMsg( 'toomanymatches' ) . "==\n" );
197 - wfProfileOut( __METHOD__ );
198 - return;
199 - }
 194+ // Sometimes the search engine knows there are too many hits
 195+ if ( $titleMatches instanceof SearchResultTooMany ) {
 196+ $wgOut->addWikiText( '==' . wfMsg( 'toomanymatches' ) . "==\n" );
 197+ wfProfileOut( __METHOD__ );
 198+ return;
 199+ }
200200
201 - $filePrefix = $wgContLang->getFormattedNsText( NS_FILE ) . ':';
202 - if ( trim( $query ) === '' || $filePrefix === trim( $query ) ) {
203 - $wgOut->addHTML( $this->formHeader( $query, 0, 0 ) );
204 - $wgOut->addHTML( '</form>' );
205 - // Empty query -- straight view of search form
206 - wfProfileOut( __METHOD__ );
207 - return;
208 - }
209 - // Get number of results
210 - $titleMatchesNum = $titleMatches ? $titleMatches->numRows() : 0;
211 - $textMatchesNum = $textMatches ? $textMatches->numRows() : 0;
212 - // Total initial query matches (possible false positives)
213 - $num = $titleMatchesNum + $textMatchesNum;
 201+ $filePrefix = $wgContLang->getFormattedNsText( NS_FILE ) . ':';
 202+ if ( trim( $query ) === '' || $filePrefix === trim( $query ) ) {
 203+ $wgOut->addHTML( $this->formHeader( $query, 0, 0 ) );
 204+ $wgOut->addHTML( '</form>' );
 205+ // Empty query -- straight view of search form
 206+ wfProfileOut( __METHOD__ );
 207+ return;
 208+ }
 209+ // Get number of results
 210+ $titleMatchesNum = $titleMatches ? $titleMatches->numRows() : 0;
 211+ $textMatchesNum = $textMatches ? $textMatches->numRows() : 0;
 212+ // Total initial query matches (possible false positives)
 213+ $num = $titleMatchesNum + $textMatchesNum;
214214
215 - // Get total actual results (after second filtering, if any)
216 - $numTitleMatches = $titleMatches && !is_null( $titleMatches->getTotalHits() ) ?
217 - $titleMatches->getTotalHits() : $titleMatchesNum;
218 - $numTextMatches = $textMatches && !is_null( $textMatches->getTotalHits() ) ?
219 - $textMatches->getTotalHits() : $textMatchesNum;
 215+ // Get total actual results (after second filtering, if any)
 216+ $numTitleMatches = $titleMatches && !is_null( $titleMatches->getTotalHits() ) ?
 217+ $titleMatches->getTotalHits() : $titleMatchesNum;
 218+ $numTextMatches = $textMatches && !is_null( $textMatches->getTotalHits() ) ?
 219+ $textMatches->getTotalHits() : $textMatchesNum;
220220
221 - // get total number of results if backend can calculate it
222 - $totalRes = 0;
223 - if ( $titleMatches && !is_null( $titleMatches->getTotalHits() ) )
224 - $totalRes += $titleMatches->getTotalHits();
225 - if ( $textMatches && !is_null( $textMatches->getTotalHits() ) )
226 - $totalRes += $textMatches->getTotalHits();
227 - // show number of results and current offset
228 - $wgOut->addHTML( $this->formHeader( $query, $num, $totalRes ) );
 221+ // get total number of results if backend can calculate it
 222+ $totalRes = 0;
 223+ if ( $titleMatches && !is_null( $titleMatches->getTotalHits() ) )
 224+ $totalRes += $titleMatches->getTotalHits();
 225+ if ( $textMatches && !is_null( $textMatches->getTotalHits() ) )
 226+ $totalRes += $textMatches->getTotalHits();
 227+ // show number of results and current offset
 228+ $wgOut->addHTML( $this->formHeader( $query, $num, $totalRes ) );
229229
230 - $wgOut->addHtml( Xml::closeElement( 'form' ) );
231 - $wgOut->addHtml( "<div class='searchresults'>" );
 230+ $wgOut->addHtml( Xml::closeElement( 'form' ) );
 231+ $wgOut->addHtml( "<div class='searchresults'>" );
232232
233 - // prev/next links
234 - if ( $num || $this->offset ) {
235 - // Show the create link ahead
236 - $this->showCreateLink( $t );
237 - $prevnext = wfViewPrevNext( $this->offset, $this->limit, SpecialPage::getTitleFor( 'SolrSearch' ), wfArrayToCGI( array( 'solrsearch' => $query ) ), max( $titleMatchesNum, $textMatchesNum ) < $this->limit
238 - );
239 - // $wgOut->addHTML( "<p class='mw-search-pager-top'>{$prevnext}</p>\n" );
240 - wfRunHooks( 'SpecialSolrSearchResults', array( $fieldSet, &$titleMatches, &$textMatches ) );
241 - } else {
242 - wfRunHooks( 'SpecialSolrSearchNoResults', array( $fieldSet ) );
243 - }
 233+ // prev/next links
 234+ if ( $num || $this->offset ) {
 235+ // Show the create link ahead
 236+ $this->showCreateLink( $t );
 237+ $prevnext = wfViewPrevNext( $this->offset, $this->limit, SpecialPage::getTitleFor( 'SolrSearch' ), wfArrayToCGI( array( 'solrsearch' => $query ) ), max( $titleMatchesNum, $textMatchesNum ) < $this->limit
 238+ );
 239+ // $wgOut->addHTML( "<p class='mw-search-pager-top'>{$prevnext}</p>\n" );
 240+ wfRunHooks( 'SpecialSolrSearchResults', array( $fieldSet, &$titleMatches, &$textMatches ) );
 241+ } else {
 242+ wfRunHooks( 'SpecialSolrSearchNoResults', array( $fieldSet ) );
 243+ }
244244
245 - if ( $titleMatches ) {
246 - if ( $numTitleMatches > 0 ) {
247 - $wgOut->wrapWikiMsg( "==$1==\n", 'titlematches' );
248 - $wgOut->addHTML( $this->showMatches( $titleMatches ) );
249 - }
250 - $titleMatches->free();
251 - }
252 - if ( $textMatches ) {
253 - // output appropriate heading
254 - if ( $numTextMatches > 0 && $numTitleMatches > 0 ) {
255 - // if no title matches the heading is redundant
256 - $wgOut->wrapWikiMsg( "==$1==\n", 'textmatches' );
257 - } elseif ( $totalRes == 0 ) {
258 - # Don't show the 'no text matches' if we received title matches
259 - # $wgOut->wrapWikiMsg( "==$1==\n", 'notextmatches' );
260 - }
 245+ if ( $titleMatches ) {
 246+ if ( $numTitleMatches > 0 ) {
 247+ $wgOut->wrapWikiMsg( "==$1==\n", 'titlematches' );
 248+ $wgOut->addHTML( $this->showMatches( $titleMatches ) );
 249+ }
 250+ $titleMatches->free();
 251+ }
 252+ if ( $textMatches ) {
 253+ // output appropriate heading
 254+ if ( $numTextMatches > 0 && $numTitleMatches > 0 ) {
 255+ // if no title matches the heading is redundant
 256+ $wgOut->wrapWikiMsg( "==$1==\n", 'textmatches' );
 257+ } elseif ( $totalRes == 0 ) {
 258+ # Don't show the 'no text matches' if we received title matches
 259+ # $wgOut->wrapWikiMsg( "==$1==\n", 'notextmatches' );
 260+ }
261261
262 - // show results
263 - if ( $numTextMatches > 0 ) {
264 - $wgOut->addHTML( $this->showMatches( $textMatches ) );
265 - }
 262+ // show results
 263+ if ( $numTextMatches > 0 ) {
 264+ $wgOut->addHTML( $this->showMatches( $textMatches ) );
 265+ }
266266
267 - $textMatches->free();
268 - }
 267+ $textMatches->free();
 268+ }
269269
270 - $wgOut->addHtml( "</div>" );
 270+ $wgOut->addHtml( "</div>" );
271271
272 - if ( $num || $this->offset ) {
273 - $wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
274 - }
275 - wfProfileOut( __METHOD__ );
276 - }
 272+ if ( $num || $this->offset ) {
 273+ $wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
 274+ }
 275+ wfProfileOut( __METHOD__ );
 276+ }
277277
278 - protected function showCreateLink( $t ) {
279 - global $wgOut;
 278+ protected function showCreateLink( $t ) {
 279+ global $wgOut;
280280
281 - // show direct page/create link if applicable
282 - $messageName = null;
283 - if ( !is_null( $t ) ) {
284 - if ( $t->isKnown() ) {
285 - $messageName = 'searchmenu-exists';
286 - } elseif ( $t->userCan( 'create' ) ) {
287 - $messageName = 'searchmenu-new';
288 - } else {
289 - $messageName = 'searchmenu-new-nocreate';
290 - }
291 - }
292 - if ( $messageName ) {
293 - $wgOut->wrapWikiMsg( "<p class=\"mw-search-createlink\">\n$1</p>", array( $messageName, wfEscapeWikiText( $t->getPrefixedText() ) ) );
294 - } else {
295 - // preserve the paragraph for margins etc...
296 - $wgOut->addHtml( '<p></p>' );
297 - }
298 - }
 281+ // show direct page/create link if applicable
 282+ $messageName = null;
 283+ if ( !is_null( $t ) ) {
 284+ if ( $t->isKnown() ) {
 285+ $messageName = 'searchmenu-exists';
 286+ } elseif ( $t->userCan( 'create' ) ) {
 287+ $messageName = 'searchmenu-new';
 288+ } else {
 289+ $messageName = 'searchmenu-new-nocreate';
 290+ }
 291+ }
 292+ if ( $messageName ) {
 293+ $wgOut->wrapWikiMsg( "<p class=\"mw-search-createlink\">\n$1</p>", array( $messageName, wfEscapeWikiText( $t->getPrefixedText() ) ) );
 294+ } else {
 295+ // preserve the paragraph for margins etc...
 296+ $wgOut->addHtml( '<p></p>' );
 297+ }
 298+ }
299299
300 - /**
301 - *
302 - */
303 - protected function setupPage( $fieldSet ) {
304 - global $wgOut;
 300+ /**
 301+ *
 302+ */
 303+ protected function setupPage( $fieldSet ) {
 304+ global $wgOut;
305305
306 - if ( !empty( $fieldSet ) ) {
307 - $wgOut->setPageTitle( wfMsg( 'searchresults' ) );
308 - $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'searchresults-title', $fieldSet->getName() ) ) );
309 - }
310 - $wgOut->setArticleRelated( false );
311 - $wgOut->setRobotPolicy( 'noindex,nofollow' );
312 - // add javascript specific to special:search
313 - $wgOut->addModules( 'mediawiki.legacy.search' );
314 - $wgOut->addModules( 'mediawiki.special.search' );
315 - }
 306+ if ( !empty( $fieldSet ) ) {
 307+ $wgOut->setPageTitle( wfMsg( 'searchresults' ) );
 308+ $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'searchresults-title', $fieldSet->getName() ) ) );
 309+ }
 310+ $wgOut->setArticleRelated( false );
 311+ $wgOut->setRobotPolicy( 'noindex,nofollow' );
 312+ // add javascript specific to special:search
 313+ $wgOut->addModules( 'mediawiki.legacy.search' );
 314+ $wgOut->addModules( 'mediawiki.special.search' );
 315+ }
316316
317 - /**
318 - * Show whole set of results
319 - *
320 - * @param $matches SearchResultSet
321 - */
322 - protected function showMatches( &$matches ) {
323 - global $wgContLang;
324 - wfProfileIn( __METHOD__ );
 317+ /**
 318+ * Show whole set of results
 319+ *
 320+ * @param $matches SearchResultSet
 321+ */
 322+ protected function showMatches( &$matches ) {
 323+ global $wgContLang;
 324+ wfProfileIn( __METHOD__ );
325325
326 - $fieldSets = $wgContLang->convertForSearchResult( $matches->termMatches() );
 326+ $fieldSets = $wgContLang->convertForSearchResult( $matches->termMatches() );
327327
328 - $out = "";
329 - $infoLine = $matches->getInfo();
330 - if ( !is_null( $infoLine ) ) {
331 - $out .= "\n<!-- {$infoLine} -->\n";
332 - }
333 - $out .= "<ul class='mw-search-results'>\n";
334 - $xxx = 0;
335 - while ( $result = $matches->next() ) {
336 - $out .= $this->showHit( $result, $fieldSets );
337 - }
338 - $out .= "</ul>\n";
 328+ $out = "";
 329+ $infoLine = $matches->getInfo();
 330+ if ( !is_null( $infoLine ) ) {
 331+ $out .= "\n<!-- {$infoLine} -->\n";
 332+ }
 333+ $out .= "<ul class='mw-search-results'>\n";
 334+ $xxx = 0;
 335+ while ( $result = $matches->next() ) {
 336+ $out .= $this->showHit( $result, $fieldSets );
 337+ }
 338+ $out .= "</ul>\n";
339339
340 - // convert the whole thing to desired language variant
341 - $out = $wgContLang->convert( $out );
342 - wfProfileOut( __METHOD__ );
343 - return $out;
344 - }
 340+ // convert the whole thing to desired language variant
 341+ $out = $wgContLang->convert( $out );
 342+ wfProfileOut( __METHOD__ );
 343+ return $out;
 344+ }
345345
346 - /**
347 - * Format a single hit result
348 - *
349 - * @param $result SearchResult
350 - * @param $fieldSets Array: terms to highlight
351 - */
352 - protected function showHit( $result, $fieldSets ) {
353 - global $wgLang, $wgUser;
354 - wfProfileIn( __METHOD__ );
 346+ /**
 347+ * Format a single hit result
 348+ *
 349+ * @param $result SearchResult
 350+ * @param $fieldSets Array: terms to highlight
 351+ */
 352+ protected function showHit( $result, $fieldSets ) {
 353+ global $wgLang, $wgUser;
 354+ wfProfileIn( __METHOD__ );
355355
356 - if ( $result->isBrokenTitle() ) {
357 - wfProfileOut( __METHOD__ );
358 - return "<!-- Broken link in search result -->\n";
359 - }
 356+ if ( $result->isBrokenTitle() ) {
 357+ wfProfileOut( __METHOD__ );
 358+ return "<!-- Broken link in search result -->\n";
 359+ }
360360
361 - $sk = $wgUser->getSkin();
362 - $t = $result->getTitle();
 361+ $sk = $wgUser->getSkin();
 362+ $t = $result->getTitle();
363363
364 - $titleSnippet = $result->getTitleSnippet( $fieldSets );
 364+ $titleSnippet = $result->getTitleSnippet( $fieldSets );
365365
366 - if ( $titleSnippet == '' )
367 - $titleSnippet = null;
 366+ if ( $titleSnippet == '' )
 367+ $titleSnippet = null;
368368
369 - $link_t = clone $t;
 369+ $link_t = clone $t;
370370
371 - wfRunHooks( 'ShowSearchHitTitle', array( &$link_t, &$titleSnippet, $result, $fieldSets, $this ) );
 371+ wfRunHooks( 'ShowSearchHitTitle', array( &$link_t, &$titleSnippet, $result, $fieldSets, $this ) );
372372
373 - $link = $this->sk->linkKnown(
374 - $link_t, $titleSnippet
375 - );
376 - // FÜLLEN
377 - // If page content is not readable, just return the title.
378 - // This is not quite safe, but better than showing excerpts from non-readable pages
379 - // Note that hiding the entry entirely would screw up paging.
380 - // ---- HIER
381 - if ( !$t->userCanRead() ) {
382 - wfProfileOut( __METHOD__ );
383 - return "<li>{$link}</li>\n";
384 - }
385 - // return "<li>{$link}</li>\n";
386 - // If the page doesn't *exist*... our search index is out of date.
387 - // The least confusing at this point is to drop the result.
388 - // You may get less results, but... oh well. :P
389 - // ---- HIER
390 - if ( $result->isMissingRevision() ) {
391 - wfProfileOut( __METHOD__ );
392 - return "<!-- missing page " . htmlspecialchars( $t->getPrefixedText() ) . "-->\n";
393 - }
 373+ $link = $this->sk->linkKnown(
 374+ $link_t, $titleSnippet
 375+ );
 376+ // FÜLLEN
 377+ // If page content is not readable, just return the title.
 378+ // This is not quite safe, but better than showing excerpts from non-readable pages
 379+ // Note that hiding the entry entirely would screw up paging.
 380+ // ---- HIER
 381+ if ( !$t->userCanRead() ) {
 382+ wfProfileOut( __METHOD__ );
 383+ return "<li>{$link}</li>\n";
 384+ }
 385+ // return "<li>{$link}</li>\n";
 386+ // If the page doesn't *exist*... our search index is out of date.
 387+ // The least confusing at this point is to drop the result.
 388+ // You may get less results, but... oh well. :P
 389+ // ---- HIER
 390+ if ( $result->isMissingRevision() ) {
 391+ wfProfileOut( __METHOD__ );
 392+ return "<!-- missing page " . htmlspecialchars( $t->getPrefixedText() ) . "-->\n";
 393+ }
394394
395 - // format redirects / relevant sections
396 - $redirectTitle = $result->getRedirectTitle();
397 - $redirectText = $result->getRedirectSnippet( $fieldSets );
398 - $sectionTitle = $result->getSectionTitle();
399 - $sectionText = $result->getSectionSnippet( $fieldSets );
400 - $redirect = '';
 395+ // format redirects / relevant sections
 396+ $redirectTitle = $result->getRedirectTitle();
 397+ $redirectText = $result->getRedirectSnippet( $fieldSets );
 398+ $sectionTitle = $result->getSectionTitle();
 399+ $sectionText = $result->getSectionSnippet( $fieldSets );
 400+ $redirect = '';
401401
402 - if ( !is_null( $redirectTitle ) ) {
403 - if ( $redirectText == '' )
404 - $redirectText = null;
 402+ if ( !is_null( $redirectTitle ) ) {
 403+ if ( $redirectText == '' )
 404+ $redirectText = null;
405405
406 - $redirect = "<span class='searchalttitle'>" .
407 - wfMsg( 'search-redirect', $this->sk->linkKnown( $redirectTitle, $redirectText ) ) .
408 - "</span>";
409 - }
 406+ $redirect = "<span class='searchalttitle'>" .
 407+ wfMsg( 'search-redirect', $this->sk->linkKnown( $redirectTitle, $redirectText ) ) .
 408+ "</span>";
 409+ }
410410
411 - $section = '';
 411+ $section = '';
412412
413413
414 - if ( !is_null( $sectionTitle ) ) {
415 - if ( $sectionText == '' )
416 - $sectionText = null;
 414+ if ( !is_null( $sectionTitle ) ) {
 415+ if ( $sectionText == '' )
 416+ $sectionText = null;
417417
418 - $section = "<span class='searchalttitle'>" .
419 - wfMsg( 'search-section', $this->sk->linkKnown( $sectionTitle, $sectionText ) ) .
420 - "</span>";
421 - }
 418+ $section = "<span class='searchalttitle'>" .
 419+ wfMsg( 'search-section', $this->sk->linkKnown( $sectionTitle, $sectionText ) ) .
 420+ "</span>";
 421+ }
422422
423 - // format text extract
424 - $extract = "<div class='searchresult'>" . $result->getTextSnippet( $fieldSets ) . "</div>";
 423+ // format text extract
 424+ $extract = "<div class='searchresult'>" . $result->getTextSnippet( $fieldSets ) . "</div>";
425425
426 - // format score
427 - if ( is_null( $result->getScore() ) ) {
428 - // Search engine doesn't report scoring info
429 - $score = '';
430 - } else {
431 - $percent = sprintf( '%2.1f', $result->getScore() * 100 );
432 - $score = wfMsg( 'search-result-score', $wgLang->formatNum( $percent ) ) . ' - ';
433 - }
 426+ // format score
 427+ if ( is_null( $result->getScore() ) ) {
 428+ // Search engine doesn't report scoring info
 429+ $score = '';
 430+ } else {
 431+ $percent = sprintf( '%2.1f', $result->getScore() * 100 );
 432+ $score = wfMsg( 'search-result-score', $wgLang->formatNum( $percent ) ) . ' - ';
 433+ }
434434
435 - // format description
436 - $byteSize = $result->getByteSize();
437 - $wordCount = $result->getWordCount();
438 - $timestamp = $result->getTimestamp();
439 - $size = wfMsgExt( 'search-result-size', array( 'parsemag', 'escape' ), $this->sk->formatSize( $byteSize ), $wgLang->formatNum( $wordCount ) );
 435+ // format description
 436+ $byteSize = $result->getByteSize();
 437+ $wordCount = $result->getWordCount();
 438+ $timestamp = $result->getTimestamp();
 439+ $size = wfMsgExt( 'search-result-size', array( 'parsemag', 'escape' ), $this->sk->formatSize( $byteSize ), $wgLang->formatNum( $wordCount ) );
440440
441 - if ( $t->getNamespace() == NS_CATEGORY ) {
442 - $cat = Category::newFromTitle( $t );
443 - $size = wfMsgExt( 'search-result-category-size', array( 'parsemag', 'escape' ), $wgLang->formatNum( $cat->getPageCount() ), $wgLang->formatNum( $cat->getSubcatCount() ), $wgLang->formatNum( $cat->getFileCount() ) );
444 - }
 441+ if ( $t->getNamespace() == NS_CATEGORY ) {
 442+ $cat = Category::newFromTitle( $t );
 443+ $size = wfMsgExt( 'search-result-category-size', array( 'parsemag', 'escape' ), $wgLang->formatNum( $cat->getPageCount() ), $wgLang->formatNum( $cat->getSubcatCount() ), $wgLang->formatNum( $cat->getFileCount() ) );
 444+ }
445445
446 - $date = $wgLang->timeanddate( $timestamp );
 446+ $date = $wgLang->timeanddate( $timestamp );
447447
448 - // link to related articles if supported
449 - $related = '';
450 - if ( $result->hasRelated() ) {
451 - $st = SpecialPage::getTitleFor( 'SolrSearch' );
452 - $stParams = array( 'solrsearch' => wfMsgForContent( 'searchrelated' ) . ':' . $t->getPrefixedText() );
453 - $related = ' -- ' . $sk->linkKnown( $st, wfMsg( 'search-relatedarticle' ), array(), $stParams );
454 - }
 448+ // link to related articles if supported
 449+ $related = '';
 450+ if ( $result->hasRelated() ) {
 451+ $st = SpecialPage::getTitleFor( 'SolrSearch' );
 452+ $stParams = array( 'solrsearch' => wfMsgForContent( 'searchrelated' ) . ':' . $t->getPrefixedText() );
 453+ $related = ' -- ' . $sk->linkKnown( $st, wfMsg( 'search-relatedarticle' ), array(), $stParams );
 454+ }
455455
456 - // Include a thumbnail for media files...
457 - // WE HAVE NEVER TESTED THIS HERE!!!
458 - if ( $t->getNamespace() == NS_FILE ) {
459 - $img = wfFindFile( $t );
460 - if ( $img ) {
461 - $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
462 - if ( $thumb ) {
463 - $desc = wfMsg( 'parentheses', $img->getShortDesc() );
464 - wfProfileOut( __METHOD__ );
465 - // Float doesn't seem to interact well with the bullets.
466 - // Table messes up vertical alignment of the bullets.
467 - // Bullets are therefore disabled (didn't look great anyway).
468 - return "<li>" .
469 - '<table class="searchResultImage">' .
470 - '<tr>' .
471 - '<td width="120" align="center" valign="top">' .
472 - $thumb->toHtml( array( 'desc-link' => true ) ) .
473 - '</td>' .
474 - '<td valign="top">' .
475 - $link .
476 - $extract .
477 - "<div class='mw-search-result-data'>{$score}{$desc}{$date}{$related}</div>" .
478 - '</td>' .
479 - '</tr>' .
480 - '</table>' .
481 - "</li>\n";
482 - }
483 - }
484 - }
 456+ // Include a thumbnail for media files...
 457+ // WE HAVE NEVER TESTED THIS HERE!!!
 458+ if ( $t->getNamespace() == NS_FILE ) {
 459+ $img = wfFindFile( $t );
 460+ if ( $img ) {
 461+ $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
 462+ if ( $thumb ) {
 463+ $desc = wfMsg( 'parentheses', $img->getShortDesc() );
 464+ wfProfileOut( __METHOD__ );
 465+ // Float doesn't seem to interact well with the bullets.
 466+ // Table messes up vertical alignment of the bullets.
 467+ // Bullets are therefore disabled (didn't look great anyway).
 468+ return "<li>" .
 469+ '<table class="searchResultImage">' .
 470+ '<tr>' .
 471+ '<td width="120" align="center" valign="top">' .
 472+ $thumb->toHtml( array( 'desc-link' => true ) ) .
 473+ '</td>' .
 474+ '<td valign="top">' .
 475+ $link .
 476+ $extract .
 477+ "<div class='mw-search-result-data'>{$score}{$desc}{$date}{$related}</div>" .
 478+ '</td>' .
 479+ '</tr>' .
 480+ '</table>' .
 481+ "</li>\n";
 482+ }
 483+ }
 484+ }
485485
486 - wfProfileOut( __METHOD__ );
487 - // HIER kommt die score ausgabe:
488 - return "<li><div class='mw-search-result-heading'>{$link} {$redirect} {$section}</div> {$extract}\n" .
489 - "<div class='mw-search-result-data'>{$score}{$date}{$related}</div>" .
490 - "</li>\n";
491 - }
 486+ wfProfileOut( __METHOD__ );
 487+ // HIER kommt die score ausgabe:
 488+ return "<li><div class='mw-search-result-heading'>{$link} {$redirect} {$section}</div> {$extract}\n" .
 489+ "<div class='mw-search-result-data'>{$score}{$date}{$related}</div>" .
 490+ "</li>\n";
 491+ }
492492
493 - protected function formHeader( $fieldSet, $resultsShown, $totalNum ) {
494 - global $wgLang;
 493+ protected function formHeader( $fieldSet, $resultsShown, $totalNum ) {
 494+ global $wgLang;
495495
496 - $out = Xml::openElement( 'div', array( 'class' => 'mw-search-formheader' ) );
 496+ $out = Xml::openElement( 'div', array( 'class' => 'mw-search-formheader' ) );
497497
498 - // Results-info
499 - if ( $resultsShown > 0 ) {
500 - if ( $totalNum > 0 ) {
501 - $top = wfMsgExt( 'showingresultsheader', array( 'parseinline' ), $wgLang->formatNum( $this->offset + 1 ), $wgLang->formatNum( $this->offset + $resultsShown ), $wgLang->formatNum( $totalNum ), $wgLang->formatNum( $resultsShown )
502 - );
503 - } elseif ( $resultsShown >= $this->limit ) {
504 - $top = wfShowingResults( $this->offset, $this->limit );
505 - } else {
506 - $top = wfShowingResultsNum( $this->offset, $this->limit, $resultsShown );
507 - }
508 - $out .= Xml::tags( 'div', array( 'class' => 'results-info' ), Xml::tags( 'ul', null, Xml::tags( 'li', null, $top ) ) );
509 - }
 498+ // Results-info
 499+ if ( $resultsShown > 0 ) {
 500+ if ( $totalNum > 0 ) {
 501+ $top = wfMsgExt( 'showingresultsheader', array( 'parseinline' ), $wgLang->formatNum( $this->offset + 1 ), $wgLang->formatNum( $this->offset + $resultsShown ), $wgLang->formatNum( $totalNum ), $wgLang->formatNum( $resultsShown )
 502+ );
 503+ } elseif ( $resultsShown >= $this->limit ) {
 504+ $top = wfShowingResults( $this->offset, $this->limit );
 505+ } else {
 506+ $top = wfShowingResultsNum( $this->offset, $this->limit, $resultsShown );
 507+ }
 508+ $out .= Xml::tags( 'div', array( 'class' => 'results-info' ), Xml::tags( 'ul', null, Xml::tags( 'li', null, $top ) ) );
 509+ }
510510
511 - $out .= Xml::element( 'div', array( 'style' => 'clear:both' ), '', false );
512 - $out .= Xml::closeElement( 'div' );
 511+ $out .= Xml::element( 'div', array( 'style' => 'clear:both' ), '', false );
 512+ $out .= Xml::closeElement( 'div' );
513513
514 - return $out;
515 - }
 514+ return $out;
 515+ }
516516
517 - protected function shortDialog( $fieldSet ) {
518 - $searchTitle = SpecialPage::getTitleFor( 'SolrSearch' );
 517+ protected function shortDialog( $fieldSet ) {
 518+ $searchTitle = SpecialPage::getTitleFor( 'SolrSearch' );
519519
520520
521 - if ( $fieldSet->getName() != 'search' ) {
522 - $out = Html::hidden( 'title', $searchTitle->getPrefixedText() . '/' . $fieldSet->getName() ) . "\n";
523 - } else {
524 - $out = Html::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n";
525 - }
526 - // Term box
 521+ if ( $fieldSet->getName() != 'search' ) {
 522+ $out = Html::hidden( 'title', $searchTitle->getPrefixedText() . '/' . $fieldSet->getName() ) . "\n";
 523+ } else {
 524+ $out = Html::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n";
 525+ }
 526+ // Term box
527527
528 - $lable = $fieldSet->getLable();
529 - $out .= '<table>';
 528+ $lable = $fieldSet->getLable();
 529+ $out .= '<table>';
530530
531 - foreach ( $fieldSet->getFields() as $key => $value ) {
532 - $out .= '<tr>';
533 - if ( isset( $lable[$key] ) ) {
534 - $out .= '<th>' . $lable[$key] . '</th>';
535 - }
536 - $out .= '<td>';
537 - $out .= Html::input( $key, $value, $key, array(
538 - 'id' => $key,
539 - 'size' => '50',
540 - 'autofocus'
541 - ) ) . "\n";
542 - $out .= '</td></tr>';
543 - }
544 - $out .= '<table>';
545 - $out .= Xml::submitButton( wfMsg( 'searchbutton' ) ) . "\n";
546 - return $out . $this->didYouMeanHtml;
547 - }
 531+ foreach ( $fieldSet->getFields() as $key => $value ) {
 532+ $out .= '<tr>';
 533+ if ( isset( $lable[$key] ) ) {
 534+ $out .= '<th>' . $lable[$key] . '</th>';
 535+ }
 536+ $out .= '<td>';
 537+ $out .= Html::input( $key, $value, $key, array(
 538+ 'id' => $key,
 539+ 'size' => '50',
 540+ 'autofocus'
 541+ ) ) . "\n";
 542+ $out .= '</td></tr>';
 543+ }
 544+ $out .= '<table>';
 545+ $out .= Xml::submitButton( wfMsg( 'searchbutton' ) ) . "\n";
 546+ return $out . $this->didYouMeanHtml;
 547+ }
548548
549549 }
Index: trunk/extensions/SolrStore/SolrConnectorStore.php
@@ -14,386 +14,386 @@
1515 */
1616 class SolrConnectorStore extends SMWStore {
1717
18 - static protected $smBaseStore;
 18+ static protected $smBaseStore;
1919
20 - /**
21 - * Get a handle for the storage backend that is used to manage the data.
22 - * Currently, it just returns one globally defined object, but the
23 - * infrastructure allows to set up load balancing and task-dependent use of
24 - * stores (e.g. using other stores for fast querying than for storing new
25 - * facts), somewhat similar to MediaWiki's DB implementation.
26 - *
27 - * @return SMWStore
28 - */
29 - static function &getBaseStore() {
30 - global $wgscBaseStore;
 20+ /**
 21+ * Get a handle for the storage backend that is used to manage the data.
 22+ * Currently, it just returns one globally defined object, but the
 23+ * infrastructure allows to set up load balancing and task-dependent use of
 24+ * stores (e.g. using other stores for fast querying than for storing new
 25+ * facts), somewhat similar to MediaWiki's DB implementation.
 26+ *
 27+ * @return SMWStore
 28+ */
 29+ static function &getBaseStore() {
 30+ global $wgscBaseStore;
3131
32 - if ( self::$smBaseStore === null ) {
33 - self::$smBaseStore = new $wgscBaseStore();
34 - }
 32+ if ( self::$smBaseStore === null ) {
 33+ self::$smBaseStore = new $wgscBaseStore();
 34+ }
3535
36 - return self::$smBaseStore;
37 - }
 36+ return self::$smBaseStore;
 37+ }
3838
3939 //// / Reading methods /////
4040
41 - /**
42 - * Retrieve all data stored about the given subject and return it as a
43 - * SMWSemanticData container. There are no options: it just returns all
44 - * available data as shown in the page's Factbox.
45 - * $filter is an array of strings that are datatype IDs. If given, the
46 - * function will avoid any work that is not necessary if only
47 - * properties of these types are of interest.
48 - *
49 - * @note There is no guarantee that the store does not retrieve more
50 - * data than requested when a filter is used. Filtering just ensures
51 - * that only necessary requests are made, i.e. it improves performance.
52 - */
53 - public function getSemanticData( SMWDIWikiPage $subject, $filter = false ) {
54 - return self::getBaseStore()->getSemanticData( $subject, $filter );
55 - }
 41+ /**
 42+ * Retrieve all data stored about the given subject and return it as a
 43+ * SMWSemanticData container. There are no options: it just returns all
 44+ * available data as shown in the page's Factbox.
 45+ * $filter is an array of strings that are datatype IDs. If given, the
 46+ * function will avoid any work that is not necessary if only
 47+ * properties of these types are of interest.
 48+ *
 49+ * @note There is no guarantee that the store does not retrieve more
 50+ * data than requested when a filter is used. Filtering just ensures
 51+ * that only necessary requests are made, i.e. it improves performance.
 52+ */
 53+ public function getSemanticData( SMWDIWikiPage $subject, $filter = false ) {
 54+ return self::getBaseStore()->getSemanticData( $subject, $filter );
 55+ }
5656
57 - /**
58 - * Get an array of all property values stored for the given subject and
59 - * property. The result is an array of SMWDataItem objects.
60 - *
61 - * If called with $subject == null, all values for the given property
62 - * are returned.
63 - *
64 - * @param $subject mixed SMWDIWikiPage or null
65 - * @param $property SMWDIProperty
66 - * @param $requestoptions SMWRequestOptions
67 - *
68 - * @return array of SMWDataItem
69 - */
70 - public function getPropertyValues( $subject, SMWDIProperty $property, $requestoptions = null ) {
71 - return self::getBaseStore()->getPropertyValues( $subject, $property, $requestoptions );
72 - }
 57+ /**
 58+ * Get an array of all property values stored for the given subject and
 59+ * property. The result is an array of SMWDataItem objects.
 60+ *
 61+ * If called with $subject == null, all values for the given property
 62+ * are returned.
 63+ *
 64+ * @param $subject mixed SMWDIWikiPage or null
 65+ * @param $property SMWDIProperty
 66+ * @param $requestoptions SMWRequestOptions
 67+ *
 68+ * @return array of SMWDataItem
 69+ */
 70+ public function getPropertyValues( $subject, SMWDIProperty $property, $requestoptions = null ) {
 71+ return self::getBaseStore()->getPropertyValues( $subject, $property, $requestoptions );
 72+ }
7373
74 - /**
75 - * Get an array of all subjects that have the given value for the given
76 - * property. The result is an array of SMWDIWikiPage objects. If null
77 - * is given as a value, all subjects having that property are returned.
78 - */
79 - public function getPropertySubjects( SMWDIProperty $property, $value, $requestoptions = null ) {
80 - return self::getBaseStore()->getPropertySubjects( $property, $value, $requestoptions );
81 - }
 74+ /**
 75+ * Get an array of all subjects that have the given value for the given
 76+ * property. The result is an array of SMWDIWikiPage objects. If null
 77+ * is given as a value, all subjects having that property are returned.
 78+ */
 79+ public function getPropertySubjects( SMWDIProperty $property, $value, $requestoptions = null ) {
 80+ return self::getBaseStore()->getPropertySubjects( $property, $value, $requestoptions );
 81+ }
8282
83 - /**
84 - * Get an array of all subjects that have some value for the given
85 - * property. The result is an array of SMWDIWikiPage objects.
86 - */
87 - public function getAllPropertySubjects( SMWDIProperty $property, $requestoptions = null ) {
88 - return self::getBaseStore()->getAllPropertySubjects( $property, $requestoptions );
89 - }
 83+ /**
 84+ * Get an array of all subjects that have some value for the given
 85+ * property. The result is an array of SMWDIWikiPage objects.
 86+ */
 87+ public function getAllPropertySubjects( SMWDIProperty $property, $requestoptions = null ) {
 88+ return self::getBaseStore()->getAllPropertySubjects( $property, $requestoptions );
 89+ }
9090
91 - /**
92 - * Get an array of all properties for which the given subject has some
93 - * value. The result is an array of SMWDIProperty objects.
94 - *
95 - * @param $subject SMWDIWikiPage denoting the subject
96 - * @param $requestoptions SMWRequestOptions optionally defining further options
97 - */
98 - public function getProperties( SMWDIWikiPage $subject, $requestoptions = null ) {
99 - return self::getBaseStore()->getProperties( $subject, $requestoptions );
100 - }
 91+ /**
 92+ * Get an array of all properties for which the given subject has some
 93+ * value. The result is an array of SMWDIProperty objects.
 94+ *
 95+ * @param $subject SMWDIWikiPage denoting the subject
 96+ * @param $requestoptions SMWRequestOptions optionally defining further options
 97+ */
 98+ public function getProperties( SMWDIWikiPage $subject, $requestoptions = null ) {
 99+ return self::getBaseStore()->getProperties( $subject, $requestoptions );
 100+ }
101101
102 - /**
103 - * Get an array of all properties for which there is some subject that
104 - * relates to the given value. The result is an array of SMWDIWikiPage
105 - * objects.
106 - * @note In some stores, this function might be implemented partially
107 - * so that only values of type Page (_wpg) are supported.
108 - */
109 - public function getInProperties( SMWDataItem $object, $requestoptions = null ) {
110 - return self::getBaseStore()->getInProperties( $object, $requestoptions );
111 - }
 102+ /**
 103+ * Get an array of all properties for which there is some subject that
 104+ * relates to the given value. The result is an array of SMWDIWikiPage
 105+ * objects.
 106+ * @note In some stores, this function might be implemented partially
 107+ * so that only values of type Page (_wpg) are supported.
 108+ */
 109+ public function getInProperties( SMWDataItem $object, $requestoptions = null ) {
 110+ return self::getBaseStore()->getInProperties( $object, $requestoptions );
 111+ }
112112
113113 //// / Writing methods /////
114114
115 - /**
116 - * Delete all semantic properties that the given subject has. This
117 - * includes relations, attributes, and special properties. This does
118 - * not delete the respective text from the wiki, but only clears the
119 - * stored data.
120 - *
121 - * @param Title $subject
122 - */
123 - public function deleteSubject( Title $subject ) {
124 - global $wgSolrTalker;
125 - // TODO: Update Solr to reflect the deleting of semantic properties
 115+ /**
 116+ * Delete all semantic properties that the given subject has. This
 117+ * includes relations, attributes, and special properties. This does
 118+ * not delete the respective text from the wiki, but only clears the
 119+ * stored data.
 120+ *
 121+ * @param Title $subject
 122+ */
 123+ public function deleteSubject( Title $subject ) {
 124+ global $wgSolrTalker;
 125+ // TODO: Update Solr to reflect the deleting of semantic properties
126126
127 - $wgSolrTalker->deleteDocId( $subject );
128 - return self::getBaseStore()->deleteSubject( $subject );
129 - }
 127+ $wgSolrTalker->deleteDocId( $subject );
 128+ return self::getBaseStore()->deleteSubject( $subject );
 129+ }
130130
131 - /**
132 - * Update the semantic data stored for some individual. The data is
133 - * given as a SMWSemanticData object, which contains all semantic data
134 - * for one particular subject.
135 - *
136 - * @param SMWSemanticData $data
137 - */
138 - public function doDataUpdate( SMWSemanticData $data ) {
139 - global $wgSolrTalker;
140 - $wgSolrTalker->parseSemanticData( $data );
141 - return self::getBaseStore()->doDataUpdate( $data );
142 - }
 131+ /**
 132+ * Update the semantic data stored for some individual. The data is
 133+ * given as a SMWSemanticData object, which contains all semantic data
 134+ * for one particular subject.
 135+ *
 136+ * @param SMWSemanticData $data
 137+ */
 138+ public function doDataUpdate( SMWSemanticData $data ) {
 139+ global $wgSolrTalker;
 140+ $wgSolrTalker->parseSemanticData( $data );
 141+ return self::getBaseStore()->doDataUpdate( $data );
 142+ }
143143
144 - /**
145 - * Update the store to reflect a renaming of some article. Normally
146 - * this happens when moving pages in the wiki, and in this case there
147 - * is also a new redirect page generated at the old position. The title
148 - * objects given are only used to specify the name of the title before
149 - * and after the move -- do not use their IDs for anything! The ID of
150 - * the moved page is given in $pageid, and the ID of the newly created
151 - * redirect, if any, is given by $redirid. If no new page was created,
152 - * $redirid will be 0.
153 - */
154 - public function changeTitle( Title $oldtitle, Title $newtitle, $pageid, $redirid = 0 ) {
 144+ /**
 145+ * Update the store to reflect a renaming of some article. Normally
 146+ * this happens when moving pages in the wiki, and in this case there
 147+ * is also a new redirect page generated at the old position. The title
 148+ * objects given are only used to specify the name of the title before
 149+ * and after the move -- do not use their IDs for anything! The ID of
 150+ * the moved page is given in $pageid, and the ID of the newly created
 151+ * redirect, if any, is given by $redirid. If no new page was created,
 152+ * $redirid will be 0.
 153+ */
 154+ public function changeTitle( Title $oldtitle, Title $newtitle, $pageid, $redirid = 0 ) {
155155
156 - // TODO: Update Solr to reflect a renaming of some article
157 - return self::getBaseStore()->changeTitle( $oldtitle, $newtitle, $pageid, $redirid );
158 - }
 156+ // TODO: Update Solr to reflect a renaming of some article
 157+ return self::getBaseStore()->changeTitle( $oldtitle, $newtitle, $pageid, $redirid );
 158+ }
159159
160160 //// / Query answering /////
161161
162 - /**
163 - * Execute the provided query and return the result as an
164 - * SMWQueryResult if the query was a usual instance retrieval query. In
165 - * the case that the query asked for a plain string (querymode
166 - * MODE_COUNT or MODE_DEBUG) a plain wiki and HTML-compatible string is
167 - * returned.
168 - *
169 - * @param SMWQuery $query
170 - *
171 - * @return SMWQueryResult
172 - */
173 - public function getQueryResult( SMWQuery $query ) {
174 - // IF YOU SEE THIS HERE PLEASE IGNORE IT!
175 - // Our first aproche was it to create new SMWStore for Querying Data
176 - // but we had big Problems recreating and parsing the SMW Query Syntax
177 - // that we just Stoped at this Point here. Maybe we will finish it someday
178 - $wgSolrTalker = new SolrTalker();
179 - if ( property_exists( $query, 'params' ) &&
180 - array_key_exists( 'source', $query->params ) &&
181 - $query->params['source'] == 'solr' ) {
 162+ /**
 163+ * Execute the provided query and return the result as an
 164+ * SMWQueryResult if the query was a usual instance retrieval query. In
 165+ * the case that the query asked for a plain string (querymode
 166+ * MODE_COUNT or MODE_DEBUG) a plain wiki and HTML-compatible string is
 167+ * returned.
 168+ *
 169+ * @param SMWQuery $query
 170+ *
 171+ * @return SMWQueryResult
 172+ */
 173+ public function getQueryResult( SMWQuery $query ) {
 174+ // IF YOU SEE THIS HERE PLEASE IGNORE IT!
 175+ // Our first aproche was it to create new SMWStore for Querying Data
 176+ // but we had big Problems recreating and parsing the SMW Query Syntax
 177+ // that we just Stoped at this Point here. Maybe we will finish it someday
 178+ $wgSolrTalker = new SolrTalker();
 179+ if ( property_exists( $query, 'params' ) &&
 180+ array_key_exists( 'source', $query->params ) &&
 181+ $query->params['source'] == 'solr' ) {
182182
183 - $results = array();
184 - $dbkey = '';
185 - $namespace = 0;
186 - $interwiki = '';
 183+ $results = array();
 184+ $dbkey = '';
 185+ $namespace = 0;
 186+ $interwiki = '';
187187
188 - echo( "SOLR query: {$query->getQueryString()}\n" );
 188+ echo( "SOLR query: {$query->getQueryString()}\n" );
189189
190 - echo( "Search is Powered by Solr!" );
191 - echo $queryStr = urldecode( $wgSolrTalker->parseSolrQuery( $query->getQueryString() ) );
 190+ echo( "Search is Powered by Solr!" );
 191+ echo $queryStr = urldecode( $wgSolrTalker->parseSolrQuery( $query->getQueryString() ) );
192192
193193
194 - // Get Sort Parameters and add them to the QueryString
195 - if ( $query->sort ) {
196 - // TODO: Der Inhalt von Sort muss genau der Name eines der Felder von Solr sein
197 - // um danach Sortieren zu können. Deshalb Wird eine Liste alle Solr Felder
198 - // Benötigt um Festzustellen welches Feld gemeint ist bzw. welche _XYZ Endung
199 - // an dem Ende des Feldes angehängt wurde.
200 - //
 194+ // Get Sort Parameters and add them to the QueryString
 195+ if ( $query->sort ) {
 196+ // TODO: Der Inhalt von Sort muss genau der Name eines der Felder von Solr sein
 197+ // um danach Sortieren zu können. Deshalb Wird eine Liste alle Solr Felder
 198+ // Benötigt um Festzustellen welches Feld gemeint ist bzw. welche _XYZ Endung
 199+ // an dem Ende des Feldes angehängt wurde.
 200+ //
201201
202202
203 - $sort = $wgSolrTalker->findField( $query->params['sort'], $query->params['order'] );
204 - $queryStr .= '&sort%3D' . $sort . '+' . trim( $query->params['order'] );
205 - // $queryStr = $queryStr . '&sort=' . trim($sort . '+' . trim($query->params['order']));
206 - // TODO: Mehrer Sort parameter auslesen wenn sie vorhanden sind.
207 - }
208 -// else {
209 -// $queryStr = $queryStr . '&sort=pagetitle';
210 -// }
 203+ $sort = $wgSolrTalker->findField( $query->params['sort'], $query->params['order'] );
 204+ $queryStr .= '&sort%3D' . $sort . '+' . trim( $query->params['order'] );
 205+ // $queryStr = $queryStr . '&sort=' . trim($sort . '+' . trim($query->params['order']));
 206+ // TODO: Mehrer Sort parameter auslesen wenn sie vorhanden sind.
 207+ }
 208+// else {
 209+// $queryStr = $queryStr . '&sort=pagetitle';
 210+// }
211211
212 - // TODO: Prüfen wieso nur 1 Ergebniss ausgegeben wird
213 - echo 'Query Limit:' . $query->getLimit();
 212+ // TODO: Prüfen wieso nur 1 Ergebniss ausgegeben wird
 213+ echo 'Query Limit:' . $query->getLimit();
214214
215 - echo ( "SEARCHRESULT: " . $xml = $wgSolrTalker->solrQuery( $queryStr, $query->getOffset(), $query->getLimit() ) );
216 - echo( "<br/>" );
217 - // TODO: Move this Code to parseSolrResult
218 - $numFound = $xml->result['numFound'];
219 - // print_r('1: ' . $xml->{"result"});
220 - foreach ( $xml->result->doc as $doc ) {
221 - foreach ( $doc->str as $field ) {
222 - switch ( $field['name'] ) {
223 - case 'dbkey':
224 - $dbkey = $field;
225 - break;
226 - case 'interwiki':
227 - $interwiki = $field;
228 - break;
229 - case 'namespace':
230 - $namespace = $field;
231 - break;
232 - }
233 - }
234 - // Multivalue Felder
235 - foreach ( $doc->arr as $field ) {
236 - switch ( $field['name'] ) {
237 - case 'dbkey':
238 - $dbkey = $field;
239 - break;
240 - case 'interwiki':
241 - $interwiki = $field;
242 - break;
243 - case 'namespace':
244 - $namespace = $field;
245 - break;
246 - }
247 - foreach ( $field->str as $value ) {
248 - $value;
249 - }
250 - }
251 - $results[] = new SMWDIWikiPage( $dbkey, $namespace, $interwiki );
252 - }
 215+ echo ( "SEARCHRESULT: " . $xml = $wgSolrTalker->solrQuery( $queryStr, $query->getOffset(), $query->getLimit() ) );
 216+ echo( "<br/>" );
 217+ // TODO: Move this Code to parseSolrResult
 218+ $numFound = $xml->result['numFound'];
 219+ // print_r('1: ' . $xml->{"result"});
 220+ foreach ( $xml->result->doc as $doc ) {
 221+ foreach ( $doc->str as $field ) {
 222+ switch ( $field['name'] ) {
 223+ case 'dbkey':
 224+ $dbkey = $field;
 225+ break;
 226+ case 'interwiki':
 227+ $interwiki = $field;
 228+ break;
 229+ case 'namespace':
 230+ $namespace = $field;
 231+ break;
 232+ }
 233+ }
 234+ // Multivalue Felder
 235+ foreach ( $doc->arr as $field ) {
 236+ switch ( $field['name'] ) {
 237+ case 'dbkey':
 238+ $dbkey = $field;
 239+ break;
 240+ case 'interwiki':
 241+ $interwiki = $field;
 242+ break;
 243+ case 'namespace':
 244+ $namespace = $field;
 245+ break;
 246+ }
 247+ foreach ( $field->str as $value ) {
 248+ $value;
 249+ }
 250+ }
 251+ $results[] = new SMWDIWikiPage( $dbkey, $namespace, $interwiki );
 252+ }
253253
254 - // Do we have more Results ?
255 - $more = false;
256 - // TODO: Does this Work ?
257 - echo 'Number of Records: ' . $numFound;
258 - if ( $numFound > 10 ) {
259 - $more = true;
260 - }
 254+ // Do we have more Results ?
 255+ $more = false;
 256+ // TODO: Does this Work ?
 257+ echo 'Number of Records: ' . $numFound;
 258+ if ( $numFound > 10 ) {
 259+ $more = true;
 260+ }
261261
262 - // return new SMWQueryResult($printRequests, $query, $results, $store);
263 - return new SMWQueryResult( $query->getDescription()->getPrintrequests(), $query, $results, $this, $more );
264 - } else {
265 - return self::getBaseStore()->getQueryResult( $query );
266 - }
267 - }
 262+ // return new SMWQueryResult($printRequests, $query, $results, $store);
 263+ return new SMWQueryResult( $query->getDescription()->getPrintrequests(), $query, $results, $this, $more );
 264+ } else {
 265+ return self::getBaseStore()->getQueryResult( $query );
 266+ }
 267+ }
268268
269269 //// / Special page functions /////
270270
271 - /**
272 - * Return all properties that have been used on pages in the wiki. The
273 - * result is an array of arrays, each containing a property title and a
274 - * count. The expected order is alphabetical w.r.t. to property title
275 - * texts.
276 - *
277 - * @param SMWRequestOptions $requestoptions
278 - *
279 - * @return array
280 - */
281 - public function getPropertiesSpecial( $requestoptions = null ) {
282 - return self::getBaseStore()->getPropertiesSpecial( $requestoptions );
283 - }
 271+ /**
 272+ * Return all properties that have been used on pages in the wiki. The
 273+ * result is an array of arrays, each containing a property title and a
 274+ * count. The expected order is alphabetical w.r.t. to property title
 275+ * texts.
 276+ *
 277+ * @param SMWRequestOptions $requestoptions
 278+ *
 279+ * @return array
 280+ */
 281+ public function getPropertiesSpecial( $requestoptions = null ) {
 282+ return self::getBaseStore()->getPropertiesSpecial( $requestoptions );
 283+ }
284284
285 - /**
286 - * Return all properties that have been declared in the wiki but that
287 - * are not used on any page. Stores might restrict here to those
288 - * properties that have been given a type if they have no efficient
289 - * means of accessing the set of all pages in the property namespace.
290 - *
291 - * @param SMWRequestOptions $requestoptions
292 - *
293 - * @return array of SMWDIProperty
294 - */
295 - public function getUnusedPropertiesSpecial( $requestoptions = null ) {
296 - return self::getBaseStore()->getUnusedPropertiesSpecial( $requestoptions );
297 - }
 285+ /**
 286+ * Return all properties that have been declared in the wiki but that
 287+ * are not used on any page. Stores might restrict here to those
 288+ * properties that have been given a type if they have no efficient
 289+ * means of accessing the set of all pages in the property namespace.
 290+ *
 291+ * @param SMWRequestOptions $requestoptions
 292+ *
 293+ * @return array of SMWDIProperty
 294+ */
 295+ public function getUnusedPropertiesSpecial( $requestoptions = null ) {
 296+ return self::getBaseStore()->getUnusedPropertiesSpecial( $requestoptions );
 297+ }
298298
299 - /**
300 - * Return all properties that are used on some page but that do not
301 - * have any page describing them. Stores that have no efficient way of
302 - * accessing the set of all existing pages can extend this list to all
303 - * properties that are used but do not have a type assigned to them.
304 - *
305 - * @param SMWRequestOptions $requestoptions
306 - *
307 - * @return array of array( SMWDIProperty, int )
308 - */
309 - public function getWantedPropertiesSpecial( $requestoptions = null ) {
310 - return self::getBaseStore()->getWantedPropertiesSpecial( $requestoptions );
311 - }
 299+ /**
 300+ * Return all properties that are used on some page but that do not
 301+ * have any page describing them. Stores that have no efficient way of
 302+ * accessing the set of all existing pages can extend this list to all
 303+ * properties that are used but do not have a type assigned to them.
 304+ *
 305+ * @param SMWRequestOptions $requestoptions
 306+ *
 307+ * @return array of array( SMWDIProperty, int )
 308+ */
 309+ public function getWantedPropertiesSpecial( $requestoptions = null ) {
 310+ return self::getBaseStore()->getWantedPropertiesSpecial( $requestoptions );
 311+ }
312312
313 - /**
314 - * Return statistical information as an associative array with the
315 - * following keys:
316 - * - 'PROPUSES': Number of property instances (value assignments) in the datatbase
317 - * - 'USEDPROPS': Number of properties that are used with at least one value
318 - * - 'DECLPROPS': Number of properties that have been declared (i.e. assigned a type)
319 - *
320 - * @return array
321 - */
322 - public function getStatistics() {
323 - return self::getBaseStore()->getStatistics();
324 - }
 313+ /**
 314+ * Return statistical information as an associative array with the
 315+ * following keys:
 316+ * - 'PROPUSES': Number of property instances (value assignments) in the datatbase
 317+ * - 'USEDPROPS': Number of properties that are used with at least one value
 318+ * - 'DECLPROPS': Number of properties that have been declared (i.e. assigned a type)
 319+ *
 320+ * @return array
 321+ */
 322+ public function getStatistics() {
 323+ return self::getBaseStore()->getStatistics();
 324+ }
325325
326326 //// / Setup store /////
327327
328 - /**
329 - * Setup all storage structures properly for using the store. This
330 - * function performs tasks like creation of database tables. It is
331 - * called upon installation as well as on upgrade: hence it must be
332 - * able to upgrade existing storage structures if needed. It should
333 - * return "true" if successful and return a meaningful string error
334 - * message otherwise.
335 - *
336 - * The parameter $verbose determines whether the procedure is allowed
337 - * to report on its progress. This is doen by just using print and
338 - * possibly ob_flush/flush. This is also relevant for preventing
339 - * timeouts during long operations. All output must be valid in an HTML
340 - * context, but should preferrably be plain text, possibly with some
341 - * linebreaks and weak markup.
342 - *
343 - * @param boolean $verbose
344 - */
345 - public function setup( $verbose = true ) {
 328+ /**
 329+ * Setup all storage structures properly for using the store. This
 330+ * function performs tasks like creation of database tables. It is
 331+ * called upon installation as well as on upgrade: hence it must be
 332+ * able to upgrade existing storage structures if needed. It should
 333+ * return "true" if successful and return a meaningful string error
 334+ * message otherwise.
 335+ *
 336+ * The parameter $verbose determines whether the procedure is allowed
 337+ * to report on its progress. This is doen by just using print and
 338+ * possibly ob_flush/flush. This is also relevant for preventing
 339+ * timeouts during long operations. All output must be valid in an HTML
 340+ * context, but should preferrably be plain text, possibly with some
 341+ * linebreaks and weak markup.
 342+ *
 343+ * @param boolean $verbose
 344+ */
 345+ public function setup( $verbose = true ) {
346346
347 - // TODO: Setup data structures on the the Solr server, if necessary
 347+ // TODO: Setup data structures on the the Solr server, if necessary
348348
349 - return self::getBaseStore()->setup( $verbose );
350 - }
 349+ return self::getBaseStore()->setup( $verbose );
 350+ }
351351
352 - /**
353 - * Drop (delete) all storage structures created by setup(). This will
354 - * delete all semantic data and possibly leave the wiki uninitialised.
355 - *
356 - * @param boolean $verbose
357 - */
358 - public function drop( $verbose = true ) {
359 - global $wgSolrTalker;
360 - $wgSolrTalker->deleteAllDocs();
361 - // Drop all data from Solr
 352+ /**
 353+ * Drop (delete) all storage structures created by setup(). This will
 354+ * delete all semantic data and possibly leave the wiki uninitialised.
 355+ *
 356+ * @param boolean $verbose
 357+ */
 358+ public function drop( $verbose = true ) {
 359+ global $wgSolrTalker;
 360+ $wgSolrTalker->deleteAllDocs();
 361+ // Drop all data from Solr
362362
363 - return self::getBaseStore()->drop( $verbose );
364 - }
 363+ return self::getBaseStore()->drop( $verbose );
 364+ }
365365
366 - /**
367 - * Refresh some objects in the store, addressed by numerical ids. The
368 - * meaning of the ids is private to the store, and does not need to
369 - * reflect the use of IDs elsewhere (e.g. page ids). The store is to
370 - * refresh $count objects starting from the given $index. Typically,
371 - * updates are achieved by generating update jobs. After the operation,
372 - * $index is set to the next index that should be used for continuing
373 - * refreshing, or to -1 for signaling that no objects of higher index
374 - * require refresh. The method returns a decimal number between 0 and 1
375 - * to indicate the overall progress of the refreshing (e.g. 0.7 if 70%
376 - * of all objects were refreshed).
377 - *
378 - * The optional parameter $namespaces may contain an array of namespace
379 - * constants. If given, only objects from those namespaces will be
380 - * refreshed. The default value FALSE disables this feature.
381 - *
382 - * The optional parameter $usejobs indicates whether updates should be
383 - * processed later using MediaWiki jobs, instead of doing all updates
384 - * immediately. The default is TRUE.
385 - *
386 - * @param $index integer
387 - * @param $count integer
388 - * @param $namespaces mixed array or false
389 - * @param $usejobs boolean
390 - *
391 - * @return decimal between 0 and 1 to indicate the overall progress of the refreshing
392 - */
393 - public function refreshData( &$index, $count, $namespaces = false, $usejobs = true ) {
 366+ /**
 367+ * Refresh some objects in the store, addressed by numerical ids. The
 368+ * meaning of the ids is private to the store, and does not need to
 369+ * reflect the use of IDs elsewhere (e.g. page ids). The store is to
 370+ * refresh $count objects starting from the given $index. Typically,
 371+ * updates are achieved by generating update jobs. After the operation,
 372+ * $index is set to the next index that should be used for continuing
 373+ * refreshing, or to -1 for signaling that no objects of higher index
 374+ * require refresh. The method returns a decimal number between 0 and 1
 375+ * to indicate the overall progress of the refreshing (e.g. 0.7 if 70%
 376+ * of all objects were refreshed).
 377+ *
 378+ * The optional parameter $namespaces may contain an array of namespace
 379+ * constants. If given, only objects from those namespaces will be
 380+ * refreshed. The default value FALSE disables this feature.
 381+ *
 382+ * The optional parameter $usejobs indicates whether updates should be
 383+ * processed later using MediaWiki jobs, instead of doing all updates
 384+ * immediately. The default is TRUE.
 385+ *
 386+ * @param $index integer
 387+ * @param $count integer
 388+ * @param $namespaces mixed array or false
 389+ * @param $usejobs boolean
 390+ *
 391+ * @return decimal between 0 and 1 to indicate the overall progress of the refreshing
 392+ */
 393+ public function refreshData( &$index, $count, $namespaces = false, $usejobs = true ) {
394394
395 - // TODO: Do we need to do something here for Solr? Can we do something?
 395+ // TODO: Do we need to do something here for Solr? Can we do something?
396396
397 - return self::getBaseStore()->refreshData( $index, $count, $namespaces, $usejobs );
398 - }
 397+ return self::getBaseStore()->refreshData( $index, $count, $namespaces, $usejobs );
 398+ }
399399
400400 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r106682stylize; insert messages for qqqfoxtrott20:11, 19 December 2011

Status & tagging log