Creating custom crawled properties

Mar 4, 2008 at 3:33 PM

how do we create custom crawled properties ?
Mar 6, 2008 at 3:25 AM
To create custom crawled properties i use some C# code:

Schema sspSchema = new Schema(SearchContext.GetContext(new SPSite(strURL)));

CategoryCollection categories = sspSchema.AllCategories;

Guid g = new Guid(....);

Category c = categories.Create("Your Category", g);
c.AutoCreateNewManagedProperties = true;

CrawledProperty cProp = c.CreateCrawledProperty("Property Name", false, g, 31);

Hope this helps,
Mar 6, 2008 at 10:00 AM
many many thanks!
Mar 13, 2008 at 11:45 AM
How to you create a new GUID?
Mar 13, 2008 at 7:19 PM
use the guidgen.exe tool and after you got your gui string split it(see bellow) and then call :

new Guid(0x@@@@@@@, 0x@@@@, 0x@@@@, 0x@@, 0x@@, 0x@@, 0x@@, 0x@@, 0x@@, 0x@@, 0x@@);

hope this helps,
Mar 14, 2008 at 7:24 AM
May 21, 2008 at 12:35 PM
Edited May 21, 2008 at 12:51 PM
Where would you run this block of code? In the Accessor.Init method or does it need to be run only once on install?
May 30, 2008 at 4:54 AM
I have a separate config application that creates these properties, but I think you can also run it on install.
Jun 9, 2008 at 9:06 PM
Edited Jun 17, 2008 at 7:10 PM
Jun 9, 2008 at 9:30 PM
Edited Jun 18, 2008 at 2:27 PM
Has anyone been successful in creating crawled properties in their protocol handler that go into a custom category versus the default "SharePoint" category.

I have successfully created a small separate console application that creates my own custom category and my own custom crawled properties. I have also successfully created a protocol handler that when content is crawled automatically adds my own discovered crawled properties. The problem I am currently having is that my protocol handler custom crawled properties go into a default crawled property category of "SharePoint". I would rather have them go into the custom category I have created but I have not been able to figure out how to get that accomplished.

I have found Microsoft documentation indicating that the combination of the Protocol Handler and iFilter determine which category a crawled property goes into but I have not been able to find the code that makes this happen.

Has anyone been able to accomplish this?

Update - 6/18/2008
I was able to solve this issue by creating my own GUID constant in ISearchProtocol.cs and then using that GUID constant in Accessor.cs when instantiating a new ChunkInfo in the m_Properties.Add call. Doing this automagically creates a "Category 1" category that holds your crawled properties added using that GUID. If you need further details, just reply to this post or otherwise ping me.
Nov 18, 2008 at 8:31 PM
Here's a complete code example.  This creates a custom category, a crawled property, a managed property and maps the crawled property to the managed property.



const string CATEGORY_GUID_YOURCATEGORY = "7E55TF97-EA48-444d-8281-83BDE702Z73";



private static string strURL = http://yoursite;




static void AddCategory()




Schema sspSchema = new Schema(SearchContext.GetContext(new SPSite(strURL)));



CategoryCollection categories = sspSchema.AllCategories;



Category cat = null;



if (!categories.Contains("YourCategory")) {


cat = categories.Create(

"YourCategory", new Guid(CATEGORY_GUID_YOURCATEGORY));


cat.AutoCreateNewManagedProperties =





else {


cat = categories[





CrawledProperty cProp = cat.CreateOrGetCrawledProperty("prop:ItemSecurity", false, new Guid(CATEGORY_GUID_COREWORX), 31);



//Add Manage Properties and create mapping to crawled properties






ManagedProperty mProp = sspSchema.AllManagedProperties.Create("ItemSecurity", ManagedDataType.Text);



MappingCollection col = new MappingCollection();



new Mapping(cProp.Propset, "prop:ItemSecurity", 31, mProp.PID));





Dec 23, 2008 at 9:47 AM


I am able to create custom crawled property and map it to managed property.
But when i add this new property in accessor.cs for indexing, it does not work.
For eg -
I have created a new crawled property with below code -
CrawledProperty cProp = c.CreateCrawledProperty("New Property", false, "A54AE7C9-DC74-41f8-986F-606EABC55212", 31);
and this creates a new property in my custom category.
But when i add below line in Init function of accessor.ccs to include for indexing -

m_Properties.Add(new ChunkInfo(new Guid("A54AE7C9-DC74-41f8-986F-606EABC55212"), "prop:ItemSecurity", "Hello"));

Indexing is not done and when i search for text = "Hello" --> no results are found.
But if i manually check the option of "included in Index" to true for crawled property - "prop:ItemSecurity" and again do a full crawl, it works.
I am not able to find a way to check this option through code while creating ctegory / crawled property.
Please help.

Thanks & Regards,


Dec 24, 2008 at 9:02 AM
Edited Dec 24, 2008 at 9:09 AM
Hi Seema,

You could try setting the bool CrawledProperty.IsMappedToContents property.

Let us know how you get on,

Dec 24, 2008 at 10:27 AM

Thanks for your reply

I have being assigning MappedToContents property , below is the all code for creating properties and mapping it

private const string CATEGORY_NAME = "SapDocuments";

private static Guid CategoryId = new Guid(0xfb031e8a, 0x7c54, 0x455d, 0x82, 0x20, 0x27, 0x85, 0x6c, 0x32, 0xcf, 0x4e);

In Main -

             string crawledProperty;

            string managedProperty;


            crawledProperty = "SAPDocuments:Office";

            managedProperty = "SAPDocuments-Office";

            SetUpProperty(crawledProperty, managedProperty);


private static void SetUpProperty(string crawlPropertyName, string managedPropertyName)


            string url = ConfigurationManager.AppSettings["SSPServiceSiteUrl"];


            Schema sspSchema = new Schema(SearchContext.GetContext(new SPSite(url)));

            CategoryCollection categories = sspSchema.AllCategories;

            Category category = null;

            if (!categories.Contains(CATEGORY_NAME))


                category = categories.Create(CATEGORY_NAME, CategoryId);

                category.MapToContents = true;

                category.DiscoverNewProperties = true;





                category = categories[CATEGORY_NAME];



            CrawledProperty crawledProperty = category.CreateOrGetCrawledProperty(crawlPropertyName, false, CategoryId, 31);

            //Add Manage Properties and create mapping to crawled properties


            ManagedProperty managedProperty = sspSchema.AllManagedProperties.Create(managedPropertyName, ManagedDataType.Text);

            MappingCollection mappingProperty = new MappingCollection();

            mappingProperty.Add(new Mapping(crawledProperty.Propset, crawlPropertyName, 31, managedProperty.PID));





In accessor.cs my code goes –


m_Properties.Add(new ChunkInfo(SearchProtocolGuids.PSGUID_SAPDOCUMENTS, "SAPDocuments:Office", m_ContentEnumerator.Office));



In class – SearchProtocolGuids

public static Guid PSGUID_SAPDOCUMENTS = new Guid(0xfb031e8a, 0x7c54, 0x455d, 0x82, 0x20, 0x27, 0x85, 0x6c, 0x32, 0xcf, 0x4e);


This does not index my custom proeprties unless I manually go and check the option "included in Index" to true for "SAPDocuments:Office" crawled property