2012-08-11 72 views
1

我有一個應用程序使用Azure Datamarketplace中的新Bing API。我曾經能夠使用OR AND等簡單的語法來查詢Bing API。這似乎不適用於新的API。如何使用Bing Marketplace API形成複合查詢?

舊語法:

「傑克遜維爾美洲虎」或「NFL美洲虎」或「獵鷹」

這將使我在使用這些短語查詢(我正在爲新聞rt_Sports查詢) 。

我首先在查詢上調用HttpEncode,但是我仍然沒有得到結果。它的作品,如果我刪除所有的「標記,但後來我有時獲得有關獵鷹和美洲虎(動物)的消息的結果...不是我想要的。

任何人都有任何想法如何可以形成一個查詢需要多個短語?

我試過不使用OR,不使用',使用a',使用|而不是OR。所有這些都與BING網站相反,只是不在API中。

我剛剛通過Bing嘗試過,獲得了36萬次結果:

NFL Football |西雅圖海鷹隊紐約巨人|達拉斯牛仔|新奧爾良聖徒|新英格蘭愛國者|傑克遜維爾美洲虎

在API中同樣的事情返回0

我從一個朋友誰我也通過電子郵件發送這個問題出在電子郵件中,他的想法是,我要它錯了。應該有一種方法可以使用多個where子句來關閉Bing對象的LINQ查詢。

但我不明白怎麼可能。您允許BingSearchContainer,然後在容器上調用News方法。 News方法只有一個Query參數。

var bingContainer = new Bing.BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/Search")); 

bingContainer.Credentials = new NetworkCredential(App.BingAPIAccountKey, App.BingAPIAccountKey); 

string unifiedQuery = "NFL Football | Jacksonville Jaguars | Atlanta Falcons"; 

var newsQuery = bingContainer.News(unifiedQuery, null, "en-US", "Strict", null, null, null, "rt_Sports", "Relevance"); 

newsQuery.BeginExecute(BingNewsResultLoadedCallback, newsQuery); 

回答

1

嘗試改變unifiedQuery以下幾點:

var unifiedQuery = "'NFL Football' or 'Jacksonville Jaguars' or 'Atlanta Falcons'";

我試過很相似,示例代碼的東西,使用這種格式的查詢字符串,和它的工作對我來說:

var bingUri = new Uri("https://api.datamarket.azure.com/Bing/Search/v1/", UriKind.Absolute); 
var bingContainer = new BingSearchContainer(bingUri); 
bingContainer.Credentials = new NetworkCredential(BingAPIUserName, BingAPIAccountKey); 
var unifiedQuery = "'NFL Football' or 'Jacksonville Jaguars' or 'Atlanta Falcons'"; 

var newsQuery = bingContainer.News(unifiedQuery, null, "en-US", "Strict", null, null, null, "rt_Sports", "Relevance"); 

var results = newsQuery.Execute(); 
foreach (var item in results) 
{ 
    Console.WriteLine(item.Title); 
} 

以下是我的結果:

Fantasy Football 2012: Ranking the Top 25 RBs 
NFL Football No Longer Just a Sunday Game 
Ravens Notebook: Ed Reed decided to play in game vs. Falcons since he 'wasn't doing anything else' 
PrimeSport Partners with Jacksonville Jaguars to Offer Tickets and Official Fan 
Packages for all Home and Away Games in 2012 Season 
Jaguars cut former Ravens wide receiver Lee Evans 
Falcons left tackle Baker finally feels healthy 
Jaguars release veteran WR Lee Evans 
NFC West: 2012 NFL Training Camp 
Atlanta Falcons 2012 NFL TV Schedule 
Jaguars training camp: Veteran WR Lee Evans released 
Jaguars score 18 points in second half to beat Giants 32-31 
Jacksonville Jaguars put running back Maurice Jones-Drew on reserve/did not report list 
Postcard from camp: Falcons 
Questions abound as NFL preseason opens in earnest 
NFL fantasy football: Ryan Mathews loses value 

unifiedQuery字符串的格式基本上是OData URI查詢字符串格式。有關這些查詢字符串如何工作的完整說明,請查閱http://www.odata.org/documentation/uri-conventions處的OData URI約定文檔。

+0

這是一個我沒有嘗試過的排列......'或者' – 2012-08-16 21:37:34

+0

這不是總是如此嗎? :-)很高興我能夠幫助。 – 2012-08-17 06:22:03