---
title: "ファセットマージハンドラーを作成する"
slug: "create-a-facet-merge-handler"
abstract: ""
---
# ファセットマージハンドラーを作成する

ファセットマージハンドラは、2つのコンタクトがマージされた際に特定のファセットに何が起こるべきかを決定します。ファセットマージハンドラはxConnect Collectionサービス上で設定され、マージ操作が提出されると実行されます。

> !重要すべての値の側面は自動的にマージされます。すべてのカスタムファセットに対して専用ハンドラーを作成する必要はありません。デフォルトの動作を上書きしたい場合を除いては。

以下の場合は、自分でマージハンドラーを作成するべきです:

-   [計算されたファセット](https://doc.sitecore.com/xp/ja/developers/93/sitecore-experience-platform/calculated-facets.html "Calculated facets")を作成しました。計算されたファセットは自動的にマージされません。
-   特定のファセットをデフォルトとは異なる方法でマージしたいのです。例えば、ソース値が常にターゲット値を上書きしてほしい場合もあります。

## 価値の側面を創出しましょう

using Sitecore.XConnect;

namespace Documentation
{
 public class CyclistProfile : Facet
 {
 public string BikeBrand { get; set; }
 public string StravaID { get; set; }
 public string NumberOfBikeRides { get; set; }
 }
}

## マージハンドラを実装する

示されたようにMergingCalculatedFacetHandlerを実装してください。

> !注UpdateFacet()メソッドからfalseを返してください。このメソッドは計算されたファセット計算にのみ使用されます。

using Sitecore.ContentTesting.Collection.Model.Plugins.Utils;
using Sitecore.ContentTesting.Model.xConnect;
using Sitecore.XConnect;
using Sitecore.XConnect.Service;

namespace Sitecore.Documentation.Plugins
{
 /// <summary>
 /// A processor to merge custom facet handler
 /// </summary>
 public class MergeCustomFacetHandler : MergingCalculatedFacetHandler<CyclistProfile>
 {
 public MergeCustomFacetHandler() : base("CyclistProfile", null)
 {
 }

 protected override bool UpdateFacet(CyclistProfile currentFacet, Interaction interaction)
 {
 // For calculated facets only
 // Return false as contact not changed by this method
 return false;
 }

 protected override bool Merge(CyclistProfile source, CyclistProfile target)
 {
 if (source == null || target == null)
 {
 // No contacts changed - return false
 return false;
 }

 // Add source and target values together
 target.NumberOfBikeRides += source.NumberOfBikeRides;

 // Return true if contact was changed
 return true;
 }
 }
}

## ファセットマージハンドラーの設定

1.  scという名前のファイルを作成します。 c:\\path\_to\_xconnect\\root\\App\_data\\config\\sitecore\\Collection\\CustomPlugins.xml 。
    
2.  以下の構成を貼り付け、ハイライトされた行を自分のハンドラーに置き換えます:
    
    <Settings>
     <Sitecore>
     <XConnect>
     <Collection>
     <Services>
     <IContactMergeHandler.MergeTestCombinationsHandler>
     <Type>Sitecore.Documentation.Plugins.MergeCustomFacetHandler, Sitecore.Documentation</Type>
     <As>Sitecore.XConnect.Service.IContactMergeHandler, Sitecore.XConnect.Service</As>
     <LifeTime>Singleton</LifeTime>
     </IContactMergeHandler.MergeTestCombinationsHandler>
     </Services>
     </Collection>
     </XConnect>
     </Sitecore>
    </Settings>
    
3.  scファイルをコピーしてください。CustomPlugins.xmlファイルをすべてのxConnect CollectionとSearchインスタンスにコピーしてください。
    
    > !注デフォルトのマージ面ハンドラはc:\\path\\toxconnect\\root\\App\_data\\config\\sitecore\\Collection\\scで設定されています。XConnect.Collection.Model.Plugins.xmlファイル。
    

## コンタクトマージとトラッカー

コンタクトマージはxConnectが所有し、匿名のコンタクトが既に存在するコンタットとして自分を識別した際にトラッカーによって呼び出されます。マージハンドラをテストするために[xConnect Client API](https://doc.sitecore.com/xp/ja/developers/93/sitecore-experience-platform/merge-contacts.html "Merge contacts")を使うことができます。