r96735 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96734‎ | r96735 | r96736 >
Date:19:47, 10 September 2011
Author:svemir
Status:deferred
Tags:
Comment:
Fix bug 30840 by correctly splitting terms using $wgSearchHighlightBoundaries - no need to rely on sphinx for excerpts anymore, so remove $wgSphinxSearchMWHighlighter
Modified paths:
  • /trunk/extensions/SphinxSearch/SphinxMWSearch.php (modified) (history)
  • /trunk/extensions/SphinxSearch/SphinxSearch.i18n.php (modified) (history)
  • /trunk/extensions/SphinxSearch/SphinxSearch.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SphinxSearch/SphinxSearch.i18n.php
@@ -8,7 +8,6 @@
99 'sphinxPowered' => 'Powered by $1',
1010 'sphinxClientFailed' => 'Could not instantiate Sphinx client.',
1111 'sphinxSearchFailed' => 'Query failed: $1',
12 - 'sphinxSearchWarning' => 'Warning: $1',
1312 'sphinxPspellError' => 'Could not invoke pspell extension.'
1413 );
1514
Index: trunk/extensions/SphinxSearch/SphinxSearch.php
@@ -11,7 +11,7 @@
1212
1313 $wgExtensionCredits['other'][] = array(
1414 'path' => __FILE__,
15 - 'version' => '0.8.2',
 15+ 'version' => '0.8.3',
1616 'name' => 'SphinxSearch',
1717 'author' => array( 'Svemir Brkic', 'Paul Grinberg' ),
1818 'url' => 'http://www.mediawiki.org/wiki/Extension:SphinxSearch',
@@ -84,9 +84,6 @@
8585 'page_title' => 100
8686 );
8787
88 -# Set to true to use MW's default search snippets and highlighting
89 -$wgSphinxSearchMWHighlighter = false;
90 -
9188 # Should the suggestion (Did you mean?) mode be enabled? Possible values:
9289 # enchant - see http://www.mediawiki.org/wiki/Extension:SphinxSearch/Search_suggestions
9390 # soundex - uses MySQL soundex() function to recommend existing titles
Index: trunk/extensions/SphinxSearch/SphinxMWSearch.php
@@ -324,6 +324,8 @@
325325 var $total_hits = 0;
326326
327327 function __construct( $resultSet, $terms, $sphinx_client, $dbr ) {
 328+ global $wgSearchHighlightBoundaries;
 329+
328330 $this->sphinx_client = $sphinx_client;
329331 $this->mResultSet = array();
330332 $this->db = $dbr ? $dbr : wfGetDB( DB_SLAVE );
@@ -343,7 +345,7 @@
344346 }
345347 }
346348 $this->mNdx = 0;
347 - $this->mTerms = preg_split('/\W+/', $terms);
 349+ $this->mTerms = preg_split( "/$wgSearchHighlightBoundaries+/ui", $terms );
348350 }
349351
350352 /**
@@ -559,48 +561,23 @@
560562 }
561563
562564 /**
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
565570 */
566 - function getTextSnippet( $terms ){
567 - global $wgUser, $wgSphinxSearchMWHighlighter, $wgSphinxSearch_index;
 571+ function getTextSnippet( $terms ) {
 572+ global $wgUser, $wgAdvancedSearchHighlighting;
568573
569 - if ( $wgSphinxSearchMWHighlighter ) {
570 - return parent::getTextSnippet( $terms );
571 - }
572 -
573574 $this->initText();
574 -
575575 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 );
601579 } else {
602 - $ret = wfMsg( 'sphinxSearchWarning', $this->sphinx_client->GetLastError() );
 580+ return $h->highlightSimple( $this->mText, $terms, $contextlines, $contextchars );
603581 }
604 - return $ret;
605582 }
606583
607584 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r96821bring back $wgSphinxSearchMWHighlighter to keep MW highlighting optional, and...svemir00:09, 12 September 2011

Status & tagging log