freearhey / wikidata

A PHP client for working with Wikidata API.
MIT License
54 stars 22 forks source link

wikipedia_article is completely bogus #18

Closed RemyNovactive closed 3 years ago

RemyNovactive commented 4 years ago

In the search function, a piece of code create an url 'wikipedia_article'.

$collection = $wikidata->search($keyword);

This url is the simple concatenation of the domain name and the label.

        $output = $collection->map(function ($item) use ($lang) {
            $item['wikipediaArticle'] = 'https://' . $lang . '.wikipedia.org/wiki/' . rawurlencode($item['label']);
            return new SearchResult($item, $lang);
        });

But the label does not contain the differentiation information between the different results. So, sometimes they all have the same URL...

image

freearhey commented 4 years ago

Thank you for noticing that! I'll see what I can do about it as soon as I have some free time.

RemyNovactive commented 4 years ago

I, for one, did this to get around the problem...

    public function autocomplete($keyword, $limit = 10) : Collection
    {
        $wikidata = new Wikidata();
        $collection = $wikidata->search($keyword, 'fr', $limit);
        return $collection->map(static function (SearchResult $item) {
            $item->wikipedia_article = 'http://www.wikidata.org/entity/' . $item->id;
            return $item;
        });
   }

composer.json : "freearhey/wikidata": "^3.5", (3.5.1)

Other than that, this bundle is great. Thanks :)

freearhey commented 3 years ago

I have just published an updated version of the package, hopefully this will finally solve this problem.