Sitecore 6.4 + Lucene - 模板继承

时间:2011-03-29 12:45:17

标签: templates inheritance lucene sitecore

经过几个小时计算出Lucene后,我放弃了。希望你能帮忙。

设置

在我们当前的Sitecore树中,我们有模板2模板继承级别。 (我们说车辆 - >汽车 - >一级方程式/车辆 - >小船)。

我现在需要通过Lucene获取的是每个ContentItem从某个模板直接间接继承

例如:

  • 获取车辆 - > 返回:“通用”车辆,汽车,F1汽车和船只
  • 获取汽车 - > 返回:汽车,F1赛车

我认为使用Lucene中的_templates字段,即:
获取车辆 - > _templates包含Vehicle-template-guid。 获取汽车 - > _templates包含Car-template-guid。

问题

我遇到的主要问题是 F1 Car -template的内容项目在_templates字段中包含汽车和F1汽车,以及通用“车辆”。

我可能误解了_templates-field,但我想知道是否还有其他选择。


Sitecore配置:

内容项目:

  • Sitecore的
    • 内容
      • 主页
        • ACategory
          • 一个孩子1
          • A Child 1.1
          • 一个孩子2

模板(级别=继承):

  • 主要实体
    • 子实体1
      • 儿童实体1.1​​
    • 子实体2
  • 类别

1 个答案:

答案 0 :(得分:2)

创建一个新的索引器,它继承Sitecore.Data.Indexing.Index,并覆盖AddFields方法,如下所示:

protected override void AddFields(Item item, Document document)
{   
    // Add base fields
    base.AddFields(item, document);

    // Add all inherited templates id to a field 
    string TEMPLATE-PATH="get template path for this item here";
    document.Add(new Field("template-path", TEMPLATE-PATH, Field.Store.NO, Field.Index.TOKENIZED)); 
}

然后您可以通过“template-path”字段进行搜索。