我的项目正在使用 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; }
}
最佳答案
实际上,我只是将一些代码推送到我的 Fork of Glass.Mapper 中,它可以做到这一点: https://github.com/csteeg/Glass.Mapper (在开发分支中)
您必须修补您的配置,以便您将使用 glass 特定的内容搜索设置:
<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 项获取值
关于solr - Glass.Mapper.Sc 是否使用索引字段进行 sitecore7 搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24776191/