/**
  * @param TermSearchResult $searchResult
  *
  * @return string HTML
  */
 public function getResultHtml(TermSearchResult $searchResult)
 {
     $idHtml = $this->getIdHtml($searchResult->getEntityId());
     $displayLabel = $searchResult->getDisplayLabel();
     $displayDescription = $searchResult->getDisplayDescription();
     $matchedTerm = $searchResult->getMatchedTerm();
     $labelHtml = $this->getLabelHtml($displayLabel);
     $descriptionHtml = $this->getDescriptionHtml($displayDescription);
     $matchHtml = $this->getMatchHtml($matchedTerm, $displayLabel);
     $result = $idHtml;
     if ($labelHtml !== '' || $descriptionHtml !== '' || $matchHtml !== '') {
         $result .= wfMessage('colon-separator')->escaped();
     }
     if ($labelHtml !== '') {
         $result .= $labelHtml;
     }
     if ($labelHtml !== '' && $descriptionHtml !== '') {
         $result .= wfMessage('comma-separator')->escaped();
     }
     if ($descriptionHtml !== '') {
         $result .= $descriptionHtml;
     }
     if ($matchHtml !== '') {
         $result .= $matchHtml;
     }
     $result = Html::rawElement('li', array('class' => 'wikibase-disambiguation'), $result);
     return $result;
 }
 /**
  * @dataProvider provideGoodConstruction
  */
 public function testGoodConstruction($matchedTerm, $matchedTermType, $entityId, $displayLabel, $displayDescription)
 {
     $result = new TermSearchResult($matchedTerm, $matchedTermType, $entityId, $displayLabel, $displayDescription);
     $this->assertEquals($matchedTerm, $result->getMatchedTerm());
     $this->assertEquals($matchedTermType, $result->getMatchedTermType());
     $this->assertEquals($entityId, $result->getEntityId());
     $this->assertEquals($displayLabel, $result->getDisplayLabel());
     $this->assertEquals($displayDescription, $result->getDisplayDescription());
 }
 /**
  * @param TermSearchResult $match
  *
  * @return array
  */
 private function buildTermSearchMatchEntry($match)
 {
     // TODO: use EntityInfoBuilder, EntityInfoTermLookup
     $title = $this->titleLookup->getTitleForId($match->getEntityId());
     $entry = array('id' => $match->getEntityId()->getSerialization(), 'concepturi' => $this->conceptBaseUri . $match->getEntityId()->getSerialization(), 'url' => $title->getFullUrl(), 'title' => $title->getPrefixedText(), 'pageid' => $title->getArticleID());
     $displayLabel = $match->getDisplayLabel();
     if (!is_null($displayLabel)) {
         $entry['label'] = $displayLabel->getText();
     }
     $displayDescription = $match->getDisplayDescription();
     if (!is_null($displayDescription)) {
         $entry['description'] = $displayDescription->getText();
     }
     $entry['match']['type'] = $match->getMatchedTermType();
     // Special handling for 'entityId's as these are not actually Term objects
     if ($entry['match']['type'] === 'entityId') {
         $entry['match']['text'] = $entry['id'];
         $entry['aliases'] = array($entry['id']);
     } else {
         $matchedTerm = $match->getMatchedTerm();
         $matchedTermText = $matchedTerm->getText();
         $entry['match']['language'] = $matchedTerm->getLanguageCode();
         $entry['match']['text'] = $matchedTermText;
         /**
          * Add matched terms to the aliases key in the result to give some context
          * for the matched Term if the matched term is different to the alias.
          * XXX: This appears odd but is used in the UI / Entity suggesters
          */
         if (!array_key_exists('label', $entry) || $matchedTermText != $entry['label']) {
             $entry['aliases'] = array($matchedTerm->getText());
         }
     }
     return $entry;
 }