gabics
gabics

Reputation: 250

Microsoft Cognitive Services News Search result URLs

I am trying to migrate from Bing search API v2 to the new Cognitive Search API v5. I am able to connect and execute a news search. But in the results I cant seem to get any of the search result URLs (target sites) like "url" = "http://somewebsite/newsarticle" instead I get results like: "url": "http://www.bing.com/cr?IG=A5F6CFB521CE442EB8ADC2B9DAD61C9F&CID=0EC3F0C" ....

Microsoft documentation states I should be getting the real target url: See the line "url": "http://tech.firstpost.com/news-analy..." in the api documentation : https://dev.cognitive.microsoft.com/docs/services/56b43f72cf5ff8098cef380a/operations/56b449fbcf5ff81038d15cdf

But when I open the test console on the same page it gives me the "http://www.bing.com/cr?IG=A5F6..." results.

What am I missing? Thanks for your help.

Upvotes: 1

Views: 192

Answers (2)

Rob Truxal
Rob Truxal

Reputation: 6408

Bing now encodes their return links for news and websearch. You'll only get display URLs in plaintext. That said, the encoded URL responses do contain all the elements of the plaintext URLs they refer to.

For this reason, if you need plaintext URLs, the best option is almost always to parse the encoded URLs as gabics suggested.

Upvotes: 0

gabics
gabics

Reputation: 250

I figured out a workaround. Does not seem ideal, but forks for now. Wrote a method that parses the target URL from the Bing URL:

url = TryGetUrlFromBingUrl(BingResultUrl);



private string TryGetUrlFromBingUrl(string BingURL)
{
    var queryString = HttpUtility.ParseQueryString(BingURL);
    if (!string.IsNullOrEmpty(queryString["r"]))
    {
        return queryString["r"];
    } else
    {
        return BingURL;
    }
}

Upvotes: 0

Related Questions