Question

I'm developing Sharepoint Search with own Content Source. And I have my crawl properties and my managed properties and mapping between them accordingly. Also I have dynamic properties, e.g. the user can change the set of properties to crawling,therefore I make it at runtime from Sharepoint Central Administration. I'm using the following code to do that:

    private static void CreateProperty(string propertyName, Category category, ManagedPropertyCollection managedProperties)
    {
        var crawledProperty = category.CreateCrawledProperty(propertyName, false, Constants.CategoryId, 31);
        crawledProperty.IsMappedToContents = true;
        SetMapping(crawledProperty, managedProperties);
        crawledProperty.Update();
    }

    private static void SetMapping(CrawledProperty cProp, ManagedPropertyCollection managedProperties)
    {
        ManagedProperty mProp = managedProperties.Create(cProp.Name, ManagedDataType.Text);
        mProp.EnabledForScoping = true;
        Mapping newMapping = new Mapping(cProp.Propset, cProp.Name, cProp.VariantType, mProp.PID);
        MappingCollection mappings = mProp.GetMappings();
        mappings.Add(newMapping);
        mProp.SetMappings(mappings);
        mProp.EnabledForScoping = true;
    }

The static properties adds while installation, the dynamic properties adds manualy at Central Administration. I'm using the same code to add properties while installation and setting manualy at Central Administration.

The problem is the value of Sharepoint flag "Included in index" for crawl properties. In the case, when the installation has been completed, the value of this flag is TRUE (yes) for all static crawl properties. Otherwise, for dynamic properties this flag is FALSE (no). I need to have always checked flag "Included in index" .

As I know, the property IsMappedToContents of CrawlProperty class is responsable to "Included to index" value, but it doesn't work for me!

Do you have any idea to do that? And what I do wrongly?

Thanks in advance.

Was it helpful?

Solution

I found of the problem. It is sharepoint stupid tricks! The main trouble is sharepoint has cache of object instances. Lets see, I wrote the sample how to update crawl property IsMappedToContents property value programmatically.

foreach (CrawledProperty crawledProperty in category.GetAllCrawledProperties())
{
   crawledProperty.IsMappedToContents = true;
   crawledProperty.Update();
}

You MUST use fresh instance of crawledProperty variable! If you write something like this:

CrawledProperty crawledProperty = category.CreateCrawledProperty(...);
crawledProperty.IsMappedToContents = true;
crawledProperty.Update();

You FAILED!

So, always use category.GetAllCrawledProperties() instances of crawled properties to change this property.

PS: IsMappedToContents responsibles for "Included in index" checkbox in the Sharepoint. *PS2: this stuff works with Sharepoint 2007, as I know Sharepoint 2010 doesn't have similar troubles with caching instances!*

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top