4

我刚刚开始使用 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" />

希望这可以帮助!

4

1 回答 1

4

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

这确实很奇怪,因为在文档Developer's Guide to Item Buckets and Search中,它明确指出它应该能够开箱即用地映射IEnumerable<T>.

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

于 2013-12-17T16:22:25.063 回答