Export (0) Print
Expand All
Expand Minimize
16 out of 23 rated this helpful - Rate this topic

Creating and Exposing Managed Properties in the Advanced Search Page of SharePoint Server Enterprise Search

SharePoint 2007

Summary:  Learn how to create and expose managed properties in the Advanced Search page of Microsoft Office SharePoint Server Enterprise Search.

Office Visual How To

Applies to:  2007 Microsoft Office System, Microsoft Office SharePoint Server 2007

Patrick Tisseghem, U2U

April 2007

Overview

Lists and document libraries in SharePoint sites typically have extra columns defined for them. This custom metadata is collected by the crawler when it indexes the contents of these containers. Administrators can expose this custom metadata to the users who perform search queries in the Search Center. The Advanced Search page has a property picker that can be populated with managed properties. This article explains and illustrates how to expose managed properties to the user, and also explains how developers can programmatically create managed properties.

Code It

You can add managed properties to the property picker in the Advanced Search page by modifying the XML attached to the Advanced Search Box for the properties. A PropertyDef element registers the managed property, and a PropertyRef element as a child of the ResultType element is used for the visualization.

XML for Adding a Managed Property to the Property Picker

<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <LangDefs>
   <LangDef DisplayName="Arabic" LangID="1"/></LangDefs>
 <Languages>
   <Language LangRef="12"/></Languages>
 <PropertyDefs>
   <PropertyDef Name="Path" DataType="text" DisplayName="URL"/><PropertyDef Name="ProjectCode" DataType="text" 
    DisplayName="Project Code"/>
 </PropertyDefs>
 <ResultTypes>
   <ResultType DisplayName="All Results" Name="default">
     <Query/>
       <PropertyRef Name="Author" /><PropertyRef Name="ProjectCode" />
   </ResultType>
   <ResultType DisplayName="Documents" Name="documents">
      <Query>IsDocument=1</Query>
      <PropertyRef Name="Author" /></ResultType>
   <ResultType DisplayName="Word Documents" Name="worddocuments">
     <Query>FileExtension='doc' Or FileExtension='docx' 
       Or FileExtension='dot'</Query>
     <PropertyRef Name="Author" />
     <PropertyRef Name="Company"/></ResultType></ResultTypes>
</root>

References and Namespaces for Programmatically Working with Managed Properties

You must run the sample code on a server running SharePoint Server 2007. The sample code requires references to the Microsoft.SharePoint.dll, the Microsoft.Office.Server.dll, the Microsoft.Office.Server.Search.dll and the System.Web.dll. The following namespaces are used:

using Microsoft.Office.Server;
using Microsoft.Office.Server.Administration;
using Microsoft.Office.Server.Search;
using Microsoft.Office.Server.Search.Administration;

Connecting to Shared Services Provider and the Search Context

Before getting access to the managed properties programmatically, you need to understand the reference to the context of the Shared Services Provider and the Search Service. The following example illustrates these concepts. The example assumes that the name of the Shared Services Provider is "SharedServices1".

private ServerContext serverctx = null;
private SearchContext searchctx = null;
private void Form1_Load(object sender, EventArgs e)
{
  serverctx = ServerContext.GetContext("SharedServices1");
  searchctx = SearchContext.GetContext(serverctx);
}

Retrieving the List of Managed Properties

Your entry point in the search namespace to work with managed properties is an instance of the Schema class. This class exposes the AllManagedProperties property, which can be used in a loop for displaying all of the individual ManagedProperty instances. A call to the GetMappings method retrieves per managed property the crawled properties that are mapped to it.

Schema schema = new Schema(this.searchContext);
foreach (ManagedProperty prop in schema.AllManagedProperties)
{
    TreeNode node = treeViewManagedProperties.Nodes.Add(prop.Name);
    node.Tag = prop;
    foreach (Mapping mapping in prop.GetMappings())
    {
        node.Nodes.Add(mapping.CrawledPropertyName);
    }
}

Retrieving the List of Crawled Properties

You can use the method QueryCrawledProperties, which is exposed by the Schema class, to retrieve all of the crawled properties. Since this can be a huge list, there are parameters available that filter and restrict the amount of properties that QueryCrawledProperties retrieves.

listBoxCrawledProperties.Items.Clear();
listBoxCrawledProperties.DisplayMember = "Name";
foreach (CrawledProperty cprop in 
   schema.QueryCrawledProperties(string.Empty, 1000, Guid.NewGuid(), 
                                 string.Empty, true))
{
    listBoxCrawledProperties.Items.Add(cprop);
}

Creating a Managed Property

You can create a managed property by calling the Create method of the ManagedPropertyCollection. Arguments are the name of the managed property and the type of the information that it will store.

Schema schema = new Schema(this.searchContext);
schema.AllManagedProperties.Create
     (textBoxManagedPropertyName.Text, ManagedDataType.Text);

Mapping Crawled Properties to a Managed Property

An instance of the class MappingCollection can be populated with Mapping objects. Each one represents one mapping of a crawled property with a managed property.

ManagedProperty prop = (ManagedProperty)
      treeViewManagedProperties.SelectedNode.Tag;
MappingCollection mappings = new MappingCollection();
foreach (CrawledProperty cprop in 
         listBoxCrawledProperties.SelectedItems)
{
    mappings.Add(new Mapping
      (cprop.Propset, cprop.Name, cprop.VariantType, prop.PID));
}
prop.SetMappings(mappings);
Read It

When content in a SharePoint site gets crawled, custom metadata is collected and stored by the crawler in the Property Store (one of the databases under the control of the Shared Services Provider). In the administration site of the Shared Services Provider, administrators can map one or more of these crawled properties to a managed property. A managed property can be exposed in the property picker of the Advanced Search page and also in the page where you define shared search scopes.

To create a managed property

  1. In the Search Settings of the Shared Services Provider administration site, click on Metadata Property Mappings

  2. The Quick Launch displays a link to the page that displays the list of managed properties as well as a link to the page that displays the list of crawled properties.

  3. In the page that shows the managed properties, click New Managed Property to create a new one. You can set a title (no spaces allowed), a description, and the type of the information stored in the property.

  4. Crawled properties can be mapped by opening the Crawled Property Selection dialog.

  5. The option to use the managed property in the definition of a search scope can be activated.

Figure 1. Classes used to programmatically access and maintain the managed properties

Classes to access and maintain managed properties
See It

MOSS2007 Creating Exposing Managed splash

Watch the Video

Length: 15:02 | Size: 14.5 MB | Type: WMV file

Explore It

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

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.