次の方法で共有


MSNSearchService.Search メソッド (Search)

Live Search エンジンに検索要求を送信します。

構文

public SearchResponse Search (SearchRequest Request)

解説

MSNSearchService オブジェクトは、MSNSearchService.Search メソッドへの入力パラメータとして SearchRequest オブジェクトを 1 つ受け付けます。各 SearchRequest オブジェクトには、複数の SourceRequest オブジェクトを格納することができます。Search メソッドは、Live Search エンジンへの呼び出しごとに、1 つの SearchRequest オブジェクトを送信し、1 つの SearchResponse を返しますが、これには、要求のソースごとに 1 つの SourceResponse オブジェクトが含まれます。

非同期検索メソッドもサポートされています。各非同期メソッドのペアまたはセットに関連付けられるメソッド名は、WSDL の処理に使用される SOAP Toolkit とプロキシ ジェネレータによって生成されます。

たとえば、Microsoft Visual Studio 2003 で生成される非同期検索メソッドは、BeginSearchEndSearch です。Microsoft Visual Studio 2005 で生成される非同期検索メソッドには、SearchAsync メソッドの SearchAsync(SearchRequest)SearchAsync(SearchRequest, Object)CancelAsync メソッド、SearchCompleted イベント、および SearchCompletedEventHandler デリゲートがあります。

この例では、既定のパラメータを使用して Web 検索を実行し、その情報をコンソール ウィンドウに表示します。下記では、MSNSearchService オブジェクトと Search メソッド呼び出しを太字で示しています。

try
{
    MSNSearchService s = new MSNSearchService();
SearchRequest searchRequest = new SearchRequest();
int arraySize = 1;
SourceRequest[] sr = new SourceRequest[arraySize];

sr[0] = new SourceRequest();
sr[0].Source = SourceType.Web;

searchRequest.Query = "Live Search";
searchRequest.Requests = sr;
// Developer Provisioning System で指定されたアプリケーション ID を 二重引用符で囲って 
// SearchRequest の AppID の値として入力します。
searchRequest.AppID = "YOUR_APP_ID_GOES_HERE";
searchRequest.CultureInfo = "en-US";
SearchResponse searchResponse;

    searchResponse = s.Search(searchRequest);

foreach (SourceResponse sourceResponse in searchResponse.Responses)
    {
Result[] sourceResults = sourceResponse.Results;
if (sourceResponse.Total > 0)
        {
Console.WriteLine(sourceResponse.Source.ToString() + " - 結果総数:" + sourceResponse.Total.ToString());
Console.WriteLine();
        }
foreach (Result sourceResult in sourceResults)
        {
if ((sourceResult.Title != null) && (sourceResult.Title != String.Empty))
Console.WriteLine("タイトル:" + sourceResult.Title);
if ((sourceResult.Description != null) && (sourceResult.Description != String.Empty))
Console.WriteLine("説明:" + sourceResult.Description);
if ((sourceResult.Url != null) && (sourceResult.Url != String.Empty))
Console.WriteLine("URL:" + sourceResult.Url);
Console.WriteLine("*****************************************************");
        }
    }
Console.WriteLine("終了するにはいずれかのキーを押してください。");
Console.ReadLine();
}
catch (SoapException fault)
{
Console.WriteLine(fault.Detail.InnerText.ToString());
Console.WriteLine("終了するにはいずれかのキーを押してください。");
Console.ReadLine();
}
catch (WebException webx)
{
Console.WriteLine(webx.ToString());
}

以下の出力の例は、このクエリの結果を示します。

Web - 結果総数: 64272757

タイトル:Live Search

説明:Next generation search engine and customizable web portal with news, high-def maps with live traffic, classifieds, and more.

URL:http://www.live.com/

*****************************************************

タイトル:Live Search

説明:Type search term Search ...

URL:http://www.live.com/?scope=maps

*****************************************************

タイトル:Live Local Search

説明:Combines online mapping and local search, uses a scratch pad to take notes, and allows to search questions in a geographical context.

URL:http://local.live.com/

*****************************************************

タイトル:Windows Live Ideas - Homepage

説明:Live Search for mobile - Find just the information you're looking for, no matter where it lives Windows Live for Windows Mobile - Delivering your world of relationships, information, and interests on ...

URL:http://ideas.live.com/

*****************************************************

タイトル:Windows Live Product Search Beta

説明:Refine results by related terms, brand, and seller, and sort by price

URL:http://ideas.live.com/programpage.aspx?versionId=29d745fb-e11a-4228-a48b-5c

1e443ea089

*****************************************************

タイトル:Enterprise Search

説明:Enterprise Search ...Enterprise Search.Information is scattered across the Web, on different computers, devices, intranets ...

URL:https://www.microsoft.com/livesearch/default.mspx

*****************************************************

タイトル:Live Search URL Submission

説明:Generally our web crawler, MSNBot, can find most pages on the Internet.However if your site does not appear on Live Search, you can send us the ad

dress (URL).Type the characters from the picture In ...

URL:http://search.live.com/docs/submit.aspx?FORM=SUNO

*****************************************************

タイトル:Live Search Maps Collection Hub

説明:Welcome to collections.live.com Use Live Search Maps to chart and comment on your favorite restaurants, prepare a guided tour of your hometown, show fellow riders the best bike routes, or plot the ...

URL:http://collections.live.com/

*****************************************************

タイトル:Live Search for mobile

説明:Download free software to your phone to get maps and directions, live traffic and more.

URL:http://mobile.search.live.com/about/

*****************************************************

タイトル:Use Live Search to support Children's Hospital

説明:Live Search contributes to Children's Hospital for each search done from this page ...Live Search and Team Seattle are partnering to benefit Children's Hospital - and you can help.Live ...

URL:http://teamseattle.live.com/Search/Charity/TeamSeattle/Default.aspx

*****************************************************

終了するにはいずれかのキーを押してください。