Monday, October 13, 2008

Searching Custom Column Values in MOSS 2007

Searching Custom Column Values in MOSS 2007

An issue that came up on a recent project was how can we search custom meta-data on document libraries in MOSS 2007? So for instance, let’s say that in a set of document libraries in a site or across a number of sites each will have a custom column named “Department” that is of a data type “Choice” and the possible values are each department in an organization. Now let’s say that end-users would like to use advanced search to use the Department field as search criteria.

I knew this was possible with SPS 2003, however, I sadly never had a chance or a reason to try it out – but now I did with SharePoint 2007, yippee! So in order to figure this out, I did a cursory search online and hit TechNet’s MOSS section, but alas, I could not find anything showing exactly what I was looking for. So through some brainstorming with a colleague and also some trial and error I was able to get it.

First off, let's create a custom column of type "Choice" in a sample document library. I've named mine "Department" and given it three possible value options ("Sales", "IT", "Marketing").



Now that we have our column created, we need to run a full crawl in the Shared Service Provider (SSP) to make SharePoint aware of this new piece of meta-data. After the crawl is run, our new property will be captured as (what in SharePoint parlance is called) a "Crawled Property", however that is not enough to perform searching on it, we need to also then create a separate "Managed Property" and map the crawled property to the manually created Managed Property (also as a side note, you can map more than one crawled property to a managed property). Once we do this, SharePoint will be fully aware of the property's existence and we can use it as search criteria. The steps for all of this are below:
1. Open up the admin page to the SSP that is hosting the web application your document library is sitting in
2. Click on “Search Setting”, then “Content sources and crawl schedules”


3. Find the content source that contains your site and perform a full crawl on it

Now SharePoint is aware our your new piece of meta-data and we can create a "Managed Property" to map to it.


4. Go back to the "Search Settings" page for your SSP and click "Metadata property mappings"



5. On the "Metadata Property Mappings" page click the "New Managed Property" link



Now on this page, we need to fill out the form for our new managed property. We need to give it a unique name (be careful here because many are already used, such as "Department"), select the correct data type, and then choose which crawled properties map to this new managed property. In this case, it will be only one crawled property and it will be the custom column we had created earlier named "Department".


1. Give a name for the managed property (I chose "OrgDepartment" to make it unique).
2. Select the correct data type, in this case "Text"
3. Now in the "Mappings to crawled properties" section of the form, click "Add Mapping" to bring up the crawled property selection dialog



4. This is a cool little widget in that you can actually search for the property you are looking for, in this case "Department". So enter "Department" in the "Crawled property name" text box and click "Find"




5. In the results I found one named "Department(Text)" and chose that. Now this is something I am still not completely clear on because also in the results list was a crawled property named "ows_Department(Text)" and I am not sure which one is best to use, but I can say that choosing the one without the "ows_" prefix worked just fine. Maybe when better documentation comes out I can get to the bottom of this!

6. Once that we have this form filled out, click OK and perform another full crawl on the necessary content source

At this point our crawled property is now correctly managed, which is great, but in order to actually use it as search criteria we need to customize our search center advanced search page.


1. Once that we have this form filled out, click OK then go back to the "Manage Content Sources" page and perform another full crawl on the necessary content source
2. Go to a search center site and click "Advanced Search"
3. Click on "Site Actions" then "Edit Page"
4. In the "Advanced Search Box" click "Edit" on the top right then click "Modify Shared Web Part"
5. On the pane to the right expand the "Properties" section



In the "Properties" text box under the "Properties" section is the XML defining which properties are searchable when which "Result type" option is selected (such as "Word Documents" or "Excel Documents"). We need to update this XML snippet with the correct nodes to define our new "Department" meta-data. Copy and paste the XML into your favorite text editor and make the following updates:


1. In the node add the following line:



This now adds a definition for our managed property into the search page, however, we will still need to add one more node to make it searchable on the page. The "Name" attribute must match up to the name of the managed property we created earlier and whatever is in the "DisplayName" attribute will be shown in the drop-down list on the UI of the advanced search page.


2. In one of the nodes (it is your choice, each ResultType node points to a different document type or overarches across all or a set of document types.) add the following node:





At this point you just need to exit edit mode and refresh the page and -kapow!- your new piece of meta-data is available in advanced search as search criteria!

No comments: