Index: trunk/extensions/SolrStore/SolrStore.php |
— | — | @@ -5,10 +5,9 @@ |
6 | 6 | * Apache Solr. |
7 | 7 | * |
8 | 8 | * @defgroup SolrStore |
9 | | - * @author Stephan Gambke, Simon Bachenberg |
10 | | - * @version 0.5 Beta |
| 9 | + * @author Stephan Gambke, Simon Bachenberg, Sascha Schueller |
| 10 | + * @version 0.6 Beta |
11 | 11 | */ |
12 | | - |
13 | 12 | /** |
14 | 13 | * The main file of the SolrConnector extension |
15 | 14 | * |
— | — | @@ -26,17 +25,17 @@ |
27 | 26 | /** |
28 | 27 | * The Solr Connector version |
29 | 28 | */ |
30 | | -define( 'SC_VERSION', '0.5 Beta' ); |
| 29 | +define( 'SC_VERSION', '0.6 Beta' ); |
31 | 30 | |
32 | 31 | // register the extension |
33 | 32 | // TODO: Add other authors here and in the file header |
34 | 33 | $wgExtensionCredits[ defined( 'SEMANTIC_EXTENSION_TYPE' ) ? 'semantic' : 'other' ][ ] = array( |
35 | | - 'path' =>__FILE__, |
36 | | - 'name' =>'SolrStore', |
37 | | - 'author' =>array( '[https://www.mediawiki.org/wiki/User:F.trott Stephan Gambke]', '[https://www.mediawiki.org/wiki/User:SBachenberg Simon Bachenberg]', 'Sascha Schüller' ), |
38 | | - 'url' =>'https://www.mediawiki.org/wiki/Extension:SolrStore', |
| 34 | + 'path'=>__FILE__, |
| 35 | + 'name'=>'SolrStore', |
| 36 | + 'author'=>array( '[https://www.mediawiki.org/wiki/User:F.trott Stephan Gambke]', '[https://www.mediawiki.org/wiki/User:SBachenberg Simon Bachenberg]', 'Sascha Schüller' ), |
| 37 | + 'url'=>'https://www.mediawiki.org/wiki/Extension:SolrStore', |
39 | 38 | 'descriptionmsg'=>'solrstore-desc', |
40 | | - 'version' =>SC_VERSION, |
| 39 | + 'version'=>SC_VERSION, |
41 | 40 | ); |
42 | 41 | |
43 | 42 | |
— | — | @@ -48,16 +47,16 @@ |
49 | 48 | $wgExtensionMessagesFiles[ 'SolrStoreAlias' ] = $dir . '/SolrStore.alias.php'; |
50 | 49 | |
51 | 50 | // register class files with the Autoloader |
52 | | -$wgAutoloadClasses[ 'SolrConnectorStore' ] = $dir . '/SolrConnectorStore.php'; |
53 | | -$wgAutoloadClasses[ 'SolrDoc' ] = $dir . '/SolrDoc.php'; |
54 | | -$wgAutoloadClasses[ 'SolrTalker' ] = $dir . '/SolrTalker.php'; |
55 | | -$wgAutoloadClasses[ 'SolrSearch' ] = $dir . '/SolrSearch.php'; |
56 | | -$wgAutoloadClasses[ 'SolrResult' ] = $dir . '/SolrSearch.php'; |
57 | | -$wgAutoloadClasses[ 'SolrSearchSet' ] = $dir . '/SolrSearch.php'; |
58 | | -$wgAutoloadClasses[ 'SpecialSolrSearch' ] = $dir . '/SpecialSolrSearch.php'; |
59 | | -$wgAutoloadClasses[ 'SolrSearchFieldSet' ] = $dir . '/SolrSearchFieldSet.php'; |
| 51 | +$wgAutoloadClasses[ 'SolrConnectorStore' ] = $dir . '/SolrConnectorStore.php'; |
| 52 | +$wgAutoloadClasses[ 'SolrDoc' ] = $dir . '/SolrDoc.php'; |
| 53 | +$wgAutoloadClasses[ 'SolrTalker' ] = $dir . '/SolrTalker.php'; |
| 54 | +$wgAutoloadClasses[ 'SolrSearch' ] = $dir . '/SolrSearch.php'; |
| 55 | +$wgAutoloadClasses[ 'SolrResult' ] = $dir . '/SolrSearch.php'; |
| 56 | +$wgAutoloadClasses[ 'SolrSearchSet' ] = $dir . '/SolrSearch.php'; |
| 57 | +$wgAutoloadClasses[ 'SpecialSolrSearch' ] = $dir . '/SpecialSolrSearch.php'; |
| 58 | +$wgAutoloadClasses[ 'SolrSearchFieldSet' ] = $dir . '/SolrSearchFieldSet.php'; |
| 59 | +$wgAutoloadClasses[ 'SolrSearchTemplateLoader' ] = $dir . '/SolrSearchTemplateLoader.php'; |
60 | 60 | |
61 | | - |
62 | 61 | // Specialpage |
63 | 62 | $wgSpecialPages[ 'SolrSearch' ] = 'SpecialSolrSearch'; # Tell MediaWiki about the new special page and its class name |
64 | 63 | $wgSpecialPageGroups[ 'SolrSearch' ] = 'smw_group'; |
— | — | @@ -66,12 +65,14 @@ |
67 | 66 | // original store |
68 | 67 | $wgscBaseStore = $smwgDefaultStore; |
69 | 68 | $smwgDefaultStore = "SolrConnectorStore"; |
70 | | -$smwgQuerySources[ "solr" ] = "SolrConnectorStore"; |
| 69 | +$smwgQuerySources[ "solr" ] = "SolrConnectorStore"; |
71 | 70 | $wgSearchType = 'SolrSearch'; |
72 | 71 | |
73 | 72 | // Solr Configuration |
74 | | -$wgSolrTalker = new SolrTalker(); |
75 | | -$wgSolrShowRelated = true; |
76 | | -$wgSolrDebug = false; |
77 | | -$wgSolrUrl = 'http://127.0.0.1:8080/solr'; |
78 | | -$wgSolrFields = array( ); |
| 73 | +$wgSolrTalker = new SolrTalker(); |
| 74 | +$SolrSearchTemplateLoader = new SolrSearchTemplateLoader(); |
| 75 | +$wgSolrUrl = 'http://127.0.0.1:8080/solr'; |
| 76 | +$wgSolrTemplate = "_Standart"; |
| 77 | +$wgSolrFields = array( ); |
| 78 | +$wgSolrShowRelated = true; |
| 79 | +$wgSolrDebug = false; |
Index: trunk/extensions/SolrStore/SolrSearch.php |
— | — | @@ -4,7 +4,7 @@ |
5 | 5 | * |
6 | 6 | * @ingroup SolrStore |
7 | 7 | * @file |
8 | | - * @author Simon Bachenberg |
| 8 | + * @author Sascha Schueller, Simon Bachenberg |
9 | 9 | */ |
10 | 10 | |
11 | 11 | /** |
— | — | @@ -17,7 +17,7 @@ |
18 | 18 | var $limit = 10; |
19 | 19 | var $offset = 0; |
20 | 20 | var $prefix = ''; |
21 | | - var $searchTerms = array(); |
| 21 | + var $searchTerms = array( ); |
22 | 22 | var $namespaces = array( NS_MAIN ); |
23 | 23 | var $showRedirects = false; |
24 | 24 | var $solrTalker; |
— | — | @@ -60,10 +60,10 @@ |
61 | 61 | static function prefixSearch( $ns, $search, $limit, &$results ) { |
62 | 62 | echo 'Prefix Search!<br />'; // @todo Is this a debug line? Certainly looks like one...if so, comment out/remove! |
63 | 63 | $it = SolrSearchSet::newFromQuery( 'prefix', $search, $ns, $limit, 0 ); |
64 | | - $results = array(); |
| 64 | + $results = array( ); |
65 | 65 | if ( $it ) { // $it can be null |
66 | 66 | while ( $res = $it->next() ) { |
67 | | - $results[] = $res->getTitle()->getPrefixedText(); |
| 67 | + $results[ ] = $res->getTitle()->getPrefixedText(); |
68 | 68 | } |
69 | 69 | } |
70 | 70 | return false; |
— | — | @@ -101,18 +101,18 @@ |
102 | 102 | $rindex = 0; // point to last rewritten character |
103 | 103 | $inquotes = false; |
104 | 104 | |
105 | | - // "search everything" keyword |
| 105 | +// "search everything" keyword |
106 | 106 | $allkeyword = wfMsgForContent( 'searchall' ); |
107 | 107 | |
108 | 108 | $qlen = strlen( $query ); |
109 | 109 | |
110 | | - // quick check, most of the time we don't need any rewriting |
| 110 | +// quick check, most of the time we don't need any rewriting |
111 | 111 | if ( strpos( $query, ':' ) === false ) { |
112 | 112 | wfProfileOut( __METHOD__ ); |
113 | 113 | return $query; |
114 | 114 | } |
115 | 115 | |
116 | | - // check if this is query for related articles |
| 116 | +// check if this is query for related articles |
117 | 117 | $relatedkey = wfMsgForContent( 'searchrelated' ) . ':'; |
118 | 118 | if ( $wgSolrUseRelated && strncmp( $query, $relatedkey, strlen( $relatedkey ) ) == 0 ) { |
119 | 119 | $this->related = true; |
— | — | @@ -128,18 +128,18 @@ |
129 | 129 | array_keys( array_merge( $wgNamespaceAliases, $wgContLang->getNamespaceAliases() ) ) |
130 | 130 | ); |
131 | 131 | |
132 | | - # add all namespace names w/o spaces |
133 | | - $nsNames = array(); |
| 132 | +# add all namespace names w/o spaces |
| 133 | + $nsNames = array( ); |
134 | 134 | foreach ( $nsNamesRaw as $ns ) { |
135 | 135 | if ( $ns != '' ) { |
136 | | - $nsNames[] = $ns; |
137 | | - $nsNames[] = str_replace( '_', ' ', $ns ); |
| 136 | + $nsNames[ ] = $ns; |
| 137 | + $nsNames[ ] = str_replace( '_', ' ', $ns ); |
138 | 138 | } |
139 | 139 | } |
140 | 140 | |
141 | 141 | $regexp = implode( '|', array_unique( $nsNames ) ); |
142 | 142 | |
143 | | - # rewrite the query by replacing valid namespace names |
| 143 | +# rewrite the query by replacing valid namespace names |
144 | 144 | $parts = preg_split( '/(")/', $query, -1, PREG_SPLIT_DELIM_CAPTURE ); |
145 | 145 | $inquotes = false; |
146 | 146 | $rewritten = ''; |
— | — | @@ -150,9 +150,9 @@ |
151 | 151 | } elseif ( $inquotes ) { |
152 | 152 | $rewritten .= $part; |
153 | 153 | } else { |
154 | | - # replace namespaces |
| 154 | +# replace namespaces |
155 | 155 | $r = preg_replace_callback( '/(^|[| :])(' . $regexp . '):/i', array( $this, 'replaceNamespace' ), $part ); |
156 | | - # replace to backend all: notation |
| 156 | +# replace to backend all: notation |
157 | 157 | $rewritten .= str_replace( $allkeyword . ':', 'all:', $r ); |
158 | 158 | } |
159 | 159 | } |
— | — | @@ -164,11 +164,11 @@ |
165 | 165 | /** callback to replace namespace names to internal notation, e.g. User: -> [2]: */ |
166 | 166 | function replaceNamespace( $matches ) { |
167 | 167 | global $wgContLang; |
168 | | - $inx = $wgContLang->getNsIndex( str_replace( ' ', '_', $matches[2] ) ); |
| 168 | + $inx = $wgContLang->getNsIndex( str_replace( ' ', '_', $matches[ 2 ] ) ); |
169 | 169 | if ( $inx === false ) { |
170 | | - return $matches[0]; |
| 170 | + return $matches[ 0 ]; |
171 | 171 | } else { |
172 | | - return $matches[1] . "[$inx]:"; |
| 172 | + return $matches[ 1 ] . "[$inx]:"; |
173 | 173 | } |
174 | 174 | } |
175 | 175 | |
— | — | @@ -181,7 +181,7 @@ |
182 | 182 | global $wgSolrSearchVersion; |
183 | 183 | |
184 | 184 | if ( $wgSolrSearchVersion >= 2.1 && $this->prefix != '' ) { |
185 | | - # convert to internal backend prefix notation |
| 185 | +# convert to internal backend prefix notation |
186 | 186 | $term = $term . ' prefix:' . $this->prefix; |
187 | 187 | } |
188 | 188 | |
— | — | @@ -204,223 +204,23 @@ |
205 | 205 | return false; |
206 | 206 | } |
207 | 207 | |
208 | | - function SolrResult( $result, $method ) { |
209 | | - global $wgContLang; |
| 208 | + function SolrResult( $xml ) { |
| 209 | + global $SolrSearchTemplateLoader; |
| 210 | + wfDebug( "Solr line: '$xml'\n" ); |
210 | 211 | |
211 | | - $score = null; |
212 | | - $interwiki = null; |
213 | | - $namespace = null; |
214 | | - $title = null; |
215 | | - |
216 | | - $xml = $result; |
217 | | - wfDebug( "Solr line: '$result'\n" ); |
218 | | - |
219 | | - // Defining results |
220 | | - |
221 | | - $this->mDate = null; |
222 | | - $score = $xml->float; |
223 | | - $this->mScore = $score; |
224 | | - |
225 | | - // ------------------------------------- |
226 | | - // Get the shit out of the XML |
227 | | - // ------------------------------------- |
228 | | - foreach ( $xml->arr as $doc ) { |
229 | | - switch ( $doc['name'] ) { |
230 | | - case 'text': |
231 | | - $nsText = $doc->str; |
232 | | - |
233 | | - $this->mSize = ''; |
234 | | - $this->mWordCount = count( $doc->str ); |
235 | | - $snipmax = 10; |
236 | | - $textsnip = ''; |
237 | | - $textsnipvar = 0; |
238 | | - foreach ( $doc->str as $inner ) { |
239 | | - $textsnipvar++; |
240 | | - if ( $textsnipvar >= 4 && $textsnipvar <= $snipmax ) { |
241 | | - $textsnip .= ' ' . $inner; |
242 | | - } |
243 | | - $this->mSize = $this->mSize + strlen( $inner ); |
244 | | - } |
245 | | - $textsnip .= '...'; |
246 | | - $this->mSize = ( $this->mSize / 3 ); |
247 | | - // $this->mSize=$size; |
248 | | - break; |
249 | | - case 'Zuletzt geändert_dt': |
250 | | - $this->mDate = $doc->date; |
251 | | - break; |
252 | | - } |
253 | | - } |
254 | | - |
255 | | - foreach ( $xml->str as $docs ) { |
256 | | - switch ( $docs['name'] ) { |
257 | | - case 'pagetitle': |
258 | | - $this->mTitle = $doc->str; |
259 | | - break; |
260 | | - case 'dbkey': |
261 | | - $title = $doc->str; |
262 | | - break; |
263 | | - case 'interwiki': |
264 | | - $this->mInterwiki = $doc->str; |
265 | | - break; |
266 | | - } |
267 | | - } |
268 | | - |
269 | | - foreach ( $xml->int as $doci ) { |
270 | | - switch ( $doci['name'] ) { |
271 | | - case 'namespace': |
272 | | - $namespace = $doc->str; |
273 | | - break; |
274 | | - } |
275 | | - } |
276 | | - |
277 | | - $title = urldecode( $title ); |
278 | | - if ( !isset( $nsText ) ) { |
279 | | - $nsText = $wgContLang->getNsText( $namespace ); |
280 | | - } else { |
281 | | - $nsText = urldecode( $nsText ); |
282 | | - } |
283 | | - |
284 | | - // make title |
285 | | - $this->mTitle = Title::makeTitle( $namespace, $title ); |
286 | | - |
287 | | - // HIGHLIGHT |
288 | | - // <em> & </em> Fix to <b> // if not, no highlighting! |
289 | | - // TITLE (LINK) |
290 | | - if ( $xml->highlight->title != '' ) { |
291 | | - $this->mHighlightTitle = str_replace( '<em>', '<b>', $xml->highlight->title ); |
292 | | - $this->mHighlightTitle = str_replace( '</em>', '</b>', $this->mHighlightTitle ); |
293 | | - } else { |
294 | | - $this->mHighlightTitle = ''; |
295 | | - } |
296 | | - // TEXT (under link) |
297 | | - // $this->mHighlightText=$xml->highlight->title; |
298 | | - if ( $xml->highlight->Inhalt != '' ) { |
299 | | - $this->mHighlightText = str_replace( '<em>', '<b>', $xml->highlight->Inhalt ); |
300 | | - $this->mHighlightText = str_replace( '</em>', '</b>', $this->mHighlightText ); |
301 | | - $this->mHighlightText .= '...'; |
302 | | - } else {// $this->mHighlightText=textsnip; |
303 | | - if ( isset( $_REQUEST['search'] ) != '' && isset( $textsnip ) != '' ) { |
304 | | - if ( strpos( strtolower( $textsnip ), strtolower( $_REQUEST['search'] ) ) ) { |
305 | | - $tempc = strlen( $_REQUEST['search'] ); |
306 | | - $pos1 = strpos( strtolower( $textsnip ), strtolower( $_REQUEST['search'] ) ); |
307 | | - $tmpa = substr( $textsnip, 0, $pos1 ); |
308 | | - $tmpb = substr( $textsnip, ( $pos1 + $tempc ) ); |
309 | | - $this->mHighlightText = $tmpa . '<b>' . substr( $textsnip, $pos1, $tempc ) . '</b>' . $tmpb; |
310 | | - // str_replace($_REQUEST['search'],"<b>".$_REQUEST['search']."</b>",$textsnip); |
311 | | - } else { |
312 | | - $this->mHighlightText = $textsnip; |
313 | | - } |
314 | | - } else { |
315 | | - $this->mHighlightText = $textsnip; |
316 | | - } |
317 | | - } |
318 | | - $this->mRedirectTitle = null; |
319 | | - $this->mHighlightSection = null; |
320 | | - $this->mSectionTitle = null; |
| 212 | + $newtemplate = $SolrSearchTemplateLoader->applyTemplate( $xml ); // define Template in SolsStore |
| 213 | + $this->mTitle = $newtemplate->mTitle; |
| 214 | + $this->mRedirectTitle = $newtemplate->mRedirectTitle; |
| 215 | + $this->mHighlightSection = $newtemplate->mHighlightSection; |
| 216 | + $this->mSectionTitle = $newtemplate->mSectionTitle; |
| 217 | + $this->mDate = $newtemplate->mDate; |
| 218 | + $this->mScore = $newtemplate->mScore; |
| 219 | + $this->mHighlightTitle = $newtemplate->mHighlightTitle; |
| 220 | + $this->mHighlightText = $newtemplate->mHighlightText; |
| 221 | + $this->mSize = $newtemplate->mSize; |
| 222 | + $this->mWordCount = $newtemplate->mWordCount; |
321 | 223 | } |
322 | 224 | |
323 | | - /** |
324 | | - * Get the pair [highlighted snippet, unmodified text] for highlighted text |
325 | | - * |
326 | | - * @param string $lines |
327 | | - * @param string $nsText textual form of namespace |
328 | | - * @param string $type |
329 | | - * @param boolean $useFinalSeparator |
330 | | - * @return array (highlighted, unmodified text) |
331 | | - */ |
332 | | - function extractSnippet( $lines, $nsText, $type, $useFinalSeparator = false ) { |
333 | | - if ( !array_key_exists( $type, $lines ) ) { |
334 | | - return array( null, null ); |
335 | | - } |
336 | | - $ret = ''; |
337 | | - $original = null; |
338 | | - foreach ( $lines[$type] as $h ) { |
339 | | - list( $s, $o ) = $this->extractSnippetLine( $h, $useFinalSeparator ); |
340 | | - $ret .= $s; |
341 | | - $original = $o; |
342 | | - } |
343 | | - if ( $nsText != '' ) { |
344 | | - $ret = $nsText . ':' . $ret; |
345 | | - } |
346 | | - return array( $ret, $original ); |
347 | | - } |
348 | | - |
349 | | - /** |
350 | | - * Parse one line of a snippet |
351 | | - * |
352 | | - * @param string $line |
353 | | - * @param boolean $useFinalSeparator if "..." is to be appended to the end of snippet |
354 | | - * @access protected |
355 | | - * @return array(snippet,unmodified text) |
356 | | - */ |
357 | | - function extractSnippetLine( $line, $useFinalSeparator ) { |
358 | | - $parts = explode( ' ', $line ); |
359 | | - if ( count( $parts ) != 4 && count( $parts ) != 5 ) { |
360 | | - wfDebug( "Bad result line:" . $line . "\n" ); |
361 | | - return ''; |
362 | | - } |
363 | | - $splits = $this->stripBracketsSplit( $parts[0] ); |
364 | | - $highlight = $this->stripBracketsSplit( $parts[1] ); |
365 | | - $suffix = urldecode( $this->stripBrackets( $parts[2] ) ); |
366 | | - $text = urldecode( $parts[3] ); |
367 | | - $original = null; |
368 | | - if ( count( $parts ) > 4 ) { |
369 | | - $original = urldecode( $parts[4] ); |
370 | | - } |
371 | | - |
372 | | - $splits[] = strlen( $text ); |
373 | | - $start = 0; |
374 | | - $snippet = ''; |
375 | | - $hi = 0; |
376 | | - $ellipsis = wfMsgForContent( 'ellipsis' ); |
377 | | - |
378 | | - foreach ( $splits as $sp ) { |
379 | | - $sp = intval( $sp ); |
380 | | - // highlight words! |
381 | | - while ( $hi < count( $highlight ) && intval( $highlight[$hi] ) < $sp ) { |
382 | | - $s = intval( $highlight[$hi] ); |
383 | | - $e = intval( $highlight[$hi + 1] ); |
384 | | - $snippet .= substr( $text, $start, $s - $start ) . |
385 | | - '<span class="searchmatch">' . substr( $text, $s, $e - $s ) . '</span>'; |
386 | | - $start = $e; |
387 | | - $hi += 2; |
388 | | - } |
389 | | - // copy till split point |
390 | | - $snippet .= substr( $text, $start, $sp - $start ); |
391 | | - if ( $sp == strlen( $text ) && $suffix != '' ) { |
392 | | - $snippet .= $suffix; |
393 | | - } elseif ( $useFinalSeparator ) { |
394 | | - $snippet .= ' <b>' . $ellipsis . '</b> '; |
395 | | - } |
396 | | - |
397 | | - $start = $sp; |
398 | | - } |
399 | | - return array( $snippet, $original ); |
400 | | - } |
401 | | - |
402 | | - /** |
403 | | - * @access private |
404 | | - */ |
405 | | - function stripBrackets( $str ) { |
406 | | - if ( $str == '[]' ) { |
407 | | - return ''; |
408 | | - } |
409 | | - return substr( $str, 1, strlen( $str ) - 2 ); |
410 | | - } |
411 | | - |
412 | | - /** |
413 | | - * @access private |
414 | | - * @return array |
415 | | - */ |
416 | | - function stripBracketsSplit( $str ) { |
417 | | - $strip = $this->stripBrackets( $str ); |
418 | | - if ( $strip == '' ) { |
419 | | - return array(); |
420 | | - } else { |
421 | | - return explode( ',', $strip ); |
422 | | - } |
423 | | - } |
424 | | - |
425 | 225 | function getTitle() { |
426 | 226 | return $this->mTitle; |
427 | 227 | } |
— | — | @@ -523,38 +323,38 @@ |
524 | 324 | * @param $searchAll Boolean |
525 | 325 | * @return array |
526 | 326 | */ |
527 | | - public static function newFromQuery( $method, $query, $namespaces = array(), $limit = 20, $offset = 0, $searchAll = false ) { |
| 327 | + public static function newFromQuery( $method, $query, $namespaces = array( ), $limit = 20, $offset = 0, $searchAll = false ) { |
528 | 328 | wfProfileIn( __METHOD__ ); |
529 | 329 | |
530 | 330 | $wgSolrTalker = new SolrTalker(); |
531 | 331 | |
532 | 332 | $query = $wgSolrTalker->queryChecker( $query ); |
533 | 333 | $xml = $wgSolrTalker->solrQuery( $query, $offset, $limit, true, true ); // Abfrage ok, ergebniss in XML |
534 | | - $totalHits = $xml->result['numFound']; |
| 334 | + $totalHits = $xml->result[ 'numFound' ]; |
535 | 335 | |
536 | | - $resultLines = array(); ; |
| 336 | + $resultLines = array( ); |
537 | 337 | |
538 | 338 | $highl = $xml->xpath( '//lst[@name="highlighting"]/lst' ); |
539 | 339 | |
540 | 340 | $hli = 0; |
541 | 341 | |
542 | 342 | foreach ( $xml->result->doc as $doc ) { |
543 | | - if ( isset( $highl[$hli]->arr ) ) { |
544 | | - foreach ( $highl[$hli]->arr as $feld ) { |
545 | | - if ( isset( $feld['name'] ) ) { |
546 | | - switch ( $feld['name'] ) { |
| 343 | + if ( isset( $highl[ $hli ]->arr ) ) { |
| 344 | + foreach ( $highl[ $hli ]->arr as $feld ) { |
| 345 | + if ( isset( $feld[ 'name' ] ) ) { |
| 346 | + switch ( $feld[ 'name' ] ) { |
547 | 347 | case 'title': |
548 | | - $doc[]->highlight->title = $feld->str; |
| 348 | + $doc[ ]->highlight->title = $feld->str; |
549 | 349 | break; |
550 | | - case 'Inhalt de_t': |
551 | | - $doc[]->highlight->Inhalt = $feld->str; |
| 350 | + case 'Inhalt de_t': // TODO: is style ? |
| 351 | + $doc[ ]->highlight->Inhalt = $feld->str; |
552 | 352 | break; |
553 | 353 | } |
554 | 354 | } |
555 | 355 | } |
556 | 356 | } |
557 | 357 | $hli++; |
558 | | - $resultLines[] = $doc; |
| 358 | + $resultLines[ ] = $doc; |
559 | 359 | } |
560 | 360 | |
561 | 361 | $suggestion = null; |
— | — | @@ -562,8 +362,8 @@ |
563 | 363 | $interwiki = null; |
564 | 364 | |
565 | 365 | $resultSet = new SolrSearchSet( |
566 | | - $method, $query, $resultLines, count( $resultLines ), $totalHits, |
567 | | - $suggestion, $info, $interwiki |
| 366 | + $method, $query, $resultLines, count( $resultLines ), $totalHits, |
| 367 | + $suggestion, $info, $interwiki |
568 | 368 | ); |
569 | 369 | |
570 | 370 | wfProfileOut( __METHOD__ ); |
— | — | @@ -606,15 +406,15 @@ |
607 | 407 | return; |
608 | 408 | } |
609 | 409 | |
610 | | - // parse split points and highlight changes |
| 410 | +// parse split points and highlight changes |
611 | 411 | list( $dummy, $points, $sug ) = explode( ' ', $suggestion ); |
612 | 412 | $sug = urldecode( $sug ); |
613 | 413 | $points = explode( ',', substr( $points, 1, -1 ) ); |
614 | 414 | array_unshift( $points, 0 ); |
615 | 415 | $suggestText = ''; |
616 | 416 | for ( $i = 1; $i < count( $points ); $i += 2 ) { |
617 | | - $suggestText .= htmlspecialchars( substr( $sug, $points[$i - 1], $points[$i] - $points[$i - 1] ) ); |
618 | | - $suggestText .= '<em>' . htmlspecialchars( substr( $sug, $points[$i], $points[$i + 1] - $points[$i] ) ) . '</em>'; |
| 417 | + $suggestText .= htmlspecialchars( substr( $sug, $points[ $i - 1 ], $points[ $i ] - $points[ $i - 1 ] ) ); |
| 418 | + $suggestText .= '<em>' . htmlspecialchars( substr( $sug, $points[ $i ], $points[ $i + 1 ] - $points[ $i ] ) ) . '</em>'; |
619 | 419 | } |
620 | 420 | $suggestText .= htmlspecialchars( substr( $sug, end( $points ) ) ); |
621 | 421 | |
— | — | @@ -633,7 +433,7 @@ |
634 | 434 | $phrases[$i] |
635 | 435 | ); |
636 | 436 | if ( $i + 1 < count( $phrases ) ) { |
637 | | - $out .= '"' . $phrases[$i + 1] . '"'; // phrase text |
| 437 | + $out .= '"' . $phrases[ $i + 1 ] . '"'; // phrase text |
638 | 438 | } |
639 | 439 | } |
640 | 440 | return $out; |
— | — | @@ -641,7 +441,7 @@ |
642 | 442 | |
643 | 443 | function genericPrefixCallback( $matches ) { |
644 | 444 | global $wgContLang; |
645 | | - return $wgContLang->getFormattedNsText( $matches[1] ) . ':'; |
| 445 | + return $wgContLang->getFormattedNsText( $matches[ 1 ] ) . ':'; |
646 | 446 | } |
647 | 447 | |
648 | 448 | function numRows() { |
— | — | @@ -652,26 +452,26 @@ |
653 | 453 | $resq = preg_replace( "/\\[.*?\\]:/", ' ', $this->mQuery ); # generic prefixes |
654 | 454 | $resq = preg_replace( '/all:/', ' ', $resq ); |
655 | 455 | |
656 | | - // @todo FIXME: this is ripped from SearchMySQL and probably kind of sucks, |
657 | | - // but it handles quoted phrase searches more or less correctly. |
658 | | - // Should encapsulate this stuff better. |
659 | | - // @todo FIXME: This doesn't handle parenthetical expressions. |
660 | | - $regexes = array(); |
661 | | - $m = array(); |
| 456 | +// @todo FIXME: this is ripped from SearchMySQL and probably kind of sucks, |
| 457 | +// but it handles quoted phrase searches more or less correctly. |
| 458 | +// Should encapsulate this stuff better. |
| 459 | +// @todo FIXME: This doesn't handle parenthetical expressions. |
| 460 | + $regexes = array( ); |
| 461 | + $m = array( ); |
662 | 462 | $lc = SearchEngine::legalSearchChars(); |
663 | 463 | if ( preg_match_all( '/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/', $resq, $m, PREG_SET_ORDER ) ) { |
664 | 464 | foreach ( $m as $terms ) { |
665 | | - if ( !empty( $terms[3] ) ) { |
666 | | - // Match individual terms in result highlighting... |
667 | | - $regexp = preg_quote( $terms[3], '/' ); |
668 | | - if ( $terms[4] ) { |
| 465 | + if ( !empty( $terms[ 3 ] ) ) { |
| 466 | +// Match individual terms in result highlighting... |
| 467 | + $regexp = preg_quote( $terms[ 3 ], '/' ); |
| 468 | + if ( $terms[ 4 ] ) { |
669 | 469 | $regexp .= '[0-9A-Za-z_]+'; |
670 | 470 | } |
671 | 471 | } else { |
672 | | - // Match the quoted term in result highlighting... |
673 | | - $regexp = preg_quote( str_replace( '"', '', $terms[2] ), '/' ); |
| 472 | +// Match the quoted term in result highlighting... |
| 473 | + $regexp = preg_quote( str_replace( '"', '', $terms[ 2 ] ), '/' ); |
674 | 474 | } |
675 | | - $regexes[] = $regexp; |
| 475 | + $regexes[ ] = $regexp; |
676 | 476 | } |
677 | 477 | wfDebug( __METHOD__ . ': Match with /' . implode( '|', $regexes ) . "/\n" ); |
678 | 478 | } else { |
— | — | @@ -752,7 +552,7 @@ |
753 | 553 | public function next() { |
754 | 554 | if ( $this->mPos < $this->mResultCount ) { |
755 | 555 | $this->mPos++; |
756 | | - return new SolrResult( $this->mResults[$this->mPos - 1], $this->mMethod ); |
| 556 | + return new SolrResult( $this->mResults[ $this->mPos - 1 ] ); |
757 | 557 | } else { |
758 | 558 | return null; |
759 | 559 | } |
Index: trunk/extensions/SolrStore/SolrSearchTemplateLoader.php |
— | — | @@ -0,0 +1,35 @@ |
| 2 | +<?php
|
| 3 | +/**
|
| 4 | + * Dynamic TemplateLoader
|
| 5 | + *
|
| 6 | + * @ingroup SolrStore
|
| 7 | + * @file
|
| 8 | + * @author Sascha Schueller
|
| 9 | + */
|
| 10 | +
|
| 11 | +/**
|
| 12 | + * TODO: Insert class description
|
| 13 | + *
|
| 14 | + * @ingroup SolrStore
|
| 15 | + */
|
| 16 | +class SolrSearchTemplateLoader {
|
| 17 | +
|
| 18 | + public function applyTemplate( $xml ) {
|
| 19 | + global $wgSolrTemplate;
|
| 20 | +
|
| 21 | + $dir = dirname( __FILE__ );
|
| 22 | + $file = $dir . '/templates/SolrSearchTemplate' . $wgSolrTemplate . '.php';
|
| 23 | + $classname = 'SolrSearchTemplate' . $wgSolrTemplate;
|
| 24 | +
|
| 25 | + if ( file_exists( $file ) ) {
|
| 26 | + if ( !class_exists( $classname ) ) {
|
| 27 | + include($dir . '/templates/SolrSearchTemplate' . $wgSolrTemplate . '.php');
|
| 28 | + }
|
| 29 | + $classname = new $classname();
|
| 30 | + return $classname->applyTemplate( $xml );
|
| 31 | + }
|
| 32 | + die( "SolrSearch Template Problem: File not exists !! " . $file );
|
| 33 | + }
|
| 34 | +
|
| 35 | +}
|
| 36 | +?>
|
Index: trunk/extensions/SolrStore/templates/SolrSearchTemplate_Standart.php |
— | — | @@ -0,0 +1,116 @@ |
| 2 | +<?php
|
| 3 | +/**
|
| 4 | + * Dynamic Template 'Standart' -> Example
|
| 5 | + *
|
| 6 | + * Conditions to use:
|
| 7 | + * Please name the class: SolrSearchTemplate_NAME
|
| 8 | + * Filename: SolrSearchTemplate_NAME.php
|
| 9 | + * dont touch the function name: applyTemplate( $xml )
|
| 10 | + *
|
| 11 | + * @ingroup SolrStore
|
| 12 | + * @path templates
|
| 13 | + * @author Sascha Schueller
|
| 14 | + */
|
| 15 | +class SolrSearchTemplate_Standart {
|
| 16 | +
|
| 17 | + var $mTitle = null;
|
| 18 | + var $mRedirectTitle = null;
|
| 19 | + var $mHighlightSection = null;
|
| 20 | + var $mSectionTitle = null;
|
| 21 | + var $mDate = null;
|
| 22 | + var $mScore = null;
|
| 23 | + var $mSize = null;
|
| 24 | + var $mHighlightText = null;
|
| 25 | + var $mHighlightTitle = null;
|
| 26 | + var $mWordCount = null;
|
| 27 | +
|
| 28 | + public function applyTemplate( $xml ) { // DONT TOUCH
|
| 29 | + $snipmax = 50;
|
| 30 | + $textlenght = 250;
|
| 31 | +
|
| 32 | + // get Size, Namespace, Wordcound, Date from XML:
|
| 33 | + foreach ( $xml->arr as $doc ) {
|
| 34 | + switch ( $doc[ 'name' ] ) {
|
| 35 | + case 'text':
|
| 36 | + $nsText = $doc->str;
|
| 37 | + $this->mSize = '';
|
| 38 | + $this->mWordCount = count( $doc->str );
|
| 39 | + $textsnip = '';
|
| 40 | + $textsnipvar = 0;
|
| 41 | + foreach ( $doc->str as $inner ) {
|
| 42 | + $textsnipvar++;
|
| 43 | + if ( $textsnipvar >= 4 && $textsnipvar <= $snipmax ) {
|
| 44 | + $textsnip .= ' ' . $inner;
|
| 45 | + }
|
| 46 | + $textsnip = substr( $textsnip, 0, $textlenght );
|
| 47 | + $this->mSize = $this->mSize + strlen( $inner );
|
| 48 | + }
|
| 49 | + $this->mSize = ( $this->mSize / 3 );
|
| 50 | + $this->mDate = $doc->date;
|
| 51 | + break;
|
| 52 | + }
|
| 53 | + }
|
| 54 | +
|
| 55 | + // get Title, Interwiki from XML:
|
| 56 | + foreach ( $xml->str as $docs ) {
|
| 57 | + switch ( $docs[ 'name' ] ) {
|
| 58 | + case 'pagetitle':
|
| 59 | + $this->mTitle = $doc->str;
|
| 60 | + break;
|
| 61 | + case 'dbkey':
|
| 62 | + $title = $doc->str;
|
| 63 | + break;
|
| 64 | + case 'interwiki':
|
| 65 | + $this->mInterwiki = $doc->str;
|
| 66 | + break;
|
| 67 | + }
|
| 68 | + }
|
| 69 | +
|
| 70 | + //get namespace from XML:
|
| 71 | + foreach ( $xml->int as $doci ) {
|
| 72 | + switch ( $doci[ 'name' ] ) {
|
| 73 | + case 'namespace':
|
| 74 | + $namespace = $doc->str;
|
| 75 | + break;
|
| 76 | + }
|
| 77 | + }
|
| 78 | +
|
| 79 | + if ( !isset( $nsText ) ) {
|
| 80 | + $nsText = $wgContLang->getNsText( $namespace );
|
| 81 | + } else {
|
| 82 | + $nsText = urldecode( $nsText );
|
| 83 | + }
|
| 84 | +
|
| 85 | + // make score / relevance
|
| 86 | + $this->mScore = $xml->float;
|
| 87 | +
|
| 88 | + // make Title
|
| 89 | + $title = urldecode( $title );
|
| 90 | + $this->mTitle = Title::makeTitle( $namespace, $title );
|
| 91 | +
|
| 92 | + // make Highlight - Title
|
| 93 | + if ( $xml->highlight->title != '' ) {
|
| 94 | + $this->mHighlightTitle = $xml->highlight->title;
|
| 95 | + } else {
|
| 96 | + $this->mHighlightTitle = '';
|
| 97 | + }
|
| 98 | +
|
| 99 | + // make Highlight - Text
|
| 100 | + if ( $xml->highlight->Inhalt != '' ) {
|
| 101 | + $this->mHighlightText = str_replace( '<em>', '<b>', $xml->highlight->Inhalt );
|
| 102 | + $this->mHighlightText = str_replace( '</em>', '</b>', $this->mHighlightText );
|
| 103 | + $this->mHighlightText .= '...';
|
| 104 | + } else {
|
| 105 | + $this->mHighlightText = "NO HIGHLIGHTING TEXT FROM SOLR !";
|
| 106 | +
|
| 107 | + // if nothing define itself !
|
| 108 | + // 4 example with
|
| 109 | + // $this->mHighlightText = $textsnip;
|
| 110 | + }
|
| 111 | +
|
| 112 | + return $this;
|
| 113 | + }
|
| 114 | +
|
| 115 | +}
|
| 116 | +
|
| 117 | +?>
|
Index: trunk/extensions/SolrStore/templates/SolrSearchTemplate_FIS.php |
— | — | @@ -0,0 +1,336 @@ |
| 2 | +<?php
|
| 3 | +/**
|
| 4 | + * Dynamic Template 'FIS' -> Example
|
| 5 | + *
|
| 6 | + * Example Template
|
| 7 | + * with : makeHighlightText and makeHighlightTitle functions
|
| 8 | + *
|
| 9 | + * to use this template add this peace of code to LocalSettings.php
|
| 10 | + *
|
| 11 | + * # define Template
|
| 12 | + * $wgSolrTemplate = "_FIS";
|
| 13 | + *
|
| 14 | + *
|
| 15 | + * @ingroup SolrStore
|
| 16 | + * @path templates
|
| 17 | + * @author Sascha Schueller
|
| 18 | + */
|
| 19 | +class SolrSearchTemplate_FIS {
|
| 20 | +
|
| 21 | + var $mTitle = null;
|
| 22 | + var $mRedirectTitle = null;
|
| 23 | + var $mHighlightSection = null;
|
| 24 | + var $mSectionTitle = null;
|
| 25 | + var $mDate = null;
|
| 26 | + var $mScore = null;
|
| 27 | + var $mSize = null;
|
| 28 | + var $Inhalt_de_t = null;
|
| 29 | + var $mHighlightText = null;
|
| 30 | + var $mHighlightTitle = null;
|
| 31 | + var $mWordCount = null;
|
| 32 | +
|
| 33 | + public function applyTemplate( $xml ) {
|
| 34 | + global $wgSolrFields;
|
| 35 | +
|
| 36 | + $snipmax = 50;
|
| 37 | + $textlenght = 1000;
|
| 38 | + $textlenghteffective = 315;
|
| 39 | +
|
| 40 | + // Bugfix: clear the var!
|
| 41 | + unset( $this->Inhalt_de_t );
|
| 42 | +
|
| 43 | + // get Size, Wordcound, Date, Inhalt_de_t from XML:
|
| 44 | + foreach ( $xml->arr as $doc ) {
|
| 45 | + switch ( $doc[ 'name' ] ) {
|
| 46 | + case 'text':
|
| 47 | + $nsText = $doc->str;
|
| 48 | + $this->mSize = '';
|
| 49 | + $this->mWordCount = count( $doc->str );
|
| 50 | + $snipmax = 50;
|
| 51 | + $textsnip = '';
|
| 52 | + $textsnipvar = 0;
|
| 53 | + foreach ( $doc->str as $inner ) {
|
| 54 | + $textsnipvar++;
|
| 55 | + if ( $textsnipvar >= 4 && $textsnipvar <= $snipmax ) {
|
| 56 | + $textsnip .= ' ' . $inner;
|
| 57 | + }
|
| 58 | + $textsnip = substr( $textsnip, 0, $textlenght );
|
| 59 | + $this->mSize = $this->mSize + strlen( $inner );
|
| 60 | + }
|
| 61 | + $this->mSize = ( $this->mSize / 3 );
|
| 62 | + break;
|
| 63 | +
|
| 64 | + case 'Zuletzt geändert_dt':
|
| 65 | + $this->mDate = $doc->date;
|
| 66 | + break;
|
| 67 | +
|
| 68 | + case 'Inhalt de_t':
|
| 69 | + $this->Inhalt_de_t[ ] = $doc->str;
|
| 70 | + break;
|
| 71 | + }
|
| 72 | + }
|
| 73 | +
|
| 74 | + // get Title, Interwiki from XML:
|
| 75 | + foreach ( $xml->str as $docs ) {
|
| 76 | + switch ( $docs[ 'name' ] ) {
|
| 77 | + case 'pagetitle':
|
| 78 | + $this->mTitle = $doc->str;
|
| 79 | + break;
|
| 80 | + case 'dbkey':
|
| 81 | + $title = $doc->str;
|
| 82 | + break;
|
| 83 | + case 'interwiki':
|
| 84 | + $this->mInterwiki = $doc->str;
|
| 85 | + break;
|
| 86 | + }
|
| 87 | + }
|
| 88 | +
|
| 89 | + //get namespace from XML:
|
| 90 | + foreach ( $xml->int as $doci ) {
|
| 91 | + switch ( $doci[ 'name' ] ) {
|
| 92 | + case 'namespace':
|
| 93 | + $namespace = $doc->str;
|
| 94 | + break;
|
| 95 | + }
|
| 96 | + }
|
| 97 | +
|
| 98 | + if ( !isset( $nsText ) ) {
|
| 99 | + $nsText = $wgContLang->getNsText( $namespace );
|
| 100 | + } else {
|
| 101 | + $nsText = urldecode( $nsText );
|
| 102 | + }
|
| 103 | +
|
| 104 | + // make score / relevance
|
| 105 | + $this->mScore = $xml->float;
|
| 106 | +
|
| 107 | + // make Title
|
| 108 | + $title = urldecode( $title );
|
| 109 | + $this->mTitle = Title::makeTitle( $namespace, $title );
|
| 110 | +
|
| 111 | + // make Highlight - Title
|
| 112 | + $this->mHighlightTitle = $title;
|
| 113 | + $this->makeHighlightTitle( $wgSolrFields, $title );
|
| 114 | +
|
| 115 | + $firstw = false;
|
| 116 | +
|
| 117 | + if ( isset( $this->Inhalt_de_t[ 0 ] ) != '' ) {
|
| 118 | + $firstw = substr( $this->Inhalt_de_t[ 0 ], 0, strpos( $this->Inhalt_de_t[ 0 ], " " ) ); // test CUT textsnip:
|
| 119 | + if ( $firstw != false ) {
|
| 120 | + $textsnip = substr( $textsnip, strpos( $textsnip, $firstw ) );
|
| 121 | + } else {
|
| 122 | + if ( isset( $xml->highlight->Inhalt ) != '' ) {
|
| 123 | + $firstw = substr( $xml->highlight->Inhalt, 0, strpos( $xml->highlight->Inhalt, " " ) ); // test CUT textsnip:
|
| 124 | + if ( $firstw != false ) {
|
| 125 | + $textsnip = substr( $textsnip, strpos( $textsnip, $firstw ) );
|
| 126 | + }
|
| 127 | + } else {
|
| 128 | +
|
| 129 | + }
|
| 130 | + }
|
| 131 | +
|
| 132 | + // make Highlight - Text
|
| 133 | + $this->mHighlightText = substr( $textsnip, 0, $textlenghteffective ) . "..."; // MAX LENG [INHALT]
|
| 134 | + $this->makeHighlightText( $wgSolrFields, $textsnip ); // TEXTSNIP: Highlight the searching stuff:
|
| 135 | + } else {
|
| 136 | + $this->mHighlightText = "";
|
| 137 | + }
|
| 138 | +
|
| 139 | + return $this;
|
| 140 | + }
|
| 141 | +
|
| 142 | + private function cleanword( $w ) { // Bugfix 4 the highlighting system
|
| 143 | + $str = array( "*", ">", "<", "/", '"' );
|
| 144 | + $w = str_replace( $str, "", $w );
|
| 145 | + return $w;
|
| 146 | + }
|
| 147 | +
|
| 148 | + private function makeHighlightTitle( $wgSolrFields, $textsnipcut ) {
|
| 149 | + for ( $tfields = 0; $tfields <= count( $wgSolrFields ) - 1; $tfields++ ) {
|
| 150 | + foreach ( $wgSolrFields[ $tfields ] as $fieldcollection=>$inhalt ) {
|
| 151 | + if ( $fieldcollection == 'mLable' ) { // get Solrfields
|
| 152 | + foreach ( $inhalt as $feldname=>$lablename ) {
|
| 153 | + $pos = false;
|
| 154 | + $pos = strpos( $feldname, "solr" );
|
| 155 | + if ( $pos !== false ) {
|
| 156 | +
|
| 157 | + if ( isset( $_REQUEST[ $feldname ] ) != '' && isset( $textsnipcut ) != '' ) {
|
| 158 | + $wcount = substr_count( $_REQUEST[ $feldname ], " " ) + 1;
|
| 159 | + unset( $leerat );
|
| 160 | + for ( $wlpos = 0; $wlpos <= strlen( $_REQUEST[ $feldname ] ); $wlpos++ ) { // wo sind die leerzeichen ?
|
| 161 | + if ( substr( $_REQUEST[ $feldname ], $wlpos, 1 ) == " " ) {
|
| 162 | + $leerat[ ].=$wlpos;
|
| 163 | + }
|
| 164 | + }
|
| 165 | + for ( $wpos = 1; $wpos <= $wcount; $wpos++ ) {
|
| 166 | + $isschon = false;
|
| 167 | + $pos1 = false;
|
| 168 | + $tempc = false;
|
| 169 | +
|
| 170 | + if ( isset( $_REQUEST[ $feldname ] ) && $_REQUEST[ $feldname ] != '' ) {
|
| 171 | + if ( $wpos == 1 ) { // First word: [OK]
|
| 172 | + if ( $wcount > 1 ) { // more than 1 highlighting word:
|
| 173 | + $highlighword = substr( $_REQUEST[ $feldname ], 0, $leerat[ $wpos - 1 ] );
|
| 174 | + } else { // Only 1 word: [OK]
|
| 175 | + $highlighword = substr( $_REQUEST[ $feldname ], 0 );
|
| 176 | + }
|
| 177 | + } elseif ( $wpos == $wcount ) { // Last word: [OK]
|
| 178 | + $highlighword = substr( $_REQUEST[ $feldname ], $leerat[ $wpos - 2 ] + 1 );
|
| 179 | + } elseif ( $wpos != $wcount && $wpos != 1 ) { // all words betwen first and last [OK]
|
| 180 | + $highlighword = substr( $_REQUEST[ $feldname ], $leerat[ $wpos - 2 ] + 1, (($leerat[ $wpos - 1 ] - $leerat[ $wpos - 2 ]) - 1 ) );
|
| 181 | + }
|
| 182 | + $highlighword = $this->cleanword( $highlighword );
|
| 183 | +
|
| 184 | + if ( $highlighword != "" ) {
|
| 185 | + if ( $highlighword == "b" || $highlighword == "B" ) {
|
| 186 | + $this->mHighlightTitle = preg_replace( "#" . strtolower( $highlighword ) . "#", "<em><b>" . $highlighword . "</b></em>", $this->mHighlightTitle );
|
| 187 | + } else {
|
| 188 | +
|
| 189 | + if ( strpos( strtolower( $this->mHighlightTitle ), strtolower( $highlighword ) ) > 0 ) { // Highlightwort nicht am anfang:
|
| 190 | + $tempc = strlen( $highlighword );
|
| 191 | + $pos1 = strpos( strtolower( $this->mHighlightTitle ), strtolower( $highlighword ) );
|
| 192 | +
|
| 193 | + if ( $pos1 != false && (substr_count( strtolower( $this->mHighlightTitle ), strtolower( $highlighword ) ) == 1) ) { // wenn Wort nur 1x vorhanden ist normal Highlighten:
|
| 194 | + $tmpa = substr( $this->mHighlightTitle, 0, $pos1 );
|
| 195 | + $tmpb = substr( $this->mHighlightTitle, ( $pos1 + $tempc ) );
|
| 196 | +
|
| 197 | + $this->mHighlightTitle = $tmpa . '<em><b>' . substr( $this->mHighlightTitle, $pos1, $tempc ) . '</b></em>' . $tmpb;
|
| 198 | + }
|
| 199 | + if ( $pos1 != false && (substr_count( strtolower( $this->mHighlightTitle ), strtolower( $highlighword ) ) >= 2) ) { // Wenn Wort mehrmals vorkommt, dann mehrmals highlighten:
|
| 200 | + $highcount = substr_count( strtolower( $this->mHighlightTitle ), strtolower( $highlighword ) );
|
| 201 | + unset( $offset );
|
| 202 | + $offset[ 0 ] = 0;
|
| 203 | + for ( $hc = 1; $hc <= $highcount; $hc++ ) {
|
| 204 | + $tempc = strlen( $highlighword );
|
| 205 | +
|
| 206 | + if ( $hc == 1 ) {
|
| 207 | + $pos1 = strpos( strtolower( $this->mHighlightTitle ), strtolower( $highlighword ) );
|
| 208 | + } else {
|
| 209 | + $pos1 = strpos( strtolower( $this->mHighlightTitle ), strtolower( $highlighword ), $offset[ $hc - 1 ] + 7 + $tempc );
|
| 210 | + }
|
| 211 | +
|
| 212 | + $offset[ $hc ] = $pos1;
|
| 213 | + $tmpa = substr( $this->mHighlightTitle, 0, $pos1 );
|
| 214 | + $tmpb = substr( $this->mHighlightTitle, ( $pos1 + $tempc ) );
|
| 215 | + $this->mHighlightTitle = $tmpa . '<em><b>' . substr( $this->mHighlightTitle, $pos1, $tempc ) . '</b></em>' . $tmpb;
|
| 216 | + }
|
| 217 | + }
|
| 218 | + } else { // Erstes Wort im Satz:
|
| 219 | + $tempc = strlen( $highlighword );
|
| 220 | + $pos1 = strpos( strtolower( $this->mHighlightTitle ), strtolower( $highlighword ) );
|
| 221 | +
|
| 222 | + if ( $isschon == false && $pos1 == 0 && (strtolower( $highlighword ) == substr( strtolower( $this->mHighlightTitle ), 0, $tempc ) ) ) {
|
| 223 | +//
|
| 224 | + $tmpb = substr( $this->mHighlightTitle, $tempc );
|
| 225 | +
|
| 226 | + if ( strtolower( $highlighword ) == substr( strtolower( $this->mHighlightTitle ), 0, $tempc ) ) {
|
| 227 | + $this->mHighlightTitle = '<em><b> ' . substr( $this->mHighlightTitle, 0, $tempc ) . '</b></em>' . $tmpb;
|
| 228 | + $isschon = true;
|
| 229 | + }
|
| 230 | + }
|
| 231 | + }
|
| 232 | + }
|
| 233 | + }
|
| 234 | + }
|
| 235 | + }
|
| 236 | + }
|
| 237 | + }
|
| 238 | + }
|
| 239 | + }
|
| 240 | + }
|
| 241 | + }
|
| 242 | + }
|
| 243 | +
|
| 244 | + private function makeHighlightText( $wgSolrFields, $textsnipcut ) {
|
| 245 | + for ( $tfields = 0; $tfields <= count( $wgSolrFields ) - 1; $tfields++ ) {
|
| 246 | + foreach ( $wgSolrFields[ $tfields ] as $fieldcollection=>$inhalt ) {
|
| 247 | + if ( $fieldcollection == 'mLable' ) { // get Solrfields
|
| 248 | + foreach ( $inhalt as $feldname=>$lablename ) {
|
| 249 | + $pos = false;
|
| 250 | +
|
| 251 | + $pos = strpos( $feldname, "solr" );
|
| 252 | + if ( $pos !== false ) {
|
| 253 | +
|
| 254 | + if ( isset( $_REQUEST[ $feldname ] ) != '' && isset( $textsnipcut ) != '' ) {
|
| 255 | + $wcount = substr_count( $_REQUEST[ $feldname ], " " ) + 1;
|
| 256 | + unset( $leerat );
|
| 257 | + for ( $wlpos = 0; $wlpos <= strlen( $_REQUEST[ $feldname ] ); $wlpos++ ) { // wo sind die leerzeichen ?
|
| 258 | + if ( substr( $_REQUEST[ $feldname ], $wlpos, 1 ) == " " ) {
|
| 259 | + $leerat[ ].=$wlpos;
|
| 260 | + }
|
| 261 | + }
|
| 262 | + for ( $wpos = 1; $wpos <= $wcount; $wpos++ ) {
|
| 263 | + $isschon = false;
|
| 264 | + $pos1 = false;
|
| 265 | + if ( isset( $_REQUEST[ $feldname ] ) && $_REQUEST[ $feldname ] != '' ) {
|
| 266 | + if ( $wpos == 1 ) { // First word: [OK]
|
| 267 | + if ( $wcount > 1 ) { // more than 1 highlighting word:
|
| 268 | + $highlighword = substr( $_REQUEST[ $feldname ], 0, $leerat[ $wpos - 1 ] );
|
| 269 | + } else { // Only 1 word: [OK]
|
| 270 | + $highlighword = substr( $_REQUEST[ $feldname ], 0 );
|
| 271 | + }
|
| 272 | + } elseif ( $wpos == $wcount ) { // Last word: [OK]
|
| 273 | + $highlighword = substr( $_REQUEST[ $feldname ], $leerat[ $wpos - 2 ] + 1 );
|
| 274 | + } elseif ( $wpos != $wcount && $wpos != 1 ) { // all words betwen first and last [OK]
|
| 275 | + $highlighword = substr( $_REQUEST[ $feldname ], $leerat[ $wpos - 2 ] + 1, (($leerat[ $wpos - 1 ] - $leerat[ $wpos - 2 ]) - 1 ) );
|
| 276 | + }
|
| 277 | +
|
| 278 | + $highlighword = $this->cleanword( $highlighword );
|
| 279 | +
|
| 280 | + if ( $highlighword != "" ) {
|
| 281 | + if ( $highlighword == "b" || $highlighword == "B" ) {
|
| 282 | + $this->mHighlightText = preg_replace( "#" . strtolower( $highlighword ) . "#", "<em><b>" . $highlighword . "</b></em>", $this->mHighlightText );
|
| 283 | + } else {
|
| 284 | +
|
| 285 | + if ( strpos( strtolower( $this->mHighlightText ), strtolower( $highlighword ) ) > 0 ) {
|
| 286 | +
|
| 287 | + $tempc = strlen( $highlighword );
|
| 288 | + $pos1 = strpos( strtolower( $this->mHighlightText ), strtolower( $highlighword ) );
|
| 289 | +
|
| 290 | + if ( $pos1 != false && (substr_count( strtolower( $this->mHighlightText ), strtolower( $highlighword ) ) == 1) ) { // wenn Wort nur 1x vorhanden ist normal Highlighten:
|
| 291 | + $tmpa = substr( $this->mHighlightText, 0, $pos1 );
|
| 292 | + $tmpb = substr( $this->mHighlightText, ( $pos1 + $tempc ) );
|
| 293 | +
|
| 294 | + $this->mHighlightText = $tmpa . '<em><b>' . substr( $this->mHighlightText, $pos1, $tempc ) . '</b></em>' . $tmpb;
|
| 295 | + }
|
| 296 | + if ( $pos1 != false && (substr_count( strtolower( $this->mHighlightText ), strtolower( $highlighword ) ) >= 2) ) { // Wenn Wort mehrmals vorkommt, dann mehrmals highlighten:
|
| 297 | + $highcount = substr_count( strtolower( $this->mHighlightText ), strtolower( $highlighword ) );
|
| 298 | + unset( $offset );
|
| 299 | + $offset[ 0 ] = 0;
|
| 300 | + for ( $hc = 1; $hc <= $highcount; $hc++ ) {
|
| 301 | + $tempc = strlen( $highlighword );
|
| 302 | + if ( $hc == 1 ) {
|
| 303 | + $pos1 = strpos( strtolower( $this->mHighlightText ), strtolower( $highlighword ) );
|
| 304 | + } else {
|
| 305 | + $pos1 = strpos( strtolower( $this->mHighlightText ), strtolower( $highlighword ), $offset[ $hc - 1 ] + 7 + $tempc );
|
| 306 | + }
|
| 307 | + $offset[ $hc ] = $pos1;
|
| 308 | + $tmpa = substr( $this->mHighlightText, 0, $pos1 );
|
| 309 | + $tmpb = substr( $this->mHighlightText, ( $pos1 + $tempc ) );
|
| 310 | + $this->mHighlightText = $tmpa . '<em><b>' . substr( $this->mHighlightText, $pos1, $tempc ) . '</b></em>' . $tmpb;
|
| 311 | + }
|
| 312 | + }
|
| 313 | + } else {
|
| 314 | + $tempc = strlen( $highlighword );
|
| 315 | + $pos1 = strpos( strtolower( $this->mHighlightText ), strtolower( $highlighword ) );
|
| 316 | +
|
| 317 | + if ( $isschon == false && $pos1 == 0 && (strtolower( $highlighword ) == substr( strtolower( $this->mHighlightText ), 0, $tempc ) ) ) {
|
| 318 | + $tmpb = substr( $this->mHighlightText, $tempc );
|
| 319 | + $this->mHighlightText = '<em><b> ' . substr( $this->mHighlightText, 0, $tempc ) . '</b></em>' . $tmpb;
|
| 320 | + $isschon = true;
|
| 321 | + }
|
| 322 | + }
|
| 323 | + }
|
| 324 | + }
|
| 325 | + }
|
| 326 | + }
|
| 327 | + }
|
| 328 | + }
|
| 329 | + }
|
| 330 | + }
|
| 331 | + }
|
| 332 | + }
|
| 333 | + }
|
| 334 | +
|
| 335 | +}
|
| 336 | +
|
| 337 | +?>
|