Index: trunk/extensions/SphinxSearch/SphinxSearch.php |
— | — | @@ -23,6 +23,7 @@ |
24 | 24 | |
25 | 25 | $wgAutoloadClasses[ 'SphinxMWSearch' ] = $dir . 'SphinxMWSearch.php'; |
26 | 26 | $wgExtensionMessagesFiles['SphinxSearch'] = $dir . 'SphinxSearch.i18n.php'; |
| 27 | +$wgExtensionFunctions[ ] = 'efSphinxSearchPrefixSetup'; |
27 | 28 | |
28 | 29 | # To completely disable the default search and replace it with SphinxSearch, |
29 | 30 | # set this BEFORE including SphinxSearch.php in LocalSettings.php |
— | — | @@ -75,7 +76,7 @@ |
76 | 77 | $wgSphinxSearchMWHighlighter = false; |
77 | 78 | |
78 | 79 | # 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 |
80 | 81 | # soundex - uses MySQL soundex() function to recommend existing titles |
81 | 82 | # aspell - uses aspell command-line utility to look for similar spellings |
82 | 83 | $wgSphinxSuggestMode = ''; |
— | — | @@ -97,3 +98,15 @@ |
98 | 99 | 'old_text' => 1, |
99 | 100 | 'page_title' => 100 |
100 | 101 | ); |
| 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 @@ |
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
| 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 | + /** |
43 | 60 | * Perform a full text search query and return a result set. |
44 | 61 | * |
45 | 62 | * @param string $term - Raw search term |
— | — | @@ -566,7 +583,7 @@ |
567 | 584 | $excerpts = $this->sphinx_client->BuildExcerpts( |
568 | 585 | array( $this->mText ), |
569 | 586 | $wgSphinxSearch_index, |
570 | | - join(' ', $terms), |
| 587 | + join( ' ', $terms ), |
571 | 588 | $excerpts_opt |
572 | 589 | ); |
573 | 590 | |