Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

How to: Retrieve the Crawled Properties Mapped to a Managed Property

SharePoint 2007

You can use the Enterprise Search Administration object model to access the list of crawled properties mapped to a managed property.

The following procedure shows how to write the GUIDs and categories for the crawled properties mapped to a specific managed property from a console application.

To retrieve the crawled properties mapped to a managed property

  1. In your application, set references to the following DLLs:

    • Microsoft.SharePoint.dll

    • Microsoft.Office.Server.dll

    • Microsoft.Office.Server.Search.dll

  2. In the class file of your console application, add the following using statements near the top of the code with the other namespace directives.

    using Microsoft.SharePoint;
    using Microsoft.Office.Server.Search.Administration;
    
  3. To retrieve the Schema object for the search context of the Shared Service Provider (SSP), add the following code. For more information about ways to retrieve the search context, see How to: Return the Search Context for the Search Service Provider.

    /*
    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. Retrieve the collection of managed properties by using the following code:

    ManagedPropertyCollection properties = sspSchema.AllManagedProperties;
    
  5. Retrieve the managed property matching the name specified in the args[0] parameter.

    ManagedProperty mProp = properties[args[0]]
    
  6. Retrieve the list of crawled properties for that managed property, and write the category name and property GUID to the console. To do this, replace the "<…>" characters in the preceding step with the following code:

    foreach (CrawledProperty cProp in mProp.GetMappedCrawledProperties(mProp.GetMappings().Count))
    {
    Console.WriteLine(cProp.Name);
    Console.WriteLine(cProp.Propset);
    }
    

Example

Following is the complete code for the console application class sample.

Prerequisites

  • Ensure that a Shared Service Provider is already created.

Project References

Add the following Project References in your console application code project before running this sample:

  • 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 props = sspSchema.AllManagedProperties;
                ManagedProperty mProp = properties[args[0]];
                foreach (CrawledProperty cProp in mProp.GetMappedCrawledProperties(mProp.GetMappings().Count))
                        {
                             Console.WriteLine(cProp.Name);
                             Console.WriteLine(cProp.Propset);
                        }
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}

See Also

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.