【问题标题】:Lucene fields default value in Sitecore 7Sitecore 7 中的 Lucene 字段默认值
【发布时间】:2014-10-22 21:38:40
【问题描述】:

当字段没有关联值时,有没有办法强制 Lucene(在 Sitecore 7 中)具有默认值?我一直在尝试对字段进行空字符串或空值比较,但它不起作用。我希望从我的结果集中排除此特定字段没有值的所有项目。

谢谢

【问题讨论】:

    标签: lucene sitecore lucene.net sitecore7


    【解决方案1】:

    您可以基于原始字段创建计算字段。如果为空,则返回默认值:

    public class NullOrEmptyComputedField : IComputedIndexField
    {
        public object ComputeFieldValue(IIndexable indexable)
        {
            Item item = indexable as SitecoreIndexableItem;
            if (item == null)
                return null;
    
            // We return a default value if the target field is empty
            if (String.IsNullOrEmpty(item["originalField"]))
                return "_EMPTY_";
    
            return item["originalField"];
        }
    
        public string FieldName { get; set; 
        public string ReturnType  { get; set; }
    }
    

    有关创建计算域的提示,请参阅以下文章:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-04
      相关资源
      最近更新 更多