2015-04-16 70 views
1

我用添加以下代码ComputedIndexFields.config文件:简单Sitecore的包含文件出了问题(ComputedIndexFields.config)

<?xml version="1.0" encoding="utf-8" ?> 
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> 
    <sitecore> 
    <contentSearch> 
     <configuration> 
     <defaultIndexConfiguration> 
      <fields hint="raw:AddComputedIndexField"> 
      <field fieldName="AppliedThemes" storageType="yes" indexType="TOKENIZED">be.extensions.AppliedThemes, be.extensions</field> 
      </fields> 
     </defaultIndexConfiguration> 
     </configuration> 
    </contentSearch> 
    </sitecore> 
</configuration> 

我还添加了类中说assemlby:

namespace be.extensions 
{ 
    class AppliedThemes : IComputedIndexField 
    { 

     public string FieldName { get; set; } 
     public string ReturnType { get; set; } 

     public object ComputeFieldValue(IIndexable indexable) 
     { 
     Item item = indexable as SitecoreIndexableItem; 
     if (item == null) 
      return null; 

     var themes = item["Themes"]; 
     if (themes == null) 
      return null; 

     // TODO 
     } 
    } 
} 

这是添加计算索引字段的基础。然而,当我添加这两个文件(代码在类文件中永远不会到达),当我打开内容编辑器时出现以下错误:

SearchConfiguration配置不正确。预期ContentSearchConfiguration但返回了System.String。

没有这个简单的配置文件一切工作正常。

有没有人看到我在这里做错了什么,或知道我可以尝试解决这个问题?

编辑:我使用Sitecore的8更新2

+0

Sitecore的是什么你使用的是哪个版本? –

+0

Sitecore 8更新2 – Timon

+0

您是否查看了/sitecore/admin/showconfig.aspx页面以确保修补程序工作正常? –

回答

4

我想你的补丁文件需要导致以下XPath

/sitecore/contentSearch/indexConfigurations/defaultLuceneIndexConfiguration/fields 

因此,像这样:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> 
    <sitecore> 
    <contentSearch> 
     <indexConfigurations> 
     <defaultLuceneIndexConfiguration> 
      <fields hint="raw:AddComputedIndexField"> 
      <field fieldName="AppliedThemes">be.extensions.AppliedThemes, be.extensions</field> 
      </fields> 
     </defaultLuceneIndexConfiguration> 
     </indexConfigurations> 
    </contentSearch> 
    </sitecore> 
</configuration> 
+0

这样做了。 我将“配置”更改为“indexConfigurations”,现在可以使用了,谢谢! 使用sitecore 8做了这个改变吗?因为我可以找到使用“配置”的每个指南。 – Timon

+0

我目前正在使用7.2版本,它在那里是一样的...它可能是你原来在早期的7版本 –

+0

你会碰巧知道我何时调用这个代码?我已经添加了一个断点并重建了几个项目的索引,但它从不碰到断点。 – Timon