私は妊娠中のサービスからの文書にbingカスタム検索APIを使用しようとしています。奇妙なことは、私がインドの場所から実行すると、それは私に1000以上の結果を与えますが、私はそれを米国のサーバーから実行すると、それはわずか25(時には50の結果)を返します。ここでは、そのサンプルコード:Bingカスタム検索APIは、1つの場所からの限定的な結果と異なる場所からの完全な結果を返します。
var totalCount = 0;
var filetypes = new List<string> { "pdf", "docx", "doc" };
foreach (var filetype in filetypes)
{
var searchTerm = "microsoft%20.net%20resume+filetype%3a" + filetype;
Console.WriteLine("Searching for : " + filetype);
for (var i = 0; i < 40; i++)
{
var nextCount = 0;
var url = "https://api.cognitive.microsoft.com/bingcustomsearch/v7.0/search?" +
"q=" + searchTerm +
"&customconfig=" + customConfigId +
"&count=25" + "&offset=" + ((i * 25) + nextCount);
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey);
var httpResponseMessage = client.GetAsync(url).Result;
var responseContent = httpResponseMessage.Content.ReadAsStringAsync().Result;
BingCustomSearchResponse response =
JsonConvert.DeserializeObject<BingCustomSearchResponse>(responseContent);
if (response.webPages == null || response.webPages.value.Length <= 0)
{
Console.WriteLine("response.webPages is null ");
break;
}
foreach (var webPage in response.webPages.value)
{
Console.WriteLine("name: " + webPage.name);
Console.WriteLine("url: " + webPage.url);
Console.WriteLine("displayUrl: " + webPage.displayUrl);
Console.WriteLine("snippet: " + webPage.snippet);
Console.WriteLine("dateLastCrawled: " + webPage.dateLastCrawled);
Console.WriteLine();
}
totalCount = totalCount + response.webPages.value.Length;
}
}
}
サブスクリプションキーは、試用キーです。
レート制限は、有料のサブスクリプションだけでなく、試用キーにも適用されます。有料購読のTPSは、https://azure.microsoft.com/en-us/pricing/details/cognitive-services/search-api/web/で確認できます。カスタム検索の場合、空きキーは1 TPSです。待ち時間が問題であるかどうかを確認するために、呼び出しの間にある程度のアイドル時間を置くことができます。 – Ronak