Microsoft.Azure.CognitiveServices.Search.EntitySearch.EntitySearchClient.Entities.Search(位置:<纬度> :? <经度> :?

时间:2019-04-09 19:36:34

标签: search entity bing

我正在使用SDK和(不是REST API)运行Microsoft必应实体搜索示例,但根据此文档,我无法弄清楚如何输入位置键/值对:

https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.cognitiveservices.search.entitysearch.entitiesoperationsextensions.search?f1url=https%3A%2F%2Fmsdn.microsoft.com%2Fquery%2Fdev15.query%3FappId%3DDev15IDEF1%26l%3DEN-US%26k%3Dk(Microsoft.Azure.CognitiveServices.Search.EntitySearch.EntitiesOperationsExtensions.Search);k(TargetFrameworkMoniker-.NETFramework,Version%3Dv4.7.2);k(DevLang-csharp)%26rd%3Dtrue&view=azure-dotnet

我想继续使用命名参数,所以我仍然可以这样做: var Restaurants = client.Entities.Search(query:currentQuery,location:lat :? long:?);

1 个答案:

答案 0 :(得分:0)

带有Microsoft示例的查询和位置的方法如下所示:

公共静态无效的MultipleCurrentQueryLookup(string subscriptionKey) {     var client = new EntitySearchClient(new ApiKeyServiceClientCredentials subscriptionKey));

try
{
    string currentQuery = Settings1.Default.CurrentQuery;
    var restaurants = client.Entities.Search(query: currentQuery, 
         location: "lat:47.623, long:-122.361, re:380m");

    if (restaurants?.Places?.Value?.Count > 0)
    {
        // get all the list items that relate to this query
        var listItems = restaurants.Places.Value.Where(thing => thing.EntityPresentationInfo.EntityScenario == EntityScenario.ListItem).ToList();

        if (listItems?.Count > 0)
        {
            var sb = new StringBuilder();

            foreach (var item in listItems)
            {
                var place = item as Place;

                if (place == null)
                {
                    Console.WriteLine("Unexpectedly found something that isn't a place named \"{0}\"", item.Name);
                    continue;
                }

                sb.AppendFormat(",{0} ({1}) {2}", place.Name, place.Telephone, place.Url);
            }

            Console.WriteLine("Ok, we found these places: ");
            Console.WriteLine(sb.ToString().Substring(1));
        }
        else
        {
            Console.WriteLine("Couldn't find any relevant results for \"The Current Query\"");
        }
    }
    else
    {
        Console.WriteLine("Didn't see any data..");
    }
}
catch (ErrorResponseException ex)
{
    Console.WriteLine("Encountered exception. " + ex.Message);
}

}