前几天遇到了这个问题,但还没有找到解决这个问题的任何东西(来自谷歌搜索)。
我使用 Solr 作为我的索引引擎。我正在尝试在我的模板中索引图像字段。索引工作正常,但它没有索引媒体 URL(我从我的代码返回),而是索引图像的 ALT 文本。如果 ALT 文本不存在,则它正在索引媒体 URL。我的索引配置在一个单独的文件中。
我认为默认 Sitecore.ContentSearch.Solr.DefaultIndexConfiguration.config 文件中的以下行可能与我的配置混淆。但是我如何只为“main_image”字段覆盖它。
<fieldReader fieldTypeName="image" fieldReaderType="Sitecore.ContentSearch.FieldReaders.ImageFieldReader, Sitecore.ContentSearch" />
下面是我的配置的样子:
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<myindex>
<indexConfigurations>
<mySolrIndexConfiguration ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration">
<fields hint="raw:AddComputedIndexField">
<field fieldName="main_image" returnType="text">My.Indexing.Namespace.MyMainImageIndexing,My.Indexing</field>
<field fieldName="thumbnail" returnType="text">My.Indexing.Namespace.MyThumbnailIndexing,My.Indexing</field>
</fields>
</mySolrIndexConfiguration>
</indexConfigurations>
</myindex>
</sitecore>
</configuration>
其中一种实现如下所示(另一种类似)
public class MyMainImageIndexing : IComputedIndexField
{
public string Parameters { get; set; }
public string FieldName { get; set; }
public string ReturnType { get; set; }
public object ComputeFieldValue(IIndexable indexable)
{
Assert.ArgumentNotNull(indexable, "indexable");
var indexableItem = indexable as SitecoreIndexableItem;
if (indexableItem == null)
{
Log.Warn(string.Format("{0} : unsupported IIndexable type : {1}", this, indexable.GetType()), this);
return null;
}
ImageField img = indexableItem.Item.Fields["Main Image"];
return (img == null || img.MediaItem == null) ? null : MediaManager.GetMediaUrl(img.MediaItem);
}
}
任何人都可以在这里阐明如何解决此问题。
提前致谢。
PS> 我在这里看到了 John West 的帖子http://www.sitecore.net/de-de/learn/blogs/technical-blogs/john-west-sitecore-blog/posts/2013/05/sitecore-7-pre -render-image-fields.aspx