Index: trunk/extensions/SphinxSearch/SphinxMWSearch.php |
— | — | @@ -19,8 +19,18 @@ |
20 | 20 | var $db; |
21 | 21 | var $sphinx_client = null; |
22 | 22 | |
23 | | - function __construct( $db ) { |
24 | | - parent::__construct( $db ); |
| 23 | + /** |
| 24 | + * Do not go to a near match if query prefixed with ~ |
| 25 | + * |
| 26 | + * @param $searchterm String |
| 27 | + * @return Title |
| 28 | + */ |
| 29 | + public static function getNearMatch( $searchterm ) { |
| 30 | + if ( $searchterm[ 0 ] === '~' ) { |
| 31 | + return null; |
| 32 | + } else { |
| 33 | + return parent::getNearMatch( $searchterm ); |
| 34 | + } |
25 | 35 | } |
26 | 36 | |
27 | 37 | /** |
— | — | @@ -84,19 +94,12 @@ |
85 | 95 | } |
86 | 96 | |
87 | 97 | /** |
88 | | - * We do a weighted title/body search, no need to return titles separately |
89 | | - */ |
90 | | - function searchTitle() { |
91 | | - return null; |
92 | | - } |
93 | | - |
94 | | - /** |
95 | 98 | * @return SphinxClient: ready to run or false if term is empty |
96 | 99 | */ |
97 | 100 | function prepareSphinxClient( &$term ) { |
98 | 101 | global $wgSphinxSearch_sortmode, $wgSphinxSearch_sortby, $wgSphinxSearch_host, |
99 | | - $wgSphinxSearch_port, $wgSphinxSearch_index_weights, $wgSphinxSearch_index, |
100 | | - $wgSphinxSearch_mode, $wgSphinxMatchAll, $wgSphinxSearch_maxmatches, |
| 102 | + $wgSphinxSearch_port, $wgSphinxSearch_index_weights, |
| 103 | + $wgSphinxSearch_mode, $wgSphinxSearch_maxmatches, |
101 | 104 | $wgSphinxSearch_cutoff, $wgSphinxSearch_weights; |
102 | 105 | |
103 | 106 | // don't do anything for blank searches |
— | — | @@ -152,44 +155,31 @@ |
153 | 156 | return $cl; |
154 | 157 | } |
155 | 158 | |
156 | | - /** |
157 | | - * @return Boolean: can we list/unlist redirects |
158 | | - */ |
159 | | - function acceptListRedirects() { |
160 | | - return true; |
161 | | - } |
162 | | - |
163 | | - /** |
164 | | - * @return String: allowed query characters |
165 | | - */ |
166 | | - public static function legalSearchChars() { |
167 | | - return "A-Za-z_'./\"!~0-9\\x80-\\xFF\\-"; |
168 | | - } |
169 | | - |
170 | 159 | } |
171 | 160 | |
172 | 161 | class SphinxMWSearchResultSet extends SearchResultSet { |
| 162 | + |
173 | 163 | var $mNdx = 0; |
174 | | - var $sphinx_client = null; |
| 164 | + var $sphinx_client; |
175 | 165 | var $mSuggestion = ''; |
| 166 | + var $db; |
176 | 167 | |
177 | 168 | function __construct( $resultSet, $terms, $sphinx_client, $dbr ) { |
178 | | - global $wgSphinxSearch_index; |
179 | | - |
180 | 169 | $this->sphinx_client = $sphinx_client; |
181 | 170 | $this->mResultSet = array(); |
| 171 | + $this->db = $dbr ? $dbr : wfGetDB( DB_SLAVE ); |
182 | 172 | |
183 | 173 | if ( is_array( $resultSet ) && isset( $resultSet['matches'] ) ) { |
184 | 174 | foreach ( $resultSet['matches'] as $id => $docinfo ) { |
185 | | - $res = $dbr->select( |
| 175 | + $res = $this->db->select( |
186 | 176 | 'page', |
187 | 177 | array( 'page_id', 'page_title', 'page_namespace' ), |
188 | 178 | array( 'page_id' => $id ), |
189 | 179 | __METHOD__, |
190 | 180 | array() |
191 | 181 | ); |
192 | | - if ( $dbr->numRows( $res ) > 0 ) { |
193 | | - $this->mResultSet[] = $dbr->fetchObject( $res ); |
| 182 | + if ( $this->db->numRows( $res ) > 0 ) { |
| 183 | + $this->mResultSet[] = $this->db->fetchObject( $res ); |
194 | 184 | } |
195 | 185 | } |
196 | 186 | } |
— | — | @@ -208,11 +198,11 @@ |
209 | 199 | |
210 | 200 | if ( $wgSphinxSuggestMode ) { |
211 | 201 | $this->mSuggestion = ''; |
212 | | - if ( $wgSphinxSuggestMode == 'enchant' ) { |
| 202 | + if ( $wgSphinxSuggestMode === 'enchant' ) { |
213 | 203 | $this->suggestWithEnchant(); |
214 | | - } elseif ( $wgSphinxSuggestMode == 'soundex' ) { |
| 204 | + } elseif ( $wgSphinxSuggestMode === 'soundex' ) { |
215 | 205 | $this->suggestWithSoundex(); |
216 | | - } elseif ( $wgSphinxSuggestMode == 'aspell' ) { |
| 206 | + } elseif ( $wgSphinxSuggestMode === 'aspell' ) { |
217 | 207 | $this->suggestWithAspell(); |
218 | 208 | } |
219 | 209 | if ($this->mSuggestion) { |
— | — | @@ -259,9 +249,8 @@ |
260 | 250 | * Default (weak) suggestions implementation relies on MySQL soundex |
261 | 251 | */ |
262 | 252 | function suggestWithSoundex() { |
263 | | - $dbr = wfGetDB( DB_SLAVE ); |
264 | | - $joined_terms = $dbr->addQuotes( join( ' ', $this->mTerms ) ); |
265 | | - $res = $dbr->select( |
| 253 | + $joined_terms = $this->db->addQuotes( join( ' ', $this->mTerms ) ); |
| 254 | + $res = $this->db->select( |
266 | 255 | array( 'page' ), |
267 | 256 | array( 'page_title' ), |
268 | 257 | array( |
— | — | @@ -275,7 +264,7 @@ |
276 | 265 | 'LIMIT' => 1 |
277 | 266 | ) |
278 | 267 | ); |
279 | | - $suggestion = $dbr->fetchObject( $res ); |
| 268 | + $suggestion = $this->db->fetchObject( $res ); |
280 | 269 | if ( is_object( $suggestion ) ) { |
281 | 270 | $this->mSuggestion = trim( $suggestion->page_title ); |
282 | 271 | } |