solr - Glass.Mapper.Sc 是否使用索引字段进行 sitecore7 搜索

标签 solr sitecore sitecore7 glass-mapper

我的项目正在使用 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/

相关文章:

c# - 为什么 sitecore 按整数类型忽略默认值 0?

solr - Sitecore Solr 通过多重列表搜索另一个多重列表中的值

search - Sitecore 索引中的 urllink 返回带有 "/sitecore/shell/~/media/..."的媒体 url

linux - solr 性能随 ram 大小的变化

Solr 4.0 fq 加入与 q 加入

sitecore - Sitecore 中是否有任何地方可以添加有关内容项版本的作者注释?

sitecore - 如何在 Sitecore 后端更改日期时间字段格式

Solr 返回错误 #404 Not Found for url http ://localhost:8983/solr/update? commit=true

java - 如何在Solr中对多个字段进行嵌套聚合?

sitecore - 营销人员的网络表单动态形成字段条件可见性