DCausse has uploaded a new change for review.
https://gerrit.wikimedia.org/r/314312
Change subject: Do not fetch results from commons if running from TextCat
......................................................................
Do not fetch results from commons if running from TextCat
Results from commons are likely to be displayed from the local
wiki search, running a query on detected language wiki + commons
will return duplicated results.
Force a local search in such case.
Bug: T145628
Change-Id: Iaecabd70caa251172834ce824cde84de49cb5427
---
M includes/CirrusSearch.php
M includes/Searcher.php
M tests/unit/LanguageDetectTest.php
3 files changed, 44 insertions(+), 4 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CirrusSearch
refs/changes/12/314312/1
diff --git a/includes/CirrusSearch.php b/includes/CirrusSearch.php
index ce43cd0..84ebe33 100644
--- a/includes/CirrusSearch.php
+++ b/includes/CirrusSearch.php
@@ -304,7 +304,7 @@
$config = null;
}
if ( $config ) {
- $matches = $this->searchTextReal( $term,
$config );
+ $matches = $this->searchTextReal( $term,
$config, true );
if ( $matches instanceof ResultSet ) {
$numRows = $matches->numRows();
$this->extraSearchMetrics['wgCirrusSearchAltLanguageNumResults'] = $numRows;
@@ -327,9 +327,11 @@
* Do the hard part of the searching - actual Searcher invocation
* @param string $term
* @param SearchConfig $config
+ * @param boolean $forceLocal set to true to force searching on the
+ * local wiki (e.g. avoid searching on commons)
* @return null|Status|ResultSet
*/
- private function searchTextReal( $term, SearchConfig $config = null ) {
+ protected function searchTextReal( $term, SearchConfig $config = null,
$forceLocal = false ) {
global $wgCirrusSearchInterwikiSources;
// Convert the unicode character 'ideographic whitespace' into
standard
@@ -353,6 +355,8 @@
$searcher->addSuggestPrefix( '~' );
}
+ $searcher->getSearchContext()->setLimitSearchToLocalWiki(
$forceLocal );
+
// TODO remove this when we no longer have to support core
versions without
// Ie946150c6796139201221dfa6f7750c210e97166
if ( method_exists( $this, 'getSort' ) ) {
diff --git a/includes/Searcher.php b/includes/Searcher.php
index 48c3414..50bc190 100644
--- a/includes/Searcher.php
+++ b/includes/Searcher.php
@@ -301,7 +301,6 @@
$builderProfile = $this->config->get(
'CirrusSearchFullTextQueryBuilderProfile' );
$builderSettings = $this->config->getElement(
'CirrusSearchFullTextQueryBuilderProfiles', $builderProfile );
-
$qb = new $builderSettings['builder_class'](
$this->config,
$this->escaper,
diff --git a/tests/unit/LanguageDetectTest.php
b/tests/unit/LanguageDetectTest.php
index a84298b..ca38c1d 100644
--- a/tests/unit/LanguageDetectTest.php
+++ b/tests/unit/LanguageDetectTest.php
@@ -23,7 +23,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*/
-class LanguageDetectTest extends \PHPUnit_Framework_TestCase {
+class LanguageDetectTest extends \MediaWikiTestCase {
/**
* @var \CirrusSearch
@@ -45,6 +45,7 @@
}
public function setUp() {
+ parent::setUp();
$this->cirrus = new \CirrusSearch();
global $wgCirrusSearchTextcatModel;
if (empty( $wgCirrusSearchTextcatModel ) ) {
@@ -71,6 +72,33 @@
$detector = new TextCat();
$detect = $detector->detect($this->cirrus, "volviendose malo");
$this->assertEquals("en", $detect);
+ }
+
+ /**
+ * Simply test the searchTextReal $forceLocal boolean flag.
+ * Testing the full chain seems hard so we just test that
+ * the $forceLocal flag is running a search on the local
+ * wiki.
+ */
+ public function testLocalSearch() {
+ \RequestContext::getMain()->setRequest( new \FauxRequest( [
+ 'cirrusDumpQuery' => 1,
+ ] ) );
+ $this->setMwGlobals( [
+ 'wgCirrusSearchIndexBaseName' => 'mywiki',
+ 'wgCirrusSearchExtraIndexes' => [NS_FILE =>
['externalwiki_file']],
+ ] );
+ $cirrus = new MyCirrusSearch();
+ $cirrus->setNamespaces( [NS_FILE] );
+ $cirrus->setDumpAndDie( false );
+ $result = $cirrus->mySearchTextReal( 'hello', null, true );
+ $result = json_decode( $result, true );
+ $result = $result[0];
+ $this->assertEquals( 'mywiki_general/page/_search',
$result['path'] );
+ $result = $cirrus->mySearchTextReal( 'hello', null );
+ $result = json_decode( $result, true );
+ $result = $result[0];
+ $this->assertEquals(
'mywiki_general,externalwiki_file/page/_search', $result['path'] );
}
public function getHttpLangs() {
@@ -106,3 +134,12 @@
$this->httpLang = $http;
}
}
+
+/**
+ * Just a simple wrapper to access the protected method searchTextReal
+ */
+class MyCirrusSearch extends \CirrusSearch {
+ public function mySearchTextReal( $term, SearchConfig $config = null,
$forceLocal = false ) {
+ return $this->searchTextReal( $term, $config, $forceLocal );
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/314312
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaecabd70caa251172834ce824cde84de49cb5427
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: DCausse <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits