【问题标题】:Sitecore 7 LinQ POCO classes - How to Fetch data from Treelist?Sitecore 7 LinQ POCO 类 - 如何从 Treelist 中获取数据?
【发布时间】:2013-12-26 22:22:36
【问题描述】:

我刚刚开始使用 SOLR 与 Sitecore 7 的集成。我设法遵循了一些指南并构建了一个“POCO”类(继承自 SearchResultItem),它允许我执行 LINQ 查询和搜索数据,如下面的示例所示:

public class MySearchItem: SearchResultItem
{
    [IndexField("Text Field")]
    public string TextField
    {
        get;
        set;
    }

    [IndexField("Drop Link")]
    public ID DropLink
    {
        get;
        set;
    }

    [IndexField("Tree List")]
    public IEnumerable<ID> TreeList
    {
        get;
        set;
    }
}

当我开始使用下面的代码执行查询时,我观察到结果项中的 TextField 和 DropLink 属性被正确填充,分别包含 TextField 和 DropLink 的内容和 ID。然而,TreeList 属性被检索为 null。我已经检查了明显的内容,并确保提示正确反映了 sitecore 模板中的字段名称,并且根据“开发人员的项目存储桶和搜索指南”文档,自动支持 sitecore 7 IEnumerable。

var index = ContentSearchManager.GetIndex("sitecore_master_index");

using (var context = index.CreateSearchContext())
{
    var results = context.GetQueryable<MySearchItem>();

    results = results.Where(item => item.TemplateName == "Custom Sitecore Template");
}

该字段位于索引器中,因为对 results.First()["TreeList"] 的调用似乎显示了我所追求的数据。这是读取数据的正确方法吗?

此外,是否可以在我的“POCO”类中放入其他类型?假设我想查询树列表中项目的属性。我将如何实施呢?我是否正确假设 sitecore 需要我的树列表类型的 TypeConverter 才能正确解析除 ID 以外的类型的 TreeList 以执行以下操作?

[IndexField("Tree List")]
public IEnumerable<TreeListItem> TreeList
{
    get;
    set;
}

任何有助于理解这种行为的帮助/指导将不胜感激。

谢谢!

更新

我已按照本文中的建议将此作为错误报告提交。如果有人遇到此问题,他们确认这是一个问题并建议了以下解决方法:

将以下行添加到 Sitecore.ContentSearch.Solr.Indexes.config 文件的部分:

<typeMatch typeName="guidCollection"      type="System.Collections.Generic.IEnumerable`1[System.Guid]"    fieldNameFormat="{0}_sm"  multiValued="true"   settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" /> 
<typeMatch typeName="stringCollection"    type="System.Collections.Generic.IEnumerable`1[System.String]"   fieldNameFormat="{0}_sm"  multiValued="true"   settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" />
<typeMatch typeName="intCollection"          type="System.Collections.Generic.IEnumerable`1[System.Int32]"     fieldNameFormat="{0}_im"   multiValued="true"   settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" />

希望这会有所帮助!

【问题讨论】:

    标签: sitecore sitecore7


    【解决方案1】:

    我遇到了同样的问题,通过检查配置文件 Sitecore.ContentSearch.Solr.Indexes.config 似乎该类型未与 Solr 提供程序映射。

    这确实很奇怪,因为文档Developer's Guide to Item Buckets and Search中明确指出,它应该能够开箱即用地映射IEnumerable&lt;T&gt;的类型。

    您能否尝试将多列表字段的类型从 IEnumerable&lt;ID&gt; 更改为 List&lt;Guid&gt; 并检查这是否解决了您的问题?

    【讨论】:

    • 立即工作!谢谢。
    • 您应该将此作为文档或配置错误报告给 Sitecore 支持
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多