http://www.mediawiki.org/wiki/Special:Code/MediaWiki/96710
Revision: 96710
Author: svemir
Date: 2011-09-10 02:35:01 +0000 (Sat, 10 Sep 2011)
Log Message:
-----------
added $wgEnableSphinxPrefixSearch var - if true (and $wgEnableMWSuggest is true
as well) use Sphinx for search suggestions
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-10 01:09:45 UTC
(rev 96709)
+++ trunk/extensions/SphinxSearch/SphinxMWSearch.php 2011-09-10 02:35:01 UTC
(rev 96710)
@@ -39,6 +39,23 @@
}
/**
+ * PrefixSearchBackend override for OpenSearch results
+ */
+ static function prefixSearch( $namespaces, $term, $limit, &$results ) {
+ $search_engine = new SphinxMWSearch( wfGetDB( DB_SLAVE ) );
+ $search_engine->namespaces = $namespaces;
+ $search_engine->setLimitOffset( $limit, 0 );
+ $result_set = $search_engine->searchText( '@page_title: ^' .
$term . '*' );
+ $results = array();
+ if ( $result_set ) {
+ while ( $res = $result_set->next() ) {
+ $results[ ] =
$res->getTitle()->getPrefixedText();
+ }
+ }
+ return false;
+ }
+
+ /**
* Perform a full text search query and return a result set.
*
* @param string $term - Raw search term
@@ -566,7 +583,7 @@
$excerpts = $this->sphinx_client->BuildExcerpts(
array( $this->mText ),
$wgSphinxSearch_index,
- join(' ', $terms),
+ join( ' ', $terms ),
$excerpts_opt
);
Modified: trunk/extensions/SphinxSearch/SphinxSearch.php
===================================================================
--- trunk/extensions/SphinxSearch/SphinxSearch.php 2011-09-10 01:09:45 UTC
(rev 96709)
+++ trunk/extensions/SphinxSearch/SphinxSearch.php 2011-09-10 02:35:01 UTC
(rev 96710)
@@ -23,6 +23,7 @@
$wgAutoloadClasses[ 'SphinxMWSearch' ] = $dir . 'SphinxMWSearch.php';
$wgExtensionMessagesFiles['SphinxSearch'] = $dir . 'SphinxSearch.i18n.php';
+$wgExtensionFunctions[ ] = 'efSphinxSearchPrefixSetup';
# To completely disable the default search and replace it with SphinxSearch,
# set this BEFORE including SphinxSearch.php in LocalSettings.php
@@ -75,7 +76,7 @@
$wgSphinxSearchMWHighlighter = false;
# Should the suggestion (Did you mean?) mode be enabled? Possible values:
-# enchant - see
http://www.mediawiki.org/wiki/Extension_talk:SphinxSearch#Search_suggestions
+# enchant - see
http://www.mediawiki.org/wiki/Extension:SphinxSearch/Search_suggestions
# soundex - uses MySQL soundex() function to recommend existing titles
# aspell - uses aspell command-line utility to look for similar spellings
$wgSphinxSuggestMode = '';
@@ -97,3 +98,15 @@
'old_text' => 1,
'page_title' => 100
);
+
+# If true, use SphinxMWSearch for search suggestions displayed while typing
+# $wgEnableMWSuggest needs to be set to true as well
+$wgEnableSphinxPrefixSearch = false;
+
+function efSphinxSearchPrefixSetup() {
+ global $wgHooks, $wgEnableSphinxPrefixSearch;
+
+ if ( $wgEnableSphinxPrefixSearch ) {
+ $wgHooks[ 'PrefixSearchBackend' ][ ] =
'SphinxMWSearch::prefixSearch';
+ }
+}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs