簡體   English   中英

Sitecore-使用Solr Index中的ContentSearchManager時未映射索引字段

[英]Sitecore - not mapping indexed field when using ContentSearchManager from Solr Index

  • Sitecore 8.2.6
  • Solr 6.6.2

問題:

無法將生日(任何-參見附件)字段映射到C#模型。 全部為null (使用returnType="string" )或01/01/0001 (使用returnType="datetime"

在此處輸入圖片說明

我正在使用sitecore_analytics_index獲取EXM聯系人的搜索結果。 在查看Solr索引時(通過localhost:8984 / solr),我可以清楚地看到這些字段。

dateofbirthcontact.dateofbirth我可以在Fields集合中看到,當查看BirthdaySearchResultItem列表中從搜索索引返回的對象時。

我能夠正確映射contact.tags_smcontact.contactid

public class BirthdaySearchResultItem : SearchResultItem, IObjectIndexers
{
    [IndexField("contact.tags_sm")]
    public string[] ContactList { get; set; } // maps correctly

    [DataMember]
    [IndexField("contact.contactid")]
    public virtual Guid ContactId { get; set; } // maps correctly

    [DataMember]
    [IndexField("contact.dateofbirth")]
    public virtual DateTime BirthDay { get; set; } // have tried using "string"

    [DataMember]
    [IndexField("dateofbirth")]
    public virtual DateTime BirthDay1 { get; set; } // have tried using "string"

    [DataMember]
    [IndexField("contact.dateofbirth_t")]
    public virtual DateTime BirthDay2 { get; set; } // have tried using "string"

    [DataMember]
    [IndexField("contact.dateofbirth_t_en")]
    public virtual DateTime BirthDay3 { get; set; } // have tried using "string"

    [DataMember]
    [IndexField("birthday")]
    public virtual DateTime BirthDay4 { get; set; } // have tried using "string"
}

      <index id="sitecore_analytics_index">
        <configuration ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration">
          <fieldMap>
            <fieldNames hint="raw:AddFieldByFieldName">
              <field fieldName="contact.contactid"                     returnType="guid"/>
              <field fieldName="contact.dateofbirth"                   returnType="datetime"/>  <!-- have tried "string" as well -->
              <field fieldName="dateofbirth"                           returnType="datetime" />
              <field fieldName="contact.dateofbirth_t"                 returnType="datetime" />
              <field fieldName="contact.dateofbirth_t_en"              returnType="datetime" />

.... omitted for brevity

        var indexName = "sitecore_analytics_index";
        var index = ContentSearchManager.GetIndex(indexName);

        using (var context = index.CreateSearchContext())  //IContactDetailFacet
        {
            var predicate = PredicateBuilder.True<BirthdaySearchResultItem>();
            var test = context.GetQueryable<BirthdaySearchResultItem>().ToList();

        }

根據您的數據樣本,我可以看到您使用前導的“ /”而不是“-”,這很重要,因為Solr使用ISO格式表示日期,請參見此處 因此,建議您首先將format屬性添加到索引定義中,例如:

<field fieldName="contact.dateofbirth"   returnType="datetime"   format="yyyy-MM-dd'T'HH:mm:ss'Z'" />

然后在模型中,使用Sitecore.DateUtil.IsoDateToDateTime()方法將ISO格式的日期字符串轉換為DateTime類。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM