http://www.mediawiki.org/wiki/Special:Code/MediaWiki/96821

Revision: 96821
Author:   svemir
Date:     2011-09-12 00:09:48 +0000 (Mon, 12 Sep 2011)
Log Message:
-----------
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
    trunk/extensions/SphinxSearch/SphinxSearch.php

Modified: trunk/extensions/SphinxSearch/SphinxMWSearch.php
===================================================================
--- trunk/extensions/SphinxSearch/SphinxMWSearch.php    2011-09-12 00:08:26 UTC 
(rev 96820)
+++ trunk/extensions/SphinxSearch/SphinxMWSearch.php    2011-09-12 00:09:48 UTC 
(rev 96821)
@@ -578,15 +578,59 @@
         */
        function getTextSnippet( $terms ) {
                global $wgUser, $wgAdvancedSearchHighlighting;
+               global $wgSphinxSearchMWHighlighter, $wgSphinxSearch_index;
 
                $this->initText();
                list( $contextlines, $contextchars ) = 
SphinxMWSearch::userHighlightPrefs( $wgUser );
-               $h = new SearchHighlighter();
-               if ( $wgAdvancedSearchHighlighting ) {
-                       return $h->highlightText( $this->mText, $terms, 
$contextlines, $contextchars );
+               if ( $wgSphinxSearchMWHighlighter ) {
+                       $h = new SearchHighlighter();
+                       if ( $wgAdvancedSearchHighlighting ) {
+                               return $h->highlightText( $this->mText, $terms, 
$contextlines, $contextchars );
+                       } else {
+                               return $h->highlightSimple( $this->mText, 
$terms, $contextlines, $contextchars );
+                       }
+               }
+
+               $excerpts_opt = array(
+                       "before_match" => "(searchmatch)",
+                       "after_match" => "(/searchmatch)",
+                       "chunk_separator" => " ... ",
+                       "limit" => $contextlines * $contextchars,
+                       "around" => $contextchars,
+               );
+
+               $excerpts = $this->sphinx_client->BuildExcerpts(
+                       array( $this->mText ),
+                       $wgSphinxSearch_index,
+                       join( ' ', $terms ),
+                       $excerpts_opt
+               );
+
+               if ( is_array( $excerpts ) ) {
+                       $ret = '';
+                       foreach ( $excerpts as $entry ) {
+                               // remove some wiki markup
+                               $entry = preg_replace(
+                                       '/([\[\]\{\}\*\#\|\!]+|==+|<br ?\/?>)/',
+                                       ' ',
+                                       $entry
+                               );
+                               $entry = str_replace(
+                                       array("<", ">"),
+                                       array("&lt;", "&gt;"),
+                                       $entry
+                               );
+                               $entry = str_replace(
+                                       array( "(searchmatch)", 
"(/searchmatch)" ),
+                                       array( "<span class='searchmatch'>", 
"</span>" ),
+                                       $entry
+                               );
+                               $ret .= "<div style='margin: 0.2em 1em 0.2em 
1em;'>$entry</div>\n";
+                       }
                } else {
-                       return $h->highlightSimple( $this->mText, $terms, 
$contextlines, $contextchars );
+                       $ret = wfMsg( 'internalerror_info', 
$this->sphinx_client->GetLastError() );
                }
+               return $ret;
        }
 
 }

Modified: trunk/extensions/SphinxSearch/SphinxSearch.php
===================================================================
--- trunk/extensions/SphinxSearch/SphinxSearch.php      2011-09-12 00:08:26 UTC 
(rev 96820)
+++ trunk/extensions/SphinxSearch/SphinxSearch.php      2011-09-12 00:09:48 UTC 
(rev 96821)
@@ -11,7 +11,7 @@
 
 $wgExtensionCredits['other'][] = array(
        'path'           => __FILE__,
-       'version'        => '0.8.4',
+       'version'        => '0.8.5',
        'name'           => 'SphinxSearch',
        'author'         => array( 'Svemir Brkic', 'Paul Grinberg' ),
        'url'            => 
'http://www.mediawiki.org/wiki/Extension:SphinxSearch',
@@ -84,6 +84,9 @@
        'page_title' => 100
 );
 
+# Set to true to use MW's default search snippets and highlighting
+$wgSphinxSearchMWHighlighter = false;
+
 # Should the suggestion (Did you mean?) mode be enabled? Possible values:
 # enchant - see 
http://www.mediawiki.org/wiki/Extension:SphinxSearch/Search_suggestions
 # soundex - uses MySQL soundex() function to recommend existing titles


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to