Share via


[方法] 共有サービス プロバイダの管理プロパティを取得する

エンタープライズ検索 管理オブジェクト モデルの Schema オブジェクトは、共有サービス プロバイダ (SSP) の検索サービス用に構成された管理プロパティへのアクセスを提供します。

次に示す手順は、コンソール アプリケーションから管理プロパティとそのプロパティ識別子 (PID) の完全なリストを書き出す方法です。.

管理プロパティの名前と PID の一覧をコンソール アプリケーションから表示するには

  1. アプリケーションで、以下の DLL への参照を設定します。

    • Microsoft.SharePoint.dll

    • Microsoft.Office.Server.dll

    • Microsoft.Office.Server.Search.dll

  2. コンソール アプリケーションのクラス ファイルで、他の名前空間ディレクティブを含むコードの先頭付近に次の using ステートメントを追加します。

    using Microsoft.SharePoint;
    using Microsoft.Office.Server.Search.Administration;
    
  3. 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);
    
  4. 以下のコードを使用して、管理プロパティのコレクションを取得します。

    ManagedPropertyCollection properties = sspSchema.AllManagedProperties;
    
  5. 管理プロパティをループして各プロパティの名前と 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

タスク

[方法] 検索サービス プロバイダに検索コンテキストを返す

[方法] 管理プロパティを作成する

[方法] 管理プロパティを削除する

[方法] 管理プロパティにマップされたクロール プロパティを取得する

[方法] クロール プロパティを管理プロパティにマップする

概念

検索管理オブジェクト モデルを使うにあたって

メタデータを管理する