How to: Delete Crawled Properties
Posted
Tuesday, February 26, 2008 9:36 AM
by
CoreyRoth
This unfortunately is not as simple as it should be. Out of the box, there is not an option to delete a single crawled property. I sort of understand the reason behind this, but when developing its very easy to get your crawled properties filled with a bunch of garbage as you are trying things out. It would be nice to clean that up. So how do you do it? Your only option is to make use of a setting on each category of crawled properties (i.e.: SharePoint, Business Data, People), labeled Delete all unmapped crawled properties. You can get there by clicking the Edit Category link after choosing a Crawled Property. To make use of this, you would need to remove any mapping of crawled properties you don't want to keep first. I don't really like this as an option all that much, especially when you are removing things from the SharePoint category. Unfortunately, this appears to be the only way to do it other than going directly to the database (which obviously is not recommended).
Examining the API, there is nothing in there to delete a single crawled property either. However, you can also use the API to do the above mentioned step if you want. Include a reference to Microsoft.SharePoint and Microsoft.Office.Server.Search.Administration. Here is the code to delete the unmapped properties.
using (SPSite currentSiteCollection = new SPSite("http://mossserver"))
{
// the schema class actually represents managed and crawled proeperties
Schema schema = new Schema(SearchContext.GetContext(currentSiteCollection));
// get the sharepoint category
Category category = schema.AllCategories("SharePoint");
// delete all unmapped properties
category.DeleteUnmappedProperties();
// after delete an update is required
category.Update();
}