r96710 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96709‎ | r96710 | r96711 >
Date:02:35, 10 September 2011
Author:svemir
Status:deferred
Tags:
Comment:
added $wgEnableSphinxPrefixSearch var - if true (and $wgEnableMWSuggest is true as well) use Sphinx for search suggestions
Modified paths:
  • /trunk/extensions/SphinxSearch/SphinxMWSearch.php (modified) (history)
  • /trunk/extensions/SphinxSearch/SphinxSearch.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SphinxSearch/SphinxSearch.php
@@ -23,6 +23,7 @@
2424
2525 $wgAutoloadClasses[ 'SphinxMWSearch' ] = $dir . 'SphinxMWSearch.php';
2626 $wgExtensionMessagesFiles['SphinxSearch'] = $dir . 'SphinxSearch.i18n.php';
 27+$wgExtensionFunctions[ ] = 'efSphinxSearchPrefixSetup';
2728
2829 # To completely disable the default search and replace it with SphinxSearch,
2930 # set this BEFORE including SphinxSearch.php in LocalSettings.php
@@ -75,7 +76,7 @@
7677 $wgSphinxSearchMWHighlighter = false;
7778
7879 # Should the suggestion (Did you mean?) mode be enabled? Possible values:
79 -# enchant - see http://www.mediawiki.org/wiki/Extension_talk:SphinxSearch#Search_suggestions
 80+# enchant - see http://www.mediawiki.org/wiki/Extension:SphinxSearch/Search_suggestions
8081 # soundex - uses MySQL soundex() function to recommend existing titles
8182 # aspell - uses aspell command-line utility to look for similar spellings
8283 $wgSphinxSuggestMode = '';
@@ -97,3 +98,15 @@
9899 'old_text' => 1,
99100 'page_title' => 100
100101 );
 102+
 103+# If true, use SphinxMWSearch for search suggestions displayed while typing
 104+# $wgEnableMWSuggest needs to be set to true as well
 105+$wgEnableSphinxPrefixSearch = false;
 106+
 107+function efSphinxSearchPrefixSetup() {
 108+ global $wgHooks, $wgEnableSphinxPrefixSearch;
 109+
 110+ if ( $wgEnableSphinxPrefixSearch ) {
 111+ $wgHooks[ 'PrefixSearchBackend' ][ ] = 'SphinxMWSearch::prefixSearch';
 112+ }
 113+}
Index: trunk/extensions/SphinxSearch/SphinxMWSearch.php
@@ -39,6 +39,23 @@
4040 }
4141
4242 /**
 43+ * PrefixSearchBackend override for OpenSearch results
 44+ */
 45+ static function prefixSearch( $namespaces, $term, $limit, &$results ) {
 46+ $search_engine = new SphinxMWSearch( wfGetDB( DB_SLAVE ) );
 47+ $search_engine->namespaces = $namespaces;
 48+ $search_engine->setLimitOffset( $limit, 0 );
 49+ $result_set = $search_engine->searchText( '@page_title: ^' . $term . '*' );
 50+ $results = array();
 51+ if ( $result_set ) {
 52+ while ( $res = $result_set->next() ) {
 53+ $results[ ] = $res->getTitle()->getPrefixedText();
 54+ }
 55+ }
 56+ return false;
 57+ }
 58+
 59+ /**
4360 * Perform a full text search query and return a result set.
4461 *
4562 * @param string $term - Raw search term
@@ -566,7 +583,7 @@
567584 $excerpts = $this->sphinx_client->BuildExcerpts(
568585 array( $this->mText ),
569586 $wgSphinxSearch_index,
570 - join(' ', $terms),
 587+ join( ' ', $terms ),
571588 $excerpts_opt
572589 );
573590

Follow-up revisions

RevisionCommit summaryAuthorDate
r96711Forgot to increase the version in r96710, plus some tweakssvemir02:43, 10 September 2011

Status & tagging log