---
title: "インデックスにプロパティフィールドを追加する"
slug: "adding-a-property-field-to-an-index"
abstract: "新しいプロパティフィールドをインデックスに設定で追加し、新しいカスタムプロパティをキーワードとしてSitecoreでCommerceアイテムを検索できるようにする方法。"
---
# インデックスにプロパティフィールドを追加する

Sitecore Experience Commerce(XC)はデフォルトでカタログエンティティのプロパティ(カタログ、カテゴリ、販売可能なアイテムのプロパティ)をインデックス化します。 [Sitecoreインデックスの再構築](https://doc.sitecore.com/xp/en/developers/100/platform-administration-and-architecture/rebuild-search-indexes.html) が起動されると、Commerce Engineのミニオンがインデックスされたフィールドをsitecore\_web\_indexとsitecore\_master\_indexに追加します。デフォルトのインデックスは、例えばHabitatカタログのコンテンツ項目をSitecore Content EditorやSXAストアフロントで検索する機能を提供します。新しい検索フィールド(カスタムフィールドを含む)を追加することで検索インデックスを拡張できます。

検索インデックスに新しいCommerceプロパティフィールドを導入するには、新しいプロパティフィールドを検索プロバイダーが処理可能なフィールドタイプにマッピングする必要があります。このマッピングは、ポリシーセットファイルの設定を通じて実現でき、コードを書いたり変更したりする必要がありません。新しいフィールドをデフォルトの検索フィールドハンドラーにマッピングできればの話です。 [Searchプラグイン](https://doc.sitecore.com/xp/ja/developers/100/sitecore-experience-commerce/search-field-handlers.html "Search field handlers") と[Catalogプラグイン](https://doc.sitecore.com/xp/ja/developers/100/sitecore-experience-commerce/catalog-search-field-handlers.html "Catalog search field handlers") は、カタログプロパティマッピングに使用されるデフォルトの検索フィールドハンドラを定義しています。既存のフィールドハンドラーを使えない場合は、[カスタムフィールドハンドラーを作成できます](https://doc.sitecore.com/xp/ja/developers/100/sitecore-experience-commerce/walkthrough--create-a-custom-index-field-handler.html "Walkthrough: Create a custom index field handler")。

## 検索ポリシーセットファイル内のインデックスフィールドマッピング定義

新しいフィールドをインデックスにマッピングする際に考慮すべきアプローチは2つあります。新しいインデックスフィールドを直接Commerceエンティティプロパティにマッピングするか、[Solrの動的フィールド](http://) などの計算フィールドをフィールドハンドラー実装で使用する方法と似ています。これはSitecoreが[Solrフィールド名解決](https://doc.sitecore.com/xp/en/developers/100/platform-administration-and-architecture/using-solr-field-name-resolution.html)で計算フィールドを使う方法に似ています。

新しいCommerceエンティティプロパティをインデックスに追加するには、検索プロバイダーのポリシーセットファイル(例えばSolrを使用している場合はPlugIn.Search.Solr.PolicySet.\*.jsonファイル)のインデックスフィールドタイプへのマッピングを定義します。このポリシーセットファイルは、デプロイメントでインデックスロールをホストしているCommerce Engineのインスタンス(例: C:\\inetpub\\wwwroot\\CommerceMinions\_Sc9\\wwwroot\\data\\Environments).

ポリシーセットファイルでは、ItemIndexablePolicyポリシーがインデックスフィールドマッピングを2つの主要な構成セクション、すなわち "FieldTypeMappers" セクションと "Fields" セクションに分けて定義しています。

### FieldTypeMappersの設定

"FieldTypeMappers"セクションでは、異なるデータ型がインデックスフィールドにどのようにマッピングされるかを定義するIndexFieldTypeMapper構成の集合を詳述しています。以下のPlugIn.Search.Solr.PolicySet.\*.jsonファイルのサンプルは、ウェブインデックスのデフォルト"FieldTypeMappers"定義の例を示しています("IndexName": "sitecore\_web\_index"):

"$type": "Sitecore.Commerce.Core.PolicySet, Sitecore.Commerce.Core",
 "Id": "Entity-PolicySet-SolrSearchPolicySet",
 "Version": 1,
 "IsPersisted": false,
 "Name": "SolrSearchPolicySet",
 "Policies": {
 "$type": "System.Collections.Generic.List\`1Sitecore.Commerce.Core.Policy, Sitecore.Commerce.Core, mscorlib",
 "$values": 
 {
 {

 "$type": "Sitecore.Commerce.Plugin.Search.ItemIndexablePolicy, Sitecore.Commerce.Plugin.Search",
 "IndexName": "sitecore\_web\_index",
 "FieldTypeMappers": 
 {
 "TypeName": "stringCollection",
 "Type": "System.Collections.Generic.List\`1System.String",
 "NameFormat": "{0}\_sm",
 "MultiValued": true
 },
 {
 "TypeName": "textCollection",
 "Type": "System.Collections.Generic.List\`1System.String",
 "NameFormat": "{0}\_txm",
 "MultiValued": true

#### FieldTypeMappersプロパティ

以下の表はFieldTypeMappers構成の性質を一覧かつ説明しています。

性質

概要

"TypeName"

フィールドタイプの名称を定義します。

"Type"

型を実装するクラス名を指定します。

"NameFormat"

型名の形式を定義します。

"MultiValued"

このフィールドタイプに対して、単一の文書に複数の値が含まれているかどうかを示します。

### フィールド構成

"Fields"セクションでは、Commerceエンティティやコンポーネントプロパティをインデックスフィールドに実際にマッピングする設定プロパティの集合を詳細に説明しています。以下はPlugIn.Search.Solr.PolicySet.\*.jsonファイルのデフォルト"Fields"セクションの例です。

"$type": "Sitecore.Commerce.Core.PolicySet, Sitecore.Commerce.Core",
 "Id": "Entity-PolicySet-SolrSearchPolicySet",
 "Version": 1,
 "IsPersisted": false,
 "Name": "SolrSearchPolicySet",
 "Policies": {
 "$type": "System.Collections.Generic.List\`1Sitecore.Commerce.Core.Policy, Sitecore.Commerce.Core, mscorlib",
 "$values": 
 {
 {
 {
 "FieldTypeMappers": 
 "Fields": 
 {
 "$type": "Sitecore.Commerce.Plugin.Search.Solr.SolrIndexFieldConfiguration, Sitecore.Commerce.Plugin.Search.Solr",
 "Name": "sxacontent",
 "Type": "System.Collections.Generic.List\`1System.String",
 "TypeHint": "textCollection",
 "Handler": {
 "$type": "Sitecore.Commerce.Plugin.Catalog.SxaContentFieldHandler, Sitecore.Commerce.Plugin.Catalog"
 }
 },

#### 場の性質

以下の表は の性質を一覧と定義Fields:

財産

定義

"$type"

フィールド型を実装するクラス名への参照を指定します。

"Name"

フィールド名を指定します。

"Type"

タイプ形式。

"TypeHint"

パス可能な値の種類を定義します。

"Handler"

フィールドハンドラを定義するクラスへの参照を指定します。

"Localizable"

場が局所化可能な文字列かどうかを指定します。

## ポリシーセットの設定例

Commerceエンティティプロパティをインデックスフィールドにマッピングする方法は多様です。このセクションではフィールドマッピングのさまざまな構成例を提供します。

マッピング構成は、Solr検索プロバイダーを使用する場合はポリシーセットファイルPlugIn.Search.Solr.PolicySet.\*.json 、Azureを使う場合はPlugin.Search.Azure.PolicySet.\*.json定義されます。

> !注すべての例はSolrを検索プロバイダーとして使っています。同じ例がAzureにも適用されますが、"$type" を "Sitecore.Commerce.Plugin.Search.Azure.AzureIndexFieldConfiguration, Sitecore.Commerce.Plugin.Search.Azure"

-   [インデックスフィールド名とエンティティプロパティが同じ1:1マッピングの例](https://doc.sitecore.com/xp/ja/developers/100/sitecore-experience-commerce/adding-a-property-field-to-an-index.html#UUID-00f7db13-d917-706c-932e-a2db7765d4b1_section-5dbc912053504-idm46038613372096 "Example of 1:1 mapping where the index field name and the entity property are the same")
-   [インデックスフィールド名とエンティティプロパティ名が異なるマッピングの例](https://doc.sitecore.com/xp/ja/developers/100/sitecore-experience-commerce/adding-a-property-field-to-an-index.html#UUID-00f7db13-d917-706c-932e-a2db7765d4b1_section-5dbc925f0d9f8-idm46038613794208 "Example of a mapping where the index field name and the entity property name are different")
-   [実際のプロパティ名とは異なるフィールド名を使ったコンポーネントからのプロパティマッピングの例](https://doc.sitecore.com/xp/ja/developers/100/sitecore-experience-commerce/adding-a-property-field-to-an-index.html#UUID-00f7db13-d917-706c-932e-a2db7765d4b1_section-5dbc93e93dd8e-idm46038613656848 "Example of a property mapping from a component using a different name for the field than the actual property name")
-   [Composerの十進性質の写像の例](https://doc.sitecore.com/xp/ja/developers/100/sitecore-experience-commerce/adding-a-property-field-to-an-index.html#UUID-00f7db13-d917-706c-932e-a2db7765d4b1_section-5dc18da2a5c4f-idm45774636656224 "Example of mapping a Composer decimal property")

### インデックスフィールド名とエンティティプロパティが同じ1:1マッピングの例

以下は、インデックスフィールド名("DisplayName")とCommerceプロパティ名が同じである例を示しています。Commerceプロパティ名を定義するために "ValueSource" を指定する必要はありません。

{
 "$type":"Sitecore.Commerce.Plugin.Search.Solr.SolrIndexFieldConfiguration,
 Sitecore.Commerce.Plugin.Search.Solr",
 "Name":"DisplayName",
 "Type":"System.String"
}

### インデックスフィールド名とエンティティプロパティ名が異なるマッピングの例

インデックスフィールド名が静的Commerceエンティティのプロパティ名に直接対応しないケースもあります。以下はその例を示しています:

{
 "$type":"Sitecore.Commerce.Plugin.Search.Solr.SolrIndexFieldConfiguration, Sitecore.Commerce.Plugin.Search.Solr",
 "Name":"CatalogEntityId",
 "Type":"System.String",
 "ValueSource":{
 "PropertyName":"Id",
 "PropertyPath":""
 }
}

### 実際のプロパティ名とは異なるフィールド名を使ったコンポーネントからのプロパティマッピングの例

以下は、インデックスフィールドDisplayPropertiesColorが "ValueSource".

{
 "$type":"Sitecore.Commerce.Plugin.Search.Solr.SolrIndexFieldConfiguration,
Sitecore.Commerce.Plugin.Search.Solr",
 "Name":"DisplayPropertiesColor",
 "Type":"System.String",
 "TypeHint":"string",
 "ValueSource": {
 "PropertyName":"Color",
 "PropertyPath":"DisplayPropertiesComponent"
 }
}

### カスタムフィールドハンドラーを用いたマッピングの例

以下はカスタムハンドラーが指定された例を示しています:

{
 "$type":"Sitecore.Commerce.Plugin.Search.Solr.SolrIndexFieldConfiguration,
Sitecore.Commerce.Plugin.Search.Solr",
 "Name":"\_UniqueId",
 "Type":"System.String",
 "Handler":{
 "$type":"Sitecore.Commerce.Plugin.Catalog.UniqueIdFieldHandler,
Sitecore.Commerce.Plugin.Catalog"
 }
}

## インデックス作成のためのポリシーセット設定Composer定義プロパティ

[Composerテンプレートを使ってカタログエンティティのカスタムプロパティを定義するビューを追加する](https://doc.sitecore.com/xp/en/users/100/sitecore-experience-commerce/work-with-custom-child-views.html)場合(つまり、テンプレートをカタログ、カテゴリ、またはセレアブルアイテムエンティティにリンクした場合)、新しいプロパティフィールドをインデックスに追加できます。

マッピング構成は、Solr検索プロバイダーを使用する場合はポリシーセットファイルPlugIn.Search.Solr.PolicySet.\*.json 、Azureを使う場合はPlugin.Search.Azure.PolicySet.\*.json定義されます。

> !注このセクションのすべての例はSolrを検索プロバイダーとして使用しています。同じ例がAzureにも適用されますが、"$type" を に更新する必要があります "Sitecore.Commerce.Plugin.Search.Azure.AzureIndexFieldConfiguration, Sitecore.Commerce.Plugin.Search.Azure"

### 作曲家フィールドハンドラー

[Catalogプラグイン](https://doc.sitecore.com/xp/ja/developers/100/sitecore-experience-commerce/catalog-search-field-handlers.html "Catalog search field handlers")は、Composerで定義したカスタムエンティティプロパティをインデックスに追加できるComposerFieldHandlerクラスを提供します。Composerフィールドハンドラーには、Composerテンプレート内のビュー名とインデックスフィールドにマッピングするカスタムプロパティの名前を指定する"ComposerSource"セクションが含まれています。

"Handler": {
 "$type": "Sitecore.Commerce.Plugin.Catalog.ComposerFieldHandler,
Sitecore.Commerce.Plugin.Catalog",
 "ComposerSource": {
 "ViewName": "MyViewName",
 "PropertyName": "StringPropertyName"
 }

Composerフィールドハンドラーの設定パラメータは以下の通りです:

-   "$type": は を実装するクラス名を指定します。 ComposerFieldHandler
-   "Viewname": はカスタムエンティティプロパティを定義する子ビュー名を指定します。
-   "PropertyName": はインデックスフィールドに対応するカスタムエンティティプロパティの名前を指定します。

> !注ViewnameとPropertyNameは [、カタログエンティティの子ビュー](https://doc.sitecore.com/xp/en/users/100/sitecore-experience-commerce/work-with-custom-child-views.html)で定義されているものです。

### Composer文字列プロパティのマッピングの例

以下は、カスタムカタログエンティティプロパティを文字列データ型として定義したものを、適切なインデックスフィールドタイプにマッピングする設定例を示しています。

{
 "$type": "Sitecore.Commerce.Plugin.Search.Solr.SolrIndexFieldConfiguration,
Sitecore.Commerce.Plugin.Search.Solr",
 "Name": "StringPropertyIndexName",
 "Type": "System.String",
 "Handler": {
 "$type": "Sitecore.Commerce.Plugin.Catalog.ComposerFieldHandler,Sitecore.Commerce.Plugin.Catalog",
 "ComposerSource": {
 "ViewName": "MyViewName",
 "PropertyName": "StringPropertyName"
 }
 }
}

### Composer整数性質の写像の例

以下は、整数データ型として定義されたカスタムカタログエンティティプロパティを適切なインデックスフィールドタイプにマッピングする構成例を示します。

{
 "$type":
"Sitecore.Commerce.Plugin.Search.Solr.SolrIndexFieldConfiguration,
Sitecore.Commerce.Plugin.Search.Solr",
 "Name": "IntegerPropertyIndexName",
 "Type": "System.Int64",
 "Handler": {
 "$type": "Sitecore.Commerce.Plugin.Catalog.ComposerFieldHandler, Sitecore.Commerce.Plugin.Catalog",
 "ComposerSource": {
 "ViewName": "MyViewName",
 "PropertyName": "IntegerPropertyName"
 }
 }
}

### Composerの十進性質の写像の例

以下は、カスタムカタログエンティティプロパティを10進データ型として定義したものを、適切なインデックスフィールドタイプにマッピングするための構成例を示しています。

{
 "$type":
"Sitecore.Commerce.Plugin.Search.Solr.SolrIndexFieldConfiguration,
Sitecore.Commerce.Plugin.Search.Solr",
 "Name": "DecimalPropertyIndexName",
 "Type": "System.Decimal",
 "Handler": {
 "$type": "Sitecore.Commerce.Plugin.Catalog.ComposerFieldHandler, Sitecore.Commerce.Plugin.Catalog",
 "ComposerSource": {
 "ViewName": "MyViewName",
 "PropertyName": "DecimalPropertyName"
 }
 }
}

### Composer DateTimeOffSetプロパティのマッピング例

以下は、DateTimeOffSetデータ型として定義されたカスタムカタログエンティティプロパティを適切なインデックスフィールドタイプにマッピングする構成例を示しています。

{
 "$type":
"Sitecore.Commerce.Plugin.Search.Solr.SolrIndexFieldConfiguration,
Sitecore.Commerce.Plugin.Search.Solr",
 "Name": "DateTimeOffsetPropertyIndexName",
 "Type": "System.DateTimeOffset",
 "Handler": {
 "$type": "Sitecore.Commerce.Plugin.Catalog.ComposerFieldHandler,Sitecore.Commerce.Plugin.Catalog",
 "ComposerSource": {
 "ViewName": "MyViewName",
 "PropertyName": "DateTimeOffsetPropertyName"
 }
 }
}

### Composer Booleanプロパティの写像の例

以下は、ブール型として定義されたカスタムカタログエンティティプロパティを適切なインデックスフィールドタイプにマッピングする構成例を示しています。

{
 "$type":
"Sitecore.Commerce.Plugin.Search.Solr.SolrIndexFieldConfiguration,
Sitecore.Commerce.Plugin.Search.Solr",
 "Name": "BooleanPropertyIndexName",
 "Type": "System.Boolean",
 "Handler": {
 "$type": "Sitecore.Commerce.Plugin.Catalog.ComposerFieldHandler, Sitecore.Commerce.Plugin.Catalog",
 "ComposerSource": {
 "ViewName": "MyViewName",
 "PropertyName": "BooleanPropertyName"
 }
 }

## Solr構成の更新

Solrを使っていて、このフィールドをファセットに使いたい場合は、新しいフィールドとデータ型を定義する構成パッチファイルを作成しなければなりません。設定ファイルを /App\_Config/Include/Z.Commerce.Engineフォルダに入れてください。以下のコードは構成パッチファイルの例です:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:search="http://www.sitecore.net/xmlconfig/search/" xmlns:role="http://www.sitecore.net/xmlconfig/role/">

 <sitecore role:require="Standalone or ContentDelivery or ContentManagement" search:require="solr">
 <contentSearch>
 <indexConfigurations>
 <defaultSolrIndexConfiguration type="Sitecore.ContentSearch.SolrProvider.SolrIndexConfiguration, Sitecore.ContentSearch.SolrProvider">
 <fieldMap type="Sitecore.ContentSearch.SolrProvider.SolrFieldMap, Sitecore.ContentSearch.SolrProvider">
 <fieldNames hint="raw:AddFieldByFieldName">
 <field fieldName="stringpropertysolr" storageType="YES" indexType="TOKENIZED" vectorType="NO" boost="1f" returnType="string" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider"/>
 </fieldNames>
 </fieldMap>
 </defaultSolrIndexConfiguration>
 </indexConfigurations>
 </contentSearch>
 </sitecore>
</configuration>

## Azure構成の更新

Azureデプロイメントでは、インデックスに新しいフィールドを追加する際に、新しいフィールドやデータ型を定義する設定パッチファイルを作成し、その設定ファイルを */App\_Config/Include/Z.Commerce.Engine/* フォルダに入れる必要があります。

以下は構成パッチファイルの例です。 <fieldMap> と <documentOptions>のセクションでAzureの新しいフィールドとフィールドタイプのマッピングを定義します。

<configuration
xmlns:patch="http://www.sitecore.net/xmlconfig/"
xmlns:search="http://www.sitecore.net/xmlconfig/search/"
xmlns:role="http://www.sitecore.net/xmlconfig/role/">
 <sitecore role:require="Standalone or ContentDelivery or ContentManagement" search:require="azure">
 <contentSearch>
 <indexConfigurations>
 <defaultCloudIndexConfiguration type="Sitecore.ContentSearch.Azure.CloudIndexConfiguration,
Sitecore.ContentSearch.Azure">
 <fieldMap
type="Sitecore.ContentSearch.Azure.FieldMaps.CloudFieldMap,
Sitecore.ContentSearch.Azure">
 <fieldNames
hint="raw:AddFieldByFieldName">
 <field fieldName="stringpropertyazure" boost="1f" Type="System.String" settingType="Sitecore.Commerce.Engine.Connect.Search.CommerceCloudSearchFieldConfiguration,Sitecore.Commerce.Engine.Connect"/>
 <field fieldName="integerpropertyazure" boost="1f"
type="System.Int32"
settingType="Sitecore.Commerce.Engine.Connect.Search.CommerceCloudSearchFieldConfiguration,Sitecore.Commerce.Engine.Connect"/>
 <field fieldName="decimalpropertyazure" boost="1f"
type="System.Double"
settingType="Sitecore.Commerce.Engine.Connect.Search.CommerceCloudSearchFieldConfiguration,Sitecore.Commerce.Engine.Connect"/>
 <field fieldName="datetimeoffsetpropertyazure" boost="1f"
type="System.DateTimeOffset"
settingType="Sitecore.Commerce.Engine.Connect.Search.CommerceCloudSearchFieldConfiguration,Sitecore.Commerce.Engine.Connect"/>
 <field fieldName="booleanpropertyazure" boost="1f"
type="System.Boolean"
settingType="Sitecore.Commerce.Engine.Connect.Search.CommerceCloudSearchFieldConfiguration,Sitecore.Commerce.Engine.Connect"/>
 </fieldNames>
 </fieldMap>
 <documentOptions
type="Sitecore.ContentSearch.DocumentBuilderOptions,
Sitecore.ContentSearch">
 <fields hint="raw:AddComputedIndexField">
 <field fieldName="stringpropertyazure"
returnType="string">Sitecore.Commerce.Engine.Connect.Search.ComputedFields.CommerceComputedStringField, Sitecore.Commerce.Engine.Connect</field>
 <field fieldName="integerpropertyazure"
returnType="int">Sitecore.Commerce.Engine.Connect.Search.ComputedFields.CommerceComputedInt32Field, Sitecore.Commerce.Engine.Connect</field>
 <field fieldName="decimalpropertyazure"
returnType="double">Sitecore.Commerce.Engine.Connect.Search.ComputedFields.CommerceComputedDoubleField, Sitecore.Commerce.Engine.Connect</field>
 <field fieldName="datetimeoffsetpropertyazure"
returnType="string">Sitecore.Commerce.Engine.Connect.Search.ComputedFields.CommerceComputedDateTimeField, Sitecore.Commerce.Engine.Connect</field>
 <field fieldName="booleanpropertyazure"
returnType="bool">Sitecore.Commerce.Engine.Connect.Search.ComputedFields.CommerceComputedBooleanField, Sitecore.Commerce.Engine.Connect</field>
 </fields>
 </documentOptions>
 </defaultCloudIndexConfiguration>
 </indexConfigurations>
 </contentSearch>
 </sitecore>
</configuration>