将 CrawlProperty 设置为“包含在索引中”以编程方式获取值 (Sharepoint 2007)

发布于 2024-12-27 17:25:23 字数 1363 浏览 1 评论 0原文

我正在使用自己的内容源开发 Sharepoint Search。我有我的爬网属性和我的托管属性以及它们之间的相应映射。 另外,我还有动态属性,例如用户可以将属性集更改为爬行,因此我在运行时从 Sharepoint 管理中心进行设置。 我使用以下代码来执行此操作:

    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;
    }

静态属性在安装时添加,动态属性在管理中心手动添加。 我在管理中心手动安装和设置时使用相同的代码添加属性。

问题在于爬网属性的 Sharepoint 标志“包含在索引中”的值。在这种情况下,当安装完成后,对于所有静态爬网属性,此标志的值为 TRUE(是)。否则,对于动态属性,此标志为 FALSE(否)。我需要始终检查标志“包含在索引中”。

据我所知,CrawlProperty 类的属性 IsMappedToContents 负责“包含到索引”值,但它对我不起作用!

你有想法这样做吗?我做错了什么?

提前致谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甚是思念 2025-01-03 17:25:24

我发现了问题所在。这是sharepoint的愚蠢把戏!
主要的问题是共享点有对象实例的缓存。
让我们看看,我编写了如何以编程方式更新爬网属性 IsMappedToContents 属性值的示例。

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

您必须使用crawledProperty变量的新实例!如果你写这样的话:

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

你失败了!

因此,始终使用已爬网属性的category.GetAllCrawledProperties()实例来更改此属性。

PS:IsMappedToContents 负责 Sharepoint 中的“包含在索引中”复选框。
*PS2:这个东西适用于 Sharepoint 2007,据我所知,Sharepoint 2010 在缓存实例方面没有类似的问题!*

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!*

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文