アイテムIDまたはフル パスでコンテンツ ツリー検索を実施すると複数の結果が返される


解説

Sitecore XPバージョン10.0以降、コンテンツ ツリー検索の挙動が変更されました。アイテムIDまたはパスを検索語句として使用する際、Sitecoreはデータベース(またはSitecoreのキャッシュ)からデータを取得しなくなりました。その代わり、検索インデックスに対するクエリが実行されます。(コンテンツのフル テキスト検索フィールドを使用して)アイテムのすべてのテキスト フィールドに対して検索が実施されるようになったため、以前のSitecore XPバージョンよりも多くの結果が返される可能性があります。

解決策

以前の挙動に戻すには、以下の手順を実施してください。

  1. データベースでDirect Hitが見つかった場合に、検索インデックスへの要求を中止するカスタム クラスを作成します:
    using Sitecore.Diagnostics;
    
    namespace Custom.Pipelines.Search
    {
        internal class AbortIfDirectHitIsFound
        {
            public void Process(SearchArgs args)
            {
                Assert.ArgumentNotNull(args, "args");
                if (args.Result.Categories.Any(category => category.Name == "Direct Hit"))
                {
                    args.AbortPipeline();
                }
            }
        }
    }
  2. このクラスをアセンブリにビルドします。
  3. アセンブリをWebサイトの\binフォルダに配置します。
  4. 設定からのクラスを参照するよう\App_Config\Include\zzzフォルダで設定パッチファイルを作成します:
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
      <sitecore>
        <pipelines>
          <search>
            <processor type="Sitecore.Pipelines.Search.IDResolver, Sitecore.Kernel" patch:before="*[1]" />
            <processor type="Sitecore.Pipelines.Search.PathResolver, Sitecore.Kernel" patch:after="*[@type='Sitecore.Pipelines.Search.IDResolver, Sitecore.Kernel']" />
            <processor type="Custom.Pipelines.Search.AbortIfDirectHitIsFound, Custom.Assembly" patch:before="*[@type='Sitecore.ContentSearch.Client.Pipelines.Search.SearchContentSearchIndex, Sitecore.ContentSearch.Client']" />
          </search>
        </pipelines>
      </sitecore>
    </configuration>

注意

Sitecore XP 10.3において、解説で説明されている挙動の変更が差し戻されました。そのため、コンテンツ ツリー検索は、Sitecore XP 10.0以前の製品バージョンと同様に、アイテムIDとパスを考慮して機能するようになりました。