Chad has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/182142

Change subject: Remove random support
......................................................................

Remove random support

It's slow.

Change-Id: Idfb0fbd9d1e9d7c62fd86f82a5b838c07b83f5dc
---
M CirrusSearch.php
M includes/CirrusSearch.php
M includes/Hooks.php
M includes/Searcher.php
D tests/browser/features/special_random.feature
5 files changed, 1 insertion(+), 91 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CirrusSearch 
refs/changes/42/182142/1

diff --git a/CirrusSearch.php b/CirrusSearch.php
index 0d3be9a..72cca7c 100644
--- a/CirrusSearch.php
+++ b/CirrusSearch.php
@@ -428,10 +428,6 @@
 // which most wikis will want. Edge cases will want to turn this off.
 $wgCirrusSearchBoostLinks = true;
 
-// Should Cirrus power Special:Random?  The result is truely random BUT it is
-// somewhat expensive to generate.
-$wgCirrusSearchPowerSpecialRandom = true;
-
 // Shard allocation settings. The include/exclude/require top level keys are
 // the type of rule to use, the names should be self explanatory. The values
 // are an array of keys and values of different rules to apply to an index.
@@ -508,7 +504,6 @@
        'mainPageCacheWarmer',
        'cacheWarmers',
        'boostLinks',
-       'powerSpecialRandom',
        'indexAllocation',
 );
 
@@ -629,7 +624,6 @@
 $wgHooks[ 'GetBetaFeaturePreferences' ][] = 
'CirrusSearch\Hooks::onGetBetaFeaturePreferences';
 $wgHooks[ 'LinksUpdateComplete' ][] = 
'CirrusSearch\Hooks::onLinksUpdateCompleted';
 $wgHooks[ 'SoftwareInfo' ][] = 'CirrusSearch\Hooks::onSoftwareInfo';
-$wgHooks[ 'SpecialRandomGetRandomTitle' ][] = 
'CirrusSearch\Hooks::onSpecialRandomGetRandomTitle';
 $wgHooks[ 'SpecialSearchResultsPrepend' ][] = 
'CirrusSearch\Hooks::onSpecialSearchResultsPrepend';
 $wgHooks[ 'TitleMove' ][] = 'CirrusSearch\Hooks::onTitleMove';
 $wgHooks[ 'TitleMoveComplete' ][] = 'CirrusSearch\Hooks::onTitleMoveComplete';
diff --git a/includes/CirrusSearch.php b/includes/CirrusSearch.php
index 45451a0..418a43a 100644
--- a/includes/CirrusSearch.php
+++ b/includes/CirrusSearch.php
@@ -227,7 +227,7 @@
         * @return array
         */
        public function getValidSorts() {
-               return array( 'relevance', 'title_asc', 'title_desc', 'random' 
);
+               return array( 'relevance', 'title_asc', 'title_desc' );
        }
 
        /**
diff --git a/includes/Hooks.php b/includes/Hooks.php
index 858088a..529d0f0 100644
--- a/includes/Hooks.php
+++ b/includes/Hooks.php
@@ -499,48 +499,6 @@
        }
 
        /**
-        * Get a random page
-        *
-        * @param string $randstr A random seed given from MediaWiki.
-        * @param bool $isRedir Are we wanting a random redirect?
-        * @param array(int) $namespaces An array of namespaces to pick a page 
from
-        * @param array $extra Extra query params for the database-backed 
random. Unused.
-        * @param Title $title The title we want to return, if any
-        * @return bool False if we've set $title, true otherwise
-        */
-       public static function onSpecialRandomGetRandomTitle( &$randstr, 
&$isRedir, &$namespaces, &$extra, &$title ) {
-               global $wgCirrusSearchPowerSpecialRandom;
-
-               if ( !$wgCirrusSearchPowerSpecialRandom ) {
-                       return true;
-               }
-               // We don't index redirects so don't try to find one.
-               if ( !$isRedir && !$extra ) {
-                       // Remove decimal from seed, we want an int
-                       $seed = (int)str_replace( '.', '', $randstr );
-
-                       $searcher = new Searcher( 0, 1, $namespaces,
-                               RequestContext::getMain()->getUser() );
-                       $searcher->limitSearchToLocalWiki( true );
-                       $randSearch = $searcher->randomSearch( $seed );
-                       if ( $randSearch->isOk() ) {
-                               $results = $randSearch->getValue();
-                               // should almost never happen unless you're 
developing
-                               // on a completely empty wiki with no pages
-                               if ( isset( $results[ 0 ] ) ) {
-                                       $page = WikiPage::newFromID( $results[ 
0 ] );
-                                       if ( $page ) {
-                                               $title = $page->getTitle();
-                                               return false;
-                                       }
-                               }
-                       }
-               }
-
-               return true;
-       }
-
-       /**
         * Take a list of titles either linked or unlinked and prepare them for 
Job\LinksUpdate.
         * This includes limiting them to $max titles.
         * @param array(Title) $titles titles to prepare
diff --git a/includes/Searcher.php b/includes/Searcher.php
index f9c0b0d..2f823c6 100644
--- a/includes/Searcher.php
+++ b/includes/Searcher.php
@@ -310,18 +310,6 @@
        }
 
        /**
-        * Perform a random search
-        * @param int $seed Seed for the random number generator
-        * @param Status(mixed) status containing results defined by 
resultsType on success
-        */
-       public function randomSearch( $seed ) {
-               $this->setResultsType( new IdResultsType() );
-               $this->sort = 'random';
-
-               return $this->search( 'random', $seed );
-       }
-
-       /**
         * @param string $suggestPrefix prefix to be prepended to suggestions
         */
        public function addSuggestPrefix( $suggestPrefix ) {
@@ -1028,13 +1016,6 @@
                                'order' => 'desc',
                                'missing' => '_last',
                        ) ) );
-                       break;
-               case 'random':
-                       // Random scoring is funky - you have to wrap the query 
in a FunctionScore query.
-                       $funcScore = new \Elastica\Query\FunctionScore();
-                       $funcScore->setRandomScore( $for );
-                       $funcScore->setQuery( $this->query );
-                       $query->setQuery( $funcScore );
                        break;
                default:
                        wfLogWarning( "Invalid sort type:  $this->sort" );
diff --git a/tests/browser/features/special_random.feature 
b/tests/browser/features/special_random.feature
deleted file mode 100644
index 9f63ebf..0000000
--- a/tests/browser/features/special_random.feature
+++ /dev/null
@@ -1,23 +0,0 @@
-@clean @phantomjs @special_random
-Feature: Cirrus powered Special:Random
-  Scenario: Special:Random gives a page in the main namespace by default
-    When I am at a random page
-    Then I am on a page in the main namespace
-
-  # Repeats test three times because failure is, well, random
-  Scenario: Special:Random/User gives a page in the user namespace
-    When I am at a random User page
-    Then I am on a page in the User namespace
-    When I am at a random User page
-    Then I am on a page in the User namespace
-    When I am at a random User page
-    Then I am on a page in the User namespace
-
-  # Repeats test three times because failure is, well, random
-  Scenario: Special:Random/User_talk gives a page in the user namespace
-    When I am at a random User_talk page
-    Then I am on a page in the User talk namespace
-    When I am at a random User_talk page
-    Then I am on a page in the User talk namespace
-    When I am at a random User_talk page
-    Then I am on a page in the User talk namespace

-- 
To view, visit https://gerrit.wikimedia.org/r/182142
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idfb0fbd9d1e9d7c62fd86f82a5b838c07b83f5dc
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: Chad <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to