Skip to content

Commit

Permalink
Take entity label, description and aliases from wbgetentities response
Browse files Browse the repository at this point in the history
  • Loading branch information
freearhey committed Dec 20, 2020
1 parent d60cb2a commit 8c96d40
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/Wikidata.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,11 @@ public function search($query, $lang = 'en', $limit = 10)

$ids = $collection->pluck('id')->toArray();

$entities = $client->getEntities($ids, $lang, ['sitelinks/urls']);

$output = $collection->map(function ($item) use ($entities, $lang) {
$entity = $entities->get($item['id']);
if (isset($entity)) {
$site = $lang . 'wiki';
$item['wiki_url'] = isset($entity['sitelinks'][$site]) ? $entity['sitelinks'][$site]['url'] : null;
}
$entities = $client->getEntities($ids, $lang, ['sitelinks/urls', 'aliases', 'descriptions', 'labels']);

return new SearchResult($item, $lang);
$output = $entities->map(function ($item) use ($lang) {
$entity = new Entity($item, $lang);
return new SearchResult($entity->toArray(), $lang);
});

return $output;
Expand Down Expand Up @@ -84,7 +79,6 @@ public function searchBy($property, $value = null, $lang = 'en', $limit = 10)

$output = $entities->map(function ($data) use ($lang) {
$entity = new Entity($data, $lang);

return new SearchResult($entity->toArray(), $lang);
});

Expand Down

0 comments on commit 8c96d40

Please sign in to comment.