Edge GraphQL スキーマにおいて結果の並べ替えが不規則になる


概要

Headless Services モジュールは、Sitecore Experience Edge用のGraphQL エンドポイントを導入しています。このエンドポイントでは、Sitecore環境のコンテンツ データをクエリできます。検索クエリは、コンテンツ アイテムを検索し、結果を特定のフィールドの値の順番で並べ替えるために使用されます。

例:

{ 
  search(where:{ 
    AND:[{ 
      name:"_name", 
      value:"home" 
   }] 
 },  
  orderBy:{ 
    name:"title", 
    direction:ASC 
 }){ 
    results{ 
      name 
      path 
    } 
 } 
} 

SolrがSitecoreのアイテムをインデックス化するとき、トークナイザーはフィールドのコンテンツを解析して、フィールドごとに複数のトークンに変換します。トークン化されたフィールド(上記の例のOrderByなど)では、順序が予測できなくなる可能性があります。本問題は、Sitecore Headless Services 18.0.0で発生します。

シナリオ

TitleはSitecore XPのデフォルト フィールドです。Solrの設定では、テキスト フィールドとして定義されています。

<fieldNames hint="raw:AddFieldByFieldName">
  <field fieldName="title" returnType="text" />
</fieldNames>


テキスト フィールドはダイナミック Solr フィールドにマップされています:

 <typeMatches hint="raw:AddTypeMatch">
    <typeMatch typeName="text" type="System.String" fieldNameFormat="{0}_t" cultureFormat="_{1}"  
     settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" />
</typematches>だ

ダイナミック フィールドは、Solr スキーマ ファイルで定義され、text_general フィールド タイプ(またはカルチャーごとに同等のもの)にマップされています。

<dynamicField name="*_t" type="text_general" indexed="true" stored="true"/>
<dynamicField name="*_t_en" type="text_general" indexed="true" stored="true"/>
<dynamicField name="*_t_da" type="text_da" indexed="true" stored="true"/>

フィールド タイプの定義には、docValuesが含まれず、StandardTokenizerFactoryを使用しています。トークナイザーは、入力値を語句に分割します。StandardTokenizerFactoryは通常、フィールドごとに複数の語句を生成します:

 <fieldType name="text_general" class="solr.TextField" positionIncrementGap="100" multiValued="false">
  <analyzer type="index">
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.StopFilterFactory" words="stopwords.txt" ignoreCase="true"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
  <analyzer type="query">
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.StopFilterFactory" words="stopwords.txt" ignoreCase="true"/>
    <filter class="solr.SynonymFilterFactory" expand="true" ignoreCase="true" synonyms="synonyms.txt"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
</fieldType>

 

解決策

本問題を解決するには、下記の選択肢を考慮して、トークン化されていないフィールドを作成する、または、コピー フィールドを含むようにSolrスキーマを修正します: