jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/336911 )

Change subject: Add descriptions to ES index
......................................................................


Add descriptions to ES index

Descriptions follow the same pattern as labels, 'descriptions'
field includes per-language fields. Only one description per language.

NOTE: descriptions are stored in the index, but are not indexed or searched for 
now.

Bug: T125500
Change-Id: I459c619daf8f7e6c47c1a486428f0ca38f7c8faf
---
M repo/Wikibase.php
M repo/includes/Search/Elastic/ElasticTermResult.php
M repo/includes/Search/Elastic/EntitySearchElastic.php
M repo/includes/Search/Elastic/Fields/DescriptionProviderFieldDefinitions.php
A repo/includes/Search/Elastic/Fields/DescriptionsField.php
M repo/tests/phpunit/data/entitySearch/search_de-ch-en.expected
M repo/tests/phpunit/data/entitySearch/search_de-ch.expected
M repo/tests/phpunit/data/entitySearch/search_de-ch_strict.expected
M repo/tests/phpunit/data/entitySearch/search_en.expected
M repo/tests/phpunit/data/entitySearch/search_en_strict.expected
M repo/tests/phpunit/data/entitySearch/search_zh-de-ch.expected
M repo/tests/phpunit/data/entitySearch/search_zh.expected
M repo/tests/phpunit/includes/Search/Elastic/ElasticTermResultTest.php
M repo/tests/phpunit/includes/Search/Elastic/EntitySearchElasticTest.php
14 files changed, 155 insertions(+), 90 deletions(-)

Approvals:
  Daniel Kinzler: Looks good to me, approved
  EBernhardson: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/repo/Wikibase.php b/repo/Wikibase.php
index efef3c7..d8a0817 100644
--- a/repo/Wikibase.php
+++ b/repo/Wikibase.php
@@ -212,10 +212,6 @@
                                $entitySearchHelper = new 
