我的项目我正在使用Sitecore7 MVC,Solr和Glass Mapper。
“ContentSearch”索引包含sitecore模板中使用的几乎所有字段。 我正在使用GlassMapper类作为我的模型(它几乎只包含属于sitecore字段的属性)并查询它。基本上按照此处所述“使用自定义结果类”:http://glass.lu/docs/tutorial/sitecore/tutorial25/tutorial25.html
它应该按预期工作。
我的问题是:
只要索引存在(这是我想要的),它是否使用Solr索引填充类属性(通常是sitecore字段)?
或
是否会使用sitecore获取字段值? (我认为这是低效的,在这种情况下,我将编写自定义类并循环它们以填充glassMapper类,因为在我的视图中我使用了GlassMapper类作为我的模型)
例如,我的一个模型看起来像这样:
[SitecoreType]
public class MyAwesomeModel
{
[SitecoreId]
[IndexField("_id")]
public virtual Guid Id { get; set; }
[SitecoreInfo(SitecoreInfoType.Language)]
[IndexField("_language")]
public virtual string Language { get; set; }
[TypeConverter(typeof(IndexFieldItemUriValueConverter))]
[XmlIgnore]
[IndexField("_uniqueid")]
public virtual ItemUri Uri { get; set; }
[SitecoreInfo(SitecoreInfoType.Version)]
public virtual int Version
{
get
{
return Uri == null ? 0 : Uri.Version.Number;
}
}
[SitecoreField(FieldName="MyRichtextField")]
[IndexField("MyRichtextField")]
public virtual string RichTextContent { get; set; }
[SitecoreInfo(SitecoreInfoType.Url, UrlOptions = SitecoreInfoUrlOptions.LanguageEmbeddingNever)]
public virtual string Url { get; set; }
}
答案 0 :(得分:5)
我实际上只是将一些代码推送到我的Fork of Glass.Mapper,它正确地执行: https://github.com/csteeg/Glass.Mapper(在开发分支中)
您必须修改配置,因此您将使用特定于玻璃的内容搜索设置:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<contentSearch>
<indexConfigurations>
<defaultLuceneIndexConfiguration type="Sitecore.ContentSearch.LuceneProvider.LuceneIndexConfiguration, Sitecore.ContentSearch.LuceneProvider">
<indexDocumentPropertyMapper>
<objectFactory type="Sitecore.ContentSearch.DefaultDocumentMapperObjectFactory, Sitecore.ContentSearch">
<patch:attribute name="type">Glass.Mapper.Sc.ContentSearch.LuceneProvider.GlassDocumentMapperObjectFactory, Glass.Mapper.Sc.ContentSearch.LuceneProvider</patch:attribute>
</objectFactory>
</indexDocumentPropertyMapper>
</defaultLuceneIndexConfiguration>
</indexConfigurations>
<configuration type="Sitecore.ContentSearch.ContentSearchConfiguration, Sitecore.ContentSearch">
<indexes hint="list:AddIndex">
<index id="sitecore_master_index">
<patch:attribute name="type">Glass.Mapper.Sc.ContentSearch.LuceneProvider.GlassLuceneIndex, Glass.Mapper.Sc.ContentSearch.LuceneProvider</patch:attribute>
</index>
<index id="sitecore_web_index">
<patch:attribute name="type">Glass.Mapper.Sc.ContentSearch.LuceneProvider.GlassLuceneIndex, Glass.Mapper.Sc.ContentSearch.LuceneProvider</patch:attribute>
</index>
<index id="sitecore_core_index">
<patch:attribute name="type">Glass.Mapper.Sc.ContentSearch.LuceneProvider.GlassLuceneIndex, Glass.Mapper.Sc.ContentSearch.LuceneProvider</patch:attribute>
</index>
</indexes>
</configuration>
</contentSearch>
</sitecore>
</configuration>
代码首先返回索引中的值(如果它们存储在那里)。如果请求的属性未存储在索引中,则它将从Sitecore项
获取值