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.4', |
| 15 | + 'version' => '0.8.5', |
16 | 16 | 'name' => 'SphinxSearch', |
17 | 17 | 'author' => array( 'Svemir Brkic', 'Paul Grinberg' ), |
18 | 18 | 'url' => 'http://www.mediawiki.org/wiki/Extension:SphinxSearch', |
— | — | @@ -84,6 +84,9 @@ |
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 | + |
88 | 91 | # Should the suggestion (Did you mean?) mode be enabled? Possible values: |
89 | 92 | # enchant - see http://www.mediawiki.org/wiki/Extension:SphinxSearch/Search_suggestions |
90 | 93 | # soundex - uses MySQL soundex() function to recommend existing titles |
Index: trunk/extensions/SphinxSearch/SphinxMWSearch.php |
— | — | @@ -578,15 +578,59 @@ |
579 | 579 | */ |
580 | 580 | function getTextSnippet( $terms ) { |
581 | 581 | global $wgUser, $wgAdvancedSearchHighlighting; |
| 582 | + global $wgSphinxSearchMWHighlighter, $wgSphinxSearch_index; |
582 | 583 | |
583 | 584 | $this->initText(); |
584 | 585 | list( $contextlines, $contextchars ) = SphinxMWSearch::userHighlightPrefs( $wgUser ); |
585 | | - $h = new SearchHighlighter(); |
586 | | - if ( $wgAdvancedSearchHighlighting ) { |
587 | | - return $h->highlightText( $this->mText, $terms, $contextlines, $contextchars ); |
| 586 | + if ( $wgSphinxSearchMWHighlighter ) { |
| 587 | + $h = new SearchHighlighter(); |
| 588 | + if ( $wgAdvancedSearchHighlighting ) { |
| 589 | + return $h->highlightText( $this->mText, $terms, $contextlines, $contextchars ); |
| 590 | + } else { |
| 591 | + return $h->highlightSimple( $this->mText, $terms, $contextlines, $contextchars ); |
| 592 | + } |
| 593 | + } |
| 594 | + |
| 595 | + $excerpts_opt = array( |
| 596 | + "before_match" => "(searchmatch)", |
| 597 | + "after_match" => "(/searchmatch)", |
| 598 | + "chunk_separator" => " ... ", |
| 599 | + "limit" => $contextlines * $contextchars, |
| 600 | + "around" => $contextchars, |
| 601 | + ); |
| 602 | + |
| 603 | + $excerpts = $this->sphinx_client->BuildExcerpts( |
| 604 | + array( $this->mText ), |
| 605 | + $wgSphinxSearch_index, |
| 606 | + join( ' ', $terms ), |
| 607 | + $excerpts_opt |
| 608 | + ); |
| 609 | + |
| 610 | + if ( is_array( $excerpts ) ) { |
| 611 | + $ret = ''; |
| 612 | + foreach ( $excerpts as $entry ) { |
| 613 | + // remove some wiki markup |
| 614 | + $entry = preg_replace( |
| 615 | + '/([\[\]\{\}\*\#\|\!]+|==+|<br ?\/?>)/', |
| 616 | + ' ', |
| 617 | + $entry |
| 618 | + ); |
| 619 | + $entry = str_replace( |
| 620 | + array("<", ">"), |
| 621 | + array("<", ">"), |
| 622 | + $entry |
| 623 | + ); |
| 624 | + $entry = str_replace( |
| 625 | + array( "(searchmatch)", "(/searchmatch)" ), |
| 626 | + array( "<span class='searchmatch'>", "</span>" ), |
| 627 | + $entry |
| 628 | + ); |
| 629 | + $ret .= "<div style='margin: 0.2em 1em 0.2em 1em;'>$entry</div>\n"; |
| 630 | + } |
588 | 631 | } else { |
589 | | - return $h->highlightSimple( $this->mText, $terms, $contextlines, $contextchars ); |
| 632 | + $ret = wfMsg( 'internalerror_info', $this->sphinx_client->GetLastError() ); |
590 | 633 | } |
| 634 | + return $ret; |
591 | 635 | } |
592 | 636 | |
593 | 637 | } |