Wikibase\Repo\Search\Elastic\EntitySearchElastic(
                                        
$repo->getLanguageFallbackChainFactory(),
                                        $repo->getEntityIdParser(),
-                                       new 
Wikibase\Lib\Store\LanguageFallbackLabelDescriptionLookup(
-                                               $repo->getTermLookup(),
-                                               
$repo->getLanguageFallbackChainFactory()->newFromLanguage( $lang )
-                                       ),
                                        $lang,
                                        $repo->getContentModelMappings(),
                                        $settings
diff --git a/repo/includes/Search/Elastic/ElasticTermResult.php 
b/repo/includes/Search/Elastic/ElasticTermResult.php
index cf9cf0b..6820915 100644
--- a/repo/includes/Search/Elastic/ElasticTermResult.php
+++ b/repo/includes/Search/Elastic/ElasticTermResult.php
@@ -6,7 +6,6 @@
 use CirrusSearch\Search\SearchContext;
 use Wikibase\DataModel\Entity\EntityIdParser;
 use Wikibase\DataModel\Entity\EntityIdParsingException;
-use Wikibase\DataModel\Services\Lookup\LabelDescriptionLookup;
 use Wikibase\DataModel\Term\Term;
 use Wikibase\LanguageFallbackChain;
 use Wikibase\Lib\Interactors\TermSearchResult;
@@ -16,11 +15,6 @@
  * a Wikibase entity by its label or alias.
  */
 class ElasticTermResult implements ResultsType {
-
-       /**
-        * @var LabelDescriptionLookup
-        */
-       private $labelDescriptionLookup;
 
        /**
         * @var EntityIdParser
@@ -35,13 +29,6 @@
        private $searchLanguageCodes;
 
        /**
-        * List of language codes in the display fallback chain, the first
-        * is the preferred language.
-        * @var string[]
-        */
-       private $displayLanguageCodes;
-
-       /**
         * Display fallback chain.
         * @var LanguageFallbackChain
         */
@@ -50,18 +37,15 @@
        /**
         * ElasticTermResult constructor.
         * @param EntityIdParser $idParser
-        * @param LabelDescriptionLookup $labelDescriptionLookup
         * @param string[] $searchLanguageCodes Language fallback chain for 
search
         * @param LanguageFallbackChain $displayFallbackChain Fallback chain 
for display
         */
        public function __construct( EntityIdParser $idParser,
-                                    LabelDescriptionLookup 
$labelDescriptionLookup,
                                     array $searchLanguageCodes,
                                     LanguageFallbackChain $displayFallbackChain
        ) {
                $this->idParser = $idParser;
                $this->searchLanguageCodes = $searchLanguageCodes;
-               $this->labelDescriptionLookup = $labelDescriptionLookup;
                $this->fallbackChain = $displayFallbackChain;
        }
 
@@ -74,6 +58,7 @@
                $fields = [ 'namespace', 'title' ];
                foreach ( $this->fallbackChain->getFetchLanguageCodes() as 
$code ) {
                        $fields[] = "labels.$code";
+                       $fields[] = "descriptions.$code";
                }
                return $fields;
        }
@@ -136,15 +121,29 @@
        /**
         * Locate label for display among the source data, basing on fallback 
chain.
         * @param array $sourceData
+        * @param string $field
         * @return null|Term
         */
-       private function findLabelForDisplay( $sourceData ) {
-               $labels_data = array_filter( array_map(
-                       function ( $data ) {
-                               return !empty( $data[0] ) ? $data[0] : null;
-                       },
-                       $sourceData['labels'] )
-               );
+       private function findTermForDisplay( $sourceData, $field ) {
+               if ( empty( $sourceData[$field] ) ) {
+                       return null;
+               }
+
+               $data = $sourceData[$field];
+               $first = reset( $data );
+               if ( is_array( $first ) ) {
+                       // If we have multiple, like for labels, extract the 
first one
+                       $labels_data = array_map(
+                               function ( $data ) {
+                                       return isset( $data[0] ) ? $data[0] : 
null;
+                               },
+                               $data
+                       );
+               } else {
+                       $labels_data = $data;
+               }
+               // Drop empty ones
+               $labels_data = array_filter( $labels_data );
 
                $preferredValue = 
$this->fallbackChain->extractPreferredValueOrAny( $labels_data );
                if ( $preferredValue ) {
@@ -174,7 +173,8 @@
                        // Highlight part contains information about what has 
actually been matched.
                        $highlight = $r->getHighlights();
                        $matchedTermType = 'label';
-                       $displayLabel = $this->findLabelForDisplay( $sourceData 
);
+                       $displayLabel = $this->findTermForDisplay( $sourceData, 
'labels' );
+                       $displayDescription = $this->findTermForDisplay( 
$sourceData, 'descriptions' );
 
                        if ( !empty( $highlight['title'] ) ) {
                                // If we matched title, this means it's a match 
by ID
@@ -210,8 +210,6 @@
                                // This should not happen, but just in case, 
it's better to return something
                                $displayLabel = $matchedTerm;
                        }
-                       // TODO: eventually this will be fetched from ES.
-                       $displayDescription = 
$this->labelDescriptionLookup->getDescription( $entityId );
 
                        $results[$entityId->getSerialization()] = new 
TermSearchResult(
                                $matchedTerm, $matchedTermType, $entityId, 
$displayLabel,
diff --git a/repo/includes/Search/Elastic/EntitySearchElastic.php 
b/repo/includes/Search/Elastic/EntitySearchElastic.php
index baef696..bfa6a20 100644
--- a/repo/includes/Search/Elastic/EntitySearchElastic.php
+++ b/repo/includes/Search/Elastic/EntitySearchElastic.php
@@ -13,7 +13,6 @@
 use Status;
 use WebRequest;
 use Wikibase\DataModel\Entity\EntityIdParser;
-use Wikibase\DataModel\Services\Lookup\LabelDescriptionLookup;
 use Wikibase\LanguageFallbackChainFactory;
 use Wikibase\Lib\Interactors\TermSearchResult;
 use Wikibase\Repo\Api\EntitySearchHelper;
@@ -33,11 +32,6 @@
         * @var LanguageFallbackChainFactory
         */
        private $languageChainFactory;
-
-       /**
-        * @var LabelDescriptionLookup
-        */
-       private $labelDescriptionLookup;
 
        /**
         * @var EntityIdParser
@@ -83,7 +77,6 @@
        /**
         * @param LanguageFallbackChainFactory $languageChainFactory
         * @param EntityIdParser $idParser
-        * @param LabelDescriptionLookup $labelDescriptionLookup
         * @param Language $userLang
         * @param array $contentModelMap Maps entity type => content model name
         * @param array $settings Search settings, see Wikibase.default.php 
under 'entitySearch'
@@ -91,14 +84,12 @@
        public function __construct(
                LanguageFallbackChainFactory $languageChainFactory,
                EntityIdParser $idParser,
-               LabelDescriptionLookup $labelDescriptionLookup,
                Language $userLang,
                array $contentModelMap,
                array $settings
        ) {
                $this->languageChainFactory = $languageChainFactory;
                $this->idParser = $idParser;
-               $this->labelDescriptionLookup = $labelDescriptionLookup;
                $this->contentModelMap = $contentModelMap;
                $this->settings = $settings;
                $this->userLang = $userLang;
@@ -248,7 +239,6 @@
 
                $searcher->setResultsType( new ElasticTermResult(
                        $this->idParser,
-                       $this->labelDescriptionLookup,
                        $this->searchLanguageCodes,
                        $this->languageChainFactory->newFromLanguage( 
$this->userLang )
                ) );
diff --git 
a/repo/includes/Search/Elastic/Fields/DescriptionProviderFieldDefinitions.php 
b/repo/includes/Search/Elastic/Fields/DescriptionProviderFieldDefinitions.php
index 6d07ed2..6df0bb5 100644
--- 
a/repo/includes/Search/Elastic/Fields/DescriptionProviderFieldDefinitions.php
+++ 
b/repo/includes/Search/Elastic/Fields/DescriptionProviderFieldDefinitions.php
@@ -25,7 +25,7 @@
        public function getFields() {
                $fields = [];
 
-               // TODO: nothing for now, will add later
+               $fields['descriptions'] = new DescriptionsField( 
$this->languageCodes );
 
                return $fields;
        }
diff --git a/repo/includes/Search/Elastic/Fields/DescriptionsField.php 
b/repo/includes/Search/Elastic/Fields/DescriptionsField.php
new file mode 100644
index 0000000..f42d5d2
--- /dev/null
+++ b/repo/includes/Search/Elastic/Fields/DescriptionsField.php
@@ -0,0 +1,55 @@
+<?php
+namespace Wikibase\Repo\Search\Elastic\Fields;
+
+use SearchEngine;
+use SearchIndexFieldDefinition;
+use Wikibase\DataModel\Entity\EntityDocument;
+use Wikibase\DataModel\Term\DescriptionsProvider;
+
+/**
+ * Field which contains per-language specific descriptions.
+ */
+class DescriptionsField implements WikibaseIndexField {
+
+       /**
+        * List of available languages
+        * @var string[]
+        */
+       private $languages;
+
+       /**
+        * DescriptionsField constructor.
+        * @param string[] $languages Available languages list.
+        */
+       public function __construct( array $languages ) {
+               $this->languages = $languages;
+       }
+
+       /**
+        * @param SearchEngine $engine
+        * @param string $name
+        * @return null|\SearchIndexField
+        */
+       public function getMappingField( SearchEngine $engine, $name ) {
+               // TODO: no mapping for now, since we're only storing it for 
retrieval
+               // When we start indexing it, we'll need to figure out how to 
add proper analyzers
+               return null;
+       }
+
+       /**
+        * @param EntityDocument $entity
+        *
+        * @return string[] Array of descriptions in available languages.
+        */
+       public function getFieldData( EntityDocument $entity ) {
+               if ( !( $entity instanceof DescriptionsProvider ) ) {
+                       return [];
+               }
+               $data = [];
+               foreach ( $entity->getDescriptions() as $language => $desc ) {
+                       $data[$language] = $desc->getText();
+               }
+               return $data;
+       }
+
+}
diff --git a/repo/tests/phpunit/data/entitySearch/search_de-ch-en.expected 
b/repo/tests/phpunit/data/entitySearch/search_de-ch-en.expected
index fc5fa92..f458654 100644
--- a/repo/tests/phpunit/data/entitySearch/search_de-ch-en.expected
+++ b/repo/tests/phpunit/data/entitySearch/search_de-ch-en.expected
@@ -58,7 +58,8 @@
         "_source": [
             "namespace",
             "title",
-            "labels.en"
+            "labels.en",
+            "descriptions.en"
         ],
         "stored_fields": [],
         "highlight": {
diff --git a/repo/tests/phpunit/data/entitySearch/search_de-ch.expected 
b/repo/tests/phpunit/data/entitySearch/search_de-ch.expected
index 81ff37a..4b15d63 100644
--- a/repo/tests/phpunit/data/entitySearch/search_de-ch.expected
+++ b/repo/tests/phpunit/data/entitySearch/search_de-ch.expected
@@ -59,8 +59,11 @@
             "namespace",
             "title",
             "labels.de-ch",
+            "descriptions.de-ch",
             "labels.de",
-            "labels.en"
+            "descriptions.de",
+            "labels.en",
+            "descriptions.en"
         ],
         "stored_fields": [],
         "highlight": {
diff --git a/repo/tests/phpunit/data/entitySearch/search_de-ch_strict.expected 
b/repo/tests/phpunit/data/entitySearch/search_de-ch_strict.expected
index e20bdf2..2904cb2 100644
--- a/repo/tests/phpunit/data/entitySearch/search_de-ch_strict.expected
+++ b/repo/tests/phpunit/data/entitySearch/search_de-ch_strict.expected
@@ -52,8 +52,11 @@
             "namespace",
             "title",
             "labels.de-ch",
+            "descriptions.de-ch",
             "labels.de",
-            "labels.en"
+            "descriptions.de",
+            "labels.en",
+            "descriptions.en"
         ],
         "stored_fields": [],
         "highlight": {
diff --git a/repo/tests/phpunit/data/entitySearch/search_en.expected 
b/repo/tests/phpunit/data/entitySearch/search_en.expected
index 51afe02..3eddbce 100644
--- a/repo/tests/phpunit/data/entitySearch/search_en.expected
+++ b/repo/tests/phpunit/data/entitySearch/search_en.expected
@@ -52,7 +52,8 @@
         "_source": [
             "namespace",
             "title",
-            "labels.en"
+            "labels.en",
+            "descriptions.en"
         ],
         "stored_fields": [],
         "highlight": {
diff --git a/repo/tests/phpunit/data/entitySearch/search_en_strict.expected 
b/repo/tests/phpunit/data/entitySearch/search_en_strict.expected
index 8981b16..c559aea 100644
--- a/repo/tests/phpunit/data/entitySearch/search_en_strict.expected
+++ b/repo/tests/phpunit/data/entitySearch/search_en_strict.expected
@@ -51,7 +51,8 @@
         "_source": [
             "namespace",
             "title",
-            "labels.en"
+            "labels.en",
+            "descriptions.en"
         ],
         "stored_fields": [],
         "highlight": {
diff --git a/repo/tests/phpunit/data/entitySearch/search_zh-de-ch.expected 
b/repo/tests/phpunit/data/entitySearch/search_zh-de-ch.expected
index 7c36a6d..107549b 100644
--- a/repo/tests/phpunit/data/entitySearch/search_zh-de-ch.expected
+++ b/repo/tests/phpunit/data/entitySearch/search_zh-de-ch.expected
@@ -80,8 +80,11 @@
             "namespace",
             "title",
             "labels.de-ch",
+            "descriptions.de-ch",
             "labels.de",
-            "labels.en"
+            "descriptions.de",
+            "labels.en",
+            "descriptions.en"
         ],
         "stored_fields": [],
         "highlight": {
diff --git a/repo/tests/phpunit/data/entitySearch/search_zh.expected 
b/repo/tests/phpunit/data/entitySearch/search_zh.expected
index 29b3aba..4dcd008 100644
--- a/repo/tests/phpunit/data/entitySearch/search_zh.expected
+++ b/repo/tests/phpunit/data/entitySearch/search_zh.expected
@@ -80,15 +80,25 @@
             "namespace",
             "title",
             "labels.zh",
+            "descriptions.zh",
             "labels.zh-hans",
+            "descriptions.zh-hans",
             "labels.zh-hant",
+            "descriptions.zh-hant",
             "labels.zh-cn",
+            "descriptions.zh-cn",
             "labels.zh-tw",
+            "descriptions.zh-tw",
             "labels.zh-hk",
+            "descriptions.zh-hk",
             "labels.zh-sg",
+            "descriptions.zh-sg",
             "labels.zh-mo",
+            "descriptions.zh-mo",
             "labels.zh-my",
-            "labels.en"
+            "descriptions.zh-my",
+            "labels.en",
+            "descriptions.en"
         ],
         "stored_fields": [],
         "highlight": {
diff --git 
a/repo/tests/phpunit/includes/Search/Elastic/ElasticTermResultTest.php 
b/repo/tests/phpunit/includes/Search/Elastic/ElasticTermResultTest.php
index e5667dc..8342415 100644
--- a/repo/tests/phpunit/includes/Search/Elastic/ElasticTermResultTest.php
+++ b/repo/tests/phpunit/includes/Search/Elastic/ElasticTermResultTest.php
@@ -7,7 +7,6 @@
 use Elastica\ResultSet;
 use MediaWikiTestCase;
 use Wikibase\DataModel\Entity\BasicEntityIdParser;
-use Wikibase\DataModel\Services\Lookup\LabelDescriptionLookup;
 use Wikibase\DataModel\Term\Term;
 use Wikibase\LanguageFallbackChain;
 use Wikibase\Repo\Search\Elastic\ElasticTermResult;
@@ -26,13 +25,15 @@
                                [
                                        '_source' => [
                                                'title' => 'Q1',
-                                               'labels' => [ 'en' => [ 'Test 
1', 'Test 1 alias' ] ]
+                                               'labels' => [ 'en' => [ 'Test 
1', 'Test 1 alias' ] ],
+                                               'descriptions' => [ 'en' => 
'Describe it' ],
                                        ],
                                        'highlight' => [ 'labels.en.prefix' => 
[ 'Test 1' ] ]
                                ],
                                [
                                        'id' => 'Q1',
                                        'label' => [ 'en', 'Test 1' ],
+                                       'description' => [ 'en', 'Describe it' 
],
                                        'matched' => [ 'en', 'Test 1' ],
                                        'matchedType' => 'label'
                                ]
@@ -43,13 +44,15 @@
                                [
                                        '_source' => [
                                                'title' => 'Q2',
-                                               'labels' => [ 'en' => [ 'Test 
1', 'Alias', 'Another' ] ]
+                                               'labels' => [ 'en' => [ 'Test 
1', 'Alias', 'Another' ] ],
+                                               'descriptions' => [ 'en' => 
'Describe it' ],
                                        ],
                                        'highlight' => [ 'labels.en.prefix' => 
[ 'Another' ] ]
                                ],
                                [
                                        'id' => 'Q2',
                                        'label' => [ 'en', 'Test 1' ],
+                                       'description' => [ 'en', 'Describe it' 
],
                                        'matched' => [ 'en', 'Another' ],
                                        'matchedType' => 'alias'
                                ]
@@ -60,13 +63,15 @@
                                [
                                        '_source' => [
                                                'title' => 'Q10',
-                                               'labels' => [ 'en' => [ 'Test 
1', 'Alias', 'Another' ] ]
+                                               'labels' => [ 'en' => [ 'Test 
1', 'Alias', 'Another' ] ],
+                                               'descriptions' => [ 'en' => 
'Describe it' ],
                                        ],
                                        'highlight' => [ 'title' => [ 'Q10' ] ]
                                ],
                                [
                                        'id' => 'Q10',
                                        'label' => [ 'en', 'Test 1' ],
+                                       'description' => [ 'en', 'Describe it' 
],
                                        'matched' => [ 'qid', 'Q10' ],
                                        'matchedType' => 'entityId'
                                ]
@@ -80,12 +85,14 @@
                                                'labels' => [ 'en' => [ 'Test 
1', 'Test 1 alias' ],
                                                                          'ru' 
=> [ 'Тест 1', 'Тили тили тест' ]
                                                                        ],
+                                               'descriptions' => [ 'en' => 
'Describe it' ],
                                        ],
                                        'highlight' => [ 'labels.ru.prefix' => 
[ 'Тест 1' ] ]
                                ],
                                [
                                        'id' => 'Q3',
                                        'label' => [ 'en', 'Test 1' ],
+                                       'description' => [ 'en', 'Describe it' 
],
                                        'matched' => [ 'ru', 'Тест 1' ],
                                        'matchedType' => 'label'
                                ]
@@ -97,12 +104,33 @@
                                        '_source' => [
                                                'title' => 'Q3',
                                                'labels' => [ 'ru' => [ 'Тест 
1', 'Тили тили тест' ] ],
+                                               'descriptions' => [ 'en' => 
'Describe it' ],
                                        ],
                                        'highlight' => [ 'labels.en.prefix' => 
[ 'Test 1' ] ]
                                ],
                                [
                                        'id' => 'Q3',
                                        'label' => [ 'ru', 'Тест 1' ],
+                                       'description' => [ 'en', 'Describe it' 
],
+                                       'matched' => [ 'en', 'Test 1' ],
+                                       'matchedType' => 'label'
+                               ],
+                       ],
+                       'fallback description' => [
+                               [ 'en', 'ru' ],
+                               [ 'en', 'ru' ],
+                               [
+                                       '_source' => [
+                                               'title' => 'Q3',
+                                               'labels' => [ 'ru' => [ 'Тест 
1', 'Тили тили тест' ] ],
+                                               'descriptions' => [ 'ru' => 
'Описание' ],
+                                       ],
+                                       'highlight' => [ 'labels.en.prefix' => 
[ 'Test 1' ] ]
+                               ],
+                               [
+                                       'id' => 'Q3',
+                                       'label' => [ 'ru', 'Тест 1' ],
+                                       'description' => [ 'ru', 'Описание' ],
                                        'matched' => [ 'en', 'Test 1' ],
                                        'matchedType' => 'label'
                                ],
@@ -117,12 +145,14 @@
                                                        'de' => [ 'Der Test 1', 
'Test 2' ],
                                                        'de-ch' => [ '', 'Test 
2' ]
                                                ],
+                                               'descriptions' => [ 'en' => 
'Describe it' ],
                                        ],
                                        'highlight' => [ 'labels.de-ch.prefix' 
=> [ 'Test 2' ] ]
                                ],
                                [
                                        'id' => 'Q6',
                                        'label' => [ 'de', 'Der Test 1' ],
+                                       'description' => [ 'en', 'Describe it' 
],
                                        'matched' => [ 'de-ch', 'Test 2' ],
                                        'matchedType' => 'alias'
                                ],
@@ -138,12 +168,14 @@
                                                        'en' => [ 'Test 1', 
'Test 3' ],
                                                        'de-ch' => [ '', 'Test 
2' ]
                                                ],
+                                               'descriptions' => [ 'en' => 
'Describe it' ],
                                        ],
                                        'highlight' => [ 'labels.de-ch.prefix' 
=> [ 'Test 2' ] ]
                                ],
                                [
                                        'id' => 'Q8',
                                        'label' => [ 'en', 'Test 1' ],
+                                       'description' => [ 'en', 'Describe it' 
],
                                        'matched' => [ 'de-ch', 'Test 2' ],
                                        'matchedType' => 'alias'
                                ],
@@ -172,21 +204,6 @@
                ];
        }
 
-       /**
-        * Get a lookup that always returns a pt label and description suffixed 
by the entity ID
-        *
-        * @return LabelDescriptionLookup
-        */
-       private function getMockLabelDescriptionLookup() {
-               $mock = $this->getMockBuilder( LabelDescriptionLookup::class )
-                       ->disableOriginalConstructor()
-                       ->getMock();
-               $mock->expects( $this->any() )
-                       ->method( 'getDescription' )
-                       ->will( $this->returnValue( new Term( 'en', 
'DESCRIPTION' ) ) );
-               return $mock;
-       }
-
        private function getMockFallbackChain( $languages ) {
                $mock = $this->getMockBuilder( LanguageFallbackChain::class )
                                ->disableOriginalConstructor()
@@ -194,7 +211,7 @@
                $mock->expects( $this->any() )
                        ->method( 'getFetchLanguageCodes' )
                        ->will( $this->returnValue( $languages ) );
-               $mock->expects( $this->once() )
+               $mock->expects( $this->atLeastOnce() )
                        ->method( 'extractPreferredValueOrAny' )
                        ->will( $this->returnCallback( function ( $sourceData ) 
use ( $languages ) {
                                foreach ( $languages as $language ) {
@@ -217,7 +234,6 @@
        public function testTransformResult( $languages, $displayLanguages, 
$resultData, $expected ) {
                $res = new ElasticTermResult(
                        new BasicEntityIdParser(),
-                       $this->getMockLabelDescriptionLookup(),
                        $languages,
                        $this->getMockFallbackChain( $displayLanguages )
                );
@@ -246,9 +262,15 @@
 
                $this->assertEquals( $expected['matchedType'], 
$converted->getMatchedTermType(), 'Match type is wrong' );
 
-               // TODO: this will be fixed when descriptions are indexed too
-               $this->assertEquals( 'DESCRIPTION', 
$converted->getDisplayDescription()->getText() );
-               $this->assertEquals( 'en', 
$converted->getDisplayDescription()->getLanguageCode() );
+               if ( !empty( $expected['description'] ) ) {
+                       $this->assertEquals( $expected['description'][0],
+                               
$converted->getDisplayDescription()->getLanguageCode(),
+                               'Description language is wrong' );
+                       $this->assertEquals( $expected['description'][1],
+                               $converted->getDisplayDescription()->getText(), 
'Description text is wrong' );
+               } else {
+                       $this->assertNull( $converted->getDisplayDescription() 
);
+               }
        }
 
 }
diff --git 
a/repo/tests/phpunit/includes/Search/Elastic/EntitySearchElasticTest.php 
b/repo/tests/phpunit/includes/Search/Elastic/EntitySearchElasticTest.php
index dd40328..2cecafe 100644
--- a/repo/tests/phpunit/includes/Search/Elastic/EntitySearchElasticTest.php
+++ b/repo/tests/phpunit/includes/Search/Elastic/EntitySearchElasticTest.php
@@ -5,8 +5,6 @@
 use Language;
 use MediaWikiTestCase;
 use Wikibase\DataModel\Entity\BasicEntityIdParser;
-use Wikibase\DataModel\Services\Lookup\LabelDescriptionLookup;
-use Wikibase\DataModel\Term\Term;
 use Wikibase\Repo\Search\Elastic\EntitySearchElastic;
 
 /**
@@ -23,21 +21,6 @@
        }
 
        /**
-        * Get a lookup that always returns a fixed label and description
-        *
-        * @return LabelDescriptionLookup
-        */
-       private function getMockLabelDescriptionLookup() {
-               $mock = $this->getMockBuilder( LabelDescriptionLookup::class )
-                               ->disableOriginalConstructor()
-                               ->getMock();
-               $mock->expects( $this->any() )
-                       ->method( 'getDescription' )
-                       ->will( $this->returnValue( new Term( 'en', 
'DESCRIPTION' ) ) );
-               return $mock;
-       }
-
-       /**
         * @param Language $userLang
         * @return EntitySearchElastic
         */
@@ -47,7 +30,6 @@
                return new EntitySearchElastic(
                        $repo->getLanguageFallbackChainFactory(),
                        new BasicEntityIdParser(),
-                       $this->getMockLabelDescriptionLookup(),
                        $userLang,
                        $repo->getContentModelMappings(),
                        $repo->getSettings()->getSetting( 'entitySearch' )

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I459c619daf8f7e6c47c1a486428f0ca38f7c8faf
Gerrit-PatchSet: 33
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Smalyshev <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: DCausse <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: EBernhardson <[email protected]>
Gerrit-Reviewer: Smalyshev <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to