Index: trunk/extensions/SphinxSearch/SphinxSearch.i18n.php |
— | — | @@ -8,7 +8,6 @@ |
9 | 9 | 'sphinxPowered' => 'Powered by $1', |
10 | 10 | 'sphinxClientFailed' => 'Could not instantiate Sphinx client.', |
11 | 11 | 'sphinxSearchFailed' => 'Query failed: $1', |
12 | | - 'sphinxSearchWarning' => 'Warning: $1', |
13 | 12 | 'sphinxPspellError' => 'Could not invoke pspell extension.' |
14 | 13 | ); |
15 | 14 | |
Index: trunk/extensions/SphinxSearch/SphinxSearch.php |
— | — | @@ -11,7 +11,7 @@ |
12 | 12 | |
13 | 13 | $wgExtensionCredits['other'][] = array( |
14 | 14 | 'path' => __FILE__, |
15 | | - 'version' => '0.8.2', |
| 15 | + 'version' => '0.8.3', |
16 | 16 | 'name' => 'SphinxSearch', |
17 | 17 | 'author' => array( 'Svemir Brkic', 'Paul Grinberg' ), |
18 | 18 | 'url' => 'http://www.mediawiki.org/wiki/Extension:SphinxSearch', |
— | — | @@ -84,9 +84,6 @@ |
85 | 85 | 'page_title' => 100 |
86 | 86 | ); |
87 | 87 | |
88 | | -# Set to true to use MW's default search snippets and highlighting |
89 | | -$wgSphinxSearchMWHighlighter = false; |
90 | | - |
91 | 88 | # Should the suggestion (Did you mean?) mode be enabled? Possible values: |
92 | 89 | # enchant - see http://www.mediawiki.org/wiki/Extension:SphinxSearch/Search_suggestions |
93 | 90 | # soundex - uses MySQL soundex() function to recommend existing titles |
Index: trunk/extensions/SphinxSearch/SphinxMWSearch.php |
— | — | @@ -324,6 +324,8 @@ |
325 | 325 | var $total_hits = 0; |
326 | 326 | |
327 | 327 | function __construct( $resultSet, $terms, $sphinx_client, $dbr ) { |
| 328 | + global $wgSearchHighlightBoundaries; |
| 329 | + |
328 | 330 | $this->sphinx_client = $sphinx_client; |
329 | 331 | $this->mResultSet = array(); |
330 | 332 | $this->db = $dbr ? $dbr : wfGetDB( DB_SLAVE ); |
— | — | @@ -343,7 +345,7 @@ |
344 | 346 | } |
345 | 347 | } |
346 | 348 | $this->mNdx = 0; |
347 | | - $this->mTerms = preg_split('/\W+/', $terms); |
| 349 | + $this->mTerms = preg_split( "/$wgSearchHighlightBoundaries+/ui", $terms ); |
348 | 350 | } |
349 | 351 | |
350 | 352 | /** |
— | — | @@ -559,48 +561,23 @@ |
560 | 562 | } |
561 | 563 | |
562 | 564 | /** |
563 | | - * @param $terms Array: terms to highlight |
564 | | - * @return String: highlighted text snippet, null (and not '') if not supported |
| 565 | + * Emulates SearchEngine getTextSnippet so that we can use our own userHighlightPrefs |
| 566 | + * (only needed until userHighlightPrefs in SearchEngine is fixed) |
| 567 | + * |
| 568 | + * @param $terms array of terms to highlight |
| 569 | + * @return string highlighted text snippet |
565 | 570 | */ |
566 | | - function getTextSnippet( $terms ){ |
567 | | - global $wgUser, $wgSphinxSearchMWHighlighter, $wgSphinxSearch_index; |
| 571 | + function getTextSnippet( $terms ) { |
| 572 | + global $wgUser, $wgAdvancedSearchHighlighting; |
568 | 573 | |
569 | | - if ( $wgSphinxSearchMWHighlighter ) { |
570 | | - return parent::getTextSnippet( $terms ); |
571 | | - } |
572 | | - |
573 | 574 | $this->initText(); |
574 | | - |
575 | 575 | list( $contextlines, $contextchars ) = SphinxMWSearch::userHighlightPrefs( $wgUser ); |
576 | | - $excerpts_opt = array( |
577 | | - "before_match" => "<span class='searchmatch'>", |
578 | | - "after_match" => "</span>", |
579 | | - "chunk_separator" => " ... ", |
580 | | - "limit" => $contextlines * $contextchars, |
581 | | - "around" => $contextchars |
582 | | - ); |
583 | | - |
584 | | - $excerpts = $this->sphinx_client->BuildExcerpts( |
585 | | - array( $this->mText ), |
586 | | - $wgSphinxSearch_index, |
587 | | - join( ' ', $terms ), |
588 | | - $excerpts_opt |
589 | | - ); |
590 | | - |
591 | | - if ( is_array( $excerpts ) ) { |
592 | | - $ret = ''; |
593 | | - foreach ( $excerpts as $entry ) { |
594 | | - // remove some wiki markup |
595 | | - $entry = preg_replace( '/([\[\]\{\}\*\#\|\!]+|==+)/', |
596 | | - ' ', |
597 | | - strip_tags( $entry, '<span><br>' ) |
598 | | - ); |
599 | | - $ret .= "<div style='margin: 0.2em 1em 0.2em 1em;'>$entry</div>\n"; |
600 | | - } |
| 576 | + $h = new SearchHighlighter(); |
| 577 | + if ( $wgAdvancedSearchHighlighting ) { |
| 578 | + return $h->highlightText( $this->mText, $terms, $contextlines, $contextchars ); |
601 | 579 | } else { |
602 | | - $ret = wfMsg( 'sphinxSearchWarning', $this->sphinx_client->GetLastError() ); |
| 580 | + return $h->highlightSimple( $this->mText, $terms, $contextlines, $contextchars ); |
603 | 581 | } |
604 | | - return $ret; |
605 | 582 | } |
606 | 583 | |
607 | 584 | } |