r96768 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96767‎ | r96768 | r96769 >
Date:02:30, 11 September 2011
Author:svemir
Status:deferred
Tags:
Comment:
Added support for -incategory: prefix to exclude categories, and some wfDebug calls
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.3',
 15+ 'version' => '0.8.4',
1616 'name' => 'SphinxSearch',
1717 'author' => array( 'Svemir Brkic', 'Paul Grinberg' ),
1818 'url' => 'http://www.mediawiki.org/wiki/Extension:SphinxSearch',
Index: trunk/extensions/SphinxSearch/SphinxMWSearch.php
@@ -100,8 +100,10 @@
101101 }
102102 }
103103 $term = str_replace($placeholders, array_keys($placeholders), $term);
 104+ $term = addcslashes( $term, $escape );
 105+ wfDebug( "SphinxSearch query: $term\n" );
104106 $resultSet = $this->sphinx_client->Query(
105 - addcslashes( $term, $escape ),
 107+ $term,
106108 $wgSphinxSearch_index_list
107109 );
108110 } else {
@@ -157,9 +159,11 @@
158160 }
159161 if ( $this->categories && count( $this->categories ) ) {
160162 $cl->SetFilter( 'category', $this->categories );
 163+ wfDebug( "SphinxSearch included categories: " . join( ', ', $this->categories ) . "\n" );
161164 }
162165 if ( $this->exc_categories && count( $this->exc_categories ) ) {
163166 $cl->SetFilter( 'category', $this->exc_categories, true );
 167+ wfDebug( "SphinxSearch excluded categories: " . join( ', ', $this->exc_categories ) . "\n" );
164168 }
165169 $cl->SetSortMode( $wgSphinxSearch_sortmode, $wgSphinxSearch_sortby );
166170 $cl->SetLimits(
@@ -201,7 +205,7 @@
202206 $parts = preg_split( '/(")/', $query, -1, PREG_SPLIT_DELIM_CAPTURE );
203207 $inquotes = false;
204208 $rewritten = '';
205 - foreach ( $parts as $part ) {
 209+ foreach ( $parts as $key => $part ) {
206210 if ( $part == '"' ) { // stuff in quotes doesn't get rewritten
207211 $rewritten .= $part;
208212 $inquotes = !$inquotes;
@@ -211,7 +215,7 @@
212216 if ( strpos( $query, ':' ) !== false ) {
213217 $regexp = $this->preparePrefixRegexp();
214218 $part = preg_replace_callback(
215 - '/(^|[| :])(' . $regexp . '):([^ ]+)/i',
 219+ '/(^|[| :]|-)(' . $regexp . '):([^ ]+)/i',
216220 array( $this, 'replaceQueryPrefix' ),
217221 $part
218222 );
@@ -309,7 +313,12 @@
310314 ),
311315 __METHOD__
312316 );
313 - $this->categories[] = intval( $page_id );
 317+ $category = intval( $page_id );
 318+ if ( $matches[ 1 ] === '-' ) {
 319+ $this->exc_categories[ ] = $category;
 320+ } else {
 321+ $this->categories[ ] = $category;
 322+ }
314323 return '';
315324 }
316325

Status & tagging log