首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Glass.Mapper.Sc是否使用索引字段进行sitecore7搜索?

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

Stack Overflow用户
提问于 2014-07-16 08:45:37
回答 1查看 1.3K关注 0票数 2

我的项目我正在使用Sitecore7 MVC,Solr和Glass。

"ContentSearch“索引包含了几乎所有在sitecore模板中使用的字段。我正在使用GlassMapper类作为我的模型(它几乎什么都不包含,只包含属性,这些属性是sitecore字段)并对其进行查询。基本操作“使用自定义结果类”,如下所述:http://glass.lu/docs/tutorial/sitecore/tutorial25/tutorial25.html

就像它应该做的那样。

我的问题是:

它是否使用Solr索引填充类属性(通常是sitecore字段),只要索引存在(这正是我想要的)?

它要去塞特罗尔得到场值吗?(我认为这是效率低下的,在这种情况下,我将编写自定义类并循环它们来填充glassMapper类,因为在我的视图中,我使用了GlassMapper类作为我的模型)

例如,我的一个模型如下所示:

代码语言:javascript
复制
    [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; }
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-07-16 09:31:57

实际上,我只是把一些代码推到了我的Glass.Mapper叉中,这样做是正确的:https://github.com/csteeg/Glass.Mapper (在开发分支中)

您必须修补您的配置,所以您将使用特定于玻璃的内容搜索设置:

代码语言:javascript
复制
<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项中获取值。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24776191

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档