Claudiu Hardalau
Claudiu Hardalau

Reputation: 177

Bing cognitive search, actual site in url, not bing redirection

Is there a way that the result link to show the exact link, not the bing redirecting one?

For example ins there a way in bing cognitive search to put href the actual link instead of a redirection?

`"value": [
 {
     "id": "https://api.cognitive.microsoft.com/api/v5/#WebPages.0",
     "name": "<b>Burrito Recipes</b> - Allrecipes.com",
     "url": "http://www.bing.com/cr?IG=4BE4CA19570B4740ABE2B85782727544&CI......",
     "displayUrl": "all<b>recipes</b>.com/<b>recipes</b>/1216",
     "snippet": "<b>Burrito Recipes</b> ...",
     "deepLinks": [
         {
             "name": "Mexican",
             "url": "http://www.bing.com/cr?IG=4BE4CA19570B4740ABE2BF...",
             "snippet": "Mexican Recipes Find ..."
         }
      ]`

so the url to be the actual link?

Upvotes: 1

Views: 809

Answers (2)

Ruchit Modi
Ruchit Modi

Reputation: 23

You can use the 'r=' query parameter in the url to get the exact url where the redirection is pointed to. A sample bing url looks like this

"url": "http://www.bing.com/cr?IG=584DA9A5C8B245DDA12848B177BAF817&CID=138CDEBD227860443797D43D239D616C&rd=1&h=0UIFjW9hoNBrd0LFRhopxM1IDwbKCHvSc-z-FdLfyMQ&v=1&r=http%3a%2f%2fallrecipes.com%2frecipes%2f1216%2fworld-cuisine%2flatin-american%2fmexican%2fmain-dishes%2fburritos%2f&p=DevEx,5066.1"

Here,

r=http%3a%2f%2fallrecipes.com%2frecipes%2f1216%2fworld-cuisine%2flatin-american%2fmexican%2fmain-dishes%2fburritos%2f

Note that the url is encoded. Perform url decoding if required. All this can be done using the following Java code.

import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URIBuilder;
import org.apache.log4j.Logger;

import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public static String getExactUrl(String url) {
    Map<String, String> queryParams = getQueryParamsMap(url);
    return queryParams.getOrDefault("r", url);
}

public static Map<String, String> getQueryParamsMap(String url) {
    Map<String, String> queryParamsMap = new HashMap<>();
    try {
        URIBuilder uriBuilder = new URIBuilder(url);
        List<NameValuePair> queryParams = uriBuilder.getQueryParams();
        queryParamsMap = queryParams.stream().collect(Collectors.toMap(NameValuePair::getName, NameValuePair::getValue));
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    return queryParamsMap;
}

Upvotes: 1

malix
malix

Reputation: 3572

The only way we found is to just remove <b> and </b> from displayUrl...

Upvotes: 0

Related Questions