[方法] 共有サービス プロバイダの管理プロパティを取得する
エンタープライズ検索 管理オブジェクト モデルの Schema オブジェクトは、共有サービス プロバイダ (SSP) の検索サービス用に構成された管理プロパティへのアクセスを提供します。
次に示す手順は、コンソール アプリケーションから管理プロパティとそのプロパティ識別子 (PID) の完全なリストを書き出す方法です。.
管理プロパティの名前と PID の一覧をコンソール アプリケーションから表示するには
アプリケーションで、以下の DLL への参照を設定します。
Microsoft.SharePoint.dll
Microsoft.Office.Server.dll
Microsoft.Office.Server.Search.dll
コンソール アプリケーションのクラス ファイルで、他の名前空間ディレクティブを含むコードの先頭付近に次の using ステートメントを追加します。
using Microsoft.SharePoint; using Microsoft.Office.Server.Search.Administration;
SSP の検索コンテキストの Schema オブジェクトを取得するには、以下のコードを追加します。検索コンテキストを取得する方法の詳細については、「[方法] 検索サービス プロバイダに検索コンテキストを返す」を参照してください。
/* Replace <SiteName> with the name of a site using the SSP */ string strURL = "http://<SiteName>"; SearchContext context; using (SPSite site = new SPSite(strURL)) { Context = SearchContext.GetContext(site); } Schema sspSchema = new Schema(context);
以下のコードを使用して、管理プロパティのコレクションを取得します。
ManagedPropertyCollection properties = sspSchema.AllManagedProperties;
管理プロパティをループして各プロパティの名前と PID を表示するには、次のコードを追加します。
foreach (ManagedProperty property in properties) { Console.WriteLine(property.Name + " PID: " + property.PID); }
例
以下に、コンソール アプリケーション クラスのサンプルの完全なコードを示します。
前提条件
- 共有サービス プロバイダが既に作成されていることを確認します。
プロジェクト参照
このサンプルを実行する前に、コンソール アプリケーション コード プロジェクトに以下のプロジェクト参照を追加します。
Microsoft.SharePoint
Microsoft.Office.Server
Microsoft.Office.Server.Search
using System;
using System.Collections;
using System.Text;
using Microsoft.Office.Server.Search.Administration;
using Microsoft.SharePoint;
namespace ManagedPropertiesSample
{
class Program
{
static void Main(string[] args)
{
try
{
/*
Replace <SiteName> with the name
of a site using the SSP
*/
string strURL = "http://<SiteName>";
SearchContext context;
using (SPSite site = new SPSite(strURL))
{
Context = SearchContext.GetContext(site);
}
Schema sspSchema = new Schema(context);
ManagedPropertyCollection properties = sspSchema.AllManagedProperties;
foreach (ManagedProperty property in properties)
{
Console.WriteLine(property.Name + " PID: " + property.PID);
}
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
}
See Also
タスク
[方法] 管理プロパティにマップされたクロール プロパティを取得する