r96821 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96820‎ | r96821 | r96822 >
Date:00:09, 12 September 2011
Author:svemir
Status:deferred
Tags:
Comment:
bring back $wgSphinxSearchMWHighlighter to keep MW highlighting optional, and bring back an improved version of sphinx-based highlighting, all for bug 30840 again
Modified paths:
  • /trunk/extensions/SphinxSearch/SphinxMWSearch.php (modified) (history)
  • /trunk/extensions/SphinxSearch/SphinxSearch.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SphinxSearch/SphinxSearch.php
@@ -11,7 +11,7 @@
1212
1313 $wgExtensionCredits['other'][] = array(
1414 'path' => __FILE__,
15 - 'version' => '0.8.4',
 15+ 'version' => '0.8.5',
1616 'name' => 'SphinxSearch',
1717 'author' => array( 'Svemir Brkic', 'Paul Grinberg' ),
1818 'url' => 'http://www.mediawiki.org/wiki/Extension:SphinxSearch',
@@ -84,6 +84,9 @@
8585 'page_title' => 100
8686 );
8787
 88+# Set to true to use MW's default search snippets and highlighting
 89+$wgSphinxSearchMWHighlighter = false;
 90+
8891 # Should the suggestion (Did you mean?) mode be enabled? Possible values:
8992 # enchant - see http://www.mediawiki.org/wiki/Extension:SphinxSearch/Search_suggestions
9093 # soundex - uses MySQL soundex() function to recommend existing titles
Index: trunk/extensions/SphinxSearch/SphinxMWSearch.php
@@ -578,15 +578,59 @@
579579 */
580580 function getTextSnippet( $terms ) {
581581 global $wgUser, $wgAdvancedSearchHighlighting;
 582+ global $wgSphinxSearchMWHighlighter, $wgSphinxSearch_index;
582583
583584 $this->initText();
584585 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("&lt;", "&gt;"),
 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+ }
588631 } else {
589 - return $h->highlightSimple( $this->mText, $terms, $contextlines, $contextchars );
 632+ $ret = wfMsg( 'internalerror_info', $this->sphinx_client->GetLastError() );
590633 }
 634+ return $ret;
591635 }
592636
593637 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r96735Fix bug 30840 by correctly splitting terms using $wgSearchHighlightBoundaries...svemir19:47, 10 September 2011

Status & tagging log