【问题标题】:Microsoft.Azure.CognitiveServices.Search.EntitySearch.EntitySearchClient.Entities.Search(location: <latitude>:? <longitude>:?Microsoft.Azure.CognitiveServices.Search.EntitySearch.EntitySearchClient.Entities.Search(位置:<latitude>:?<longitude>:?
【发布时间】:2019-04-09 19:36:33
【问题描述】:

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

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 restaurant = client.Entities.Search(query: currentQuery, location: lat:?long:?);

【问题讨论】:

    标签: search entity bing


    【解决方案1】:

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

    public static void 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);
    }
    

    }

    【讨论】:

      猜你喜欢
      • 2011-08-27
      • 1970-01-01
      • 2016-03-06
      • 2018-04-02
      • 2020-04-07
      • 2015-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多