1

先日この問題に遭遇しましたが、この問題に対処するものは (グーグルから) まだ見つかりません。

インデックス作成エンジンとして 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>

実装の1つは以下のようになります(もう1つは同様です)

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

4

1 に答える 1

4

あなたのコードは完全にうまく見えます。構成にバグがあります。

returnTypeフィールドを に設定しますtext。これは、Solr がそれらのフィールドをトークン化することを意味します。これは、Solr が値を 1 つの文字列として保持しないことを意味します。代わりに、将来全文検索を可能にするトークンを作成します。

構成を次のように変更する必要があります

<field fieldName="main_image" returnType="string">...

インデックスを再作成した後、Solr は値全体を 1 つの文字列として保持します。

また、メディア アイテムの名前を変更すると、Solr の URL が古くなり、すべての参照ドキュメントが自動的に再構築されないことに注意してください。

于 2016-03-07T07:48:00.550 に答える