前幾天遇到了這個問題,但找不到任何東西(從谷歌搜索),解決這個問題。Sitecore 8.1計算機索引字段僅用於索引圖像的索引alt文本
我正在使用Solr作爲我的索引引擎。我正在嘗試爲我的模板中的圖像字段編制索引。索引工作正常,但它不是索引媒體網址(我從我的代碼返回),而是索引圖像的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);
}
}
任何人都可以在這裏提供一些線索關於如何解決這個問題。
在此先感謝。
P.S>我在這裏看到約翰·韋斯特的後http://www.sitecore.net/de-de/learn/blogs/technical-blogs/john-west-sitecore-blog/posts/2013/05/sitecore-7-pre-render-image-fields.aspx