---
title: "ルールの追加"
slug: "adding-rules"
abstract: "Sitecore SearchのSearchとRecommendation APIを使って、検索結果にブラックリスト、ブースト、埋め込み、含め、ピン留めするルールを学びましょう。"
---
# ルールの追加

widget.items.search.ruleオブジェクトを使って、Sitecore Searchが特定の結果アイテムをどのように扱うかを設定できます。アイテムやカテゴリはブラックリスト、ブースト、埋め込み、含め、ピン留めが可能です。pinルールを除き、ルールが適用されるアイテムを指定するには、ruleオブジェクト内に[filterオブジェクト](https://doc.sitecore.com/search/ja/developers/search-developer-guide/integrating-using-rest-apis/using-the-search-and-recommendation-api-to-create-search-experiences/filtering-items-in-search-results.html "Filtering items in search results")をネストする必要があります。

このオブジェクトのデータモデルについては、[Search and Recommendation APIリファレン](https://doc.sitecore.com/search/en/developers/search-and-recommentation-api/index.html)スを参照してください。

> !注APIリクエストで通したルールは、Sitecore Searchで設定されたルールを上書きします。

## アイテムをスロットにブーストする

アイテムやカテゴリをスロットにブーストするには、widget.items.search.rule.boostオブジェクトを追加してください。ブーストしたい商品やカテゴリと、それらを表示したいスロットを指定する必要があります。

この例では、

-   productカテゴリのすべてのアイテムをブーストしたいです。
-   ブーストされたアイテムは検索結果の2番目と3番目のスロットに表示されるようにしたいです。

以下のコードはサンプルリクエストを示しています:

{
 "widget": {
 "items": 
 {
 "rfk\_id": "rfkid\_7",
 "entity": "content",
 "search": {
 "content": {},
 "rule": {
 "boost": 
 {
 "filter": {
 "type": "eq",
 "name": "type",
 "value": "products"
 },
 "slots": 
 2,
 3
 
 }
 
 }
 }
 }
 
 },
 "context": {
 "locale": {
 "country": "us",
 "language": "en"
 },
 "user": {
 "uuid": "159871551-1g-i4-4x-1p-f5tdhddqwvywv7b9g2vy-1664852644904"
 }
 }
}

以下はその要請への回答です:

{
 "rfk\_id": "rfkid\_7",
 "entity": "content",
 "content": 
 {
 "description": "Premier Assure is designed...",
 "id": "https\_\_\_www\_sitecore\_com\_activities",
 "image": "https:imageurl/activities/gettyimages-699087272-hero.jpg?md=20220921T172222Z",
 "image\_type": "Image",
 "image\_url": "www.imageur.com",
 "last\_modified": "2022-10-19 \`20:57\`:04Z",
 "source\_id": "407033",
 "subtitle": "Improve the quality of your Sitecore investment using a review-based approach.",
 "title": "Premier Assure services: assuring confidence in your investment",
 "type": "Knowledge Center",
 "url": "https://www.sitecore.com/activities"
 },
 {
 "description": "Sitecore CDP Connector for Responsys...",
 "id": "https\_\_\_www\_sitecore\_com\_products\_marketplace\_tap\_cdp\_sitecore-cdp-connector-for-responsys",
 "source\_id": "388218",
 "subtitle": null,
 "title": "Sitecore CDP Connector for Responsys",
 "type": "products",
 "url": "https://www.sitecore.com/products/marketplace/tap/cdp/sitecore-cdp-connector-for-responsys"
 },
 {
 "description": "Sitecore CDP Integration for Amazon Sagemaker...",
 "source\_id": "388218",
 "subtitle": null,
 "title": "Sitecore CDP Integration for Amazon Sagemaker",
 "type": "products",
 "url": "https://www.sitecore.com/products/marketplace/tap/cdp/sitecore-cdp-integration-for-amazon-sagemaker"
 },
 {
 "description": "Related topicsResource hubPersonalizationEnable customer connections with your brand...",
 "id": "https\_\_\_www\_sitecore\_com\_content-management",
 "image": "https:imageurl/content-gettyimages-691574517-original2.jpg?md=20220107T002955Z",
 "image\_type": "Image",
 "image\_url": "https:imageurl/588D7FE5D8C&t=544x310",
 "last\_modified": "2022-05-25 \`19:52\`:23Z",
 "source\_id": "407033",
 "subtitle": "Content fuels the digital experience in just about every industry.",
 "title": "Content resources",
 "type": "Knowledge Center",
 "url": "https://www.sitecore.com/content-management"
 }
 ...
 ,
 "total\_item": 5856,
 "limit": 10,
 "offset": 0
 }
 ,
 "dt": 109,
 "ts": 1669433189900
}

レスポンスcontentオブジェクトでは、2番目と3番目の結果項目、すなわちスロット2と3の項目にproduct項目が見られます。

## スロットなしでアイテムを強化する

スロットを指定せずにアイテムやカテゴリをブーストするには、widget.items.search.rule.boostオブジェクトを使います。ブーストしたい商品やカテゴリと、ブーストしたい重さを指定する必要があります。

この例では、

-   訪問者はキーワードの *内容*を検索します。
-   すべてのブログを *5*倍の重みでブーストしたいのです。

{
 "widget": {
 "items": 
 {
 "entity": "content",
 "rfk\_id": "rfkid\_7",
 "search": {
 "content": {},
 "rule": {
 "boost": 
 {
 "weight": 4,
 "filter": {
 "type": "eq",
 "name": "type",
 "value": "Blogs"
 }
 }
 
 },
 "personalization": {
 "fields": 
 "title",
 "type"
 
 },
 "limit": 10,
 "offset": 0,
 "query": {
 "keyphrase": "content"
 }
 },
 "sources": 
 "407033",
 "408162"
 
 }
 
 },
 "context": {
 "locale": {
 "country": "us",
 "language": "en"
 },
 "user": {
 "uuid": "159871551-ye-l5-4u-1p-0z7apweb0jxcibpfzr40-1663129543566"
 }
 }
}

## ブラックリスト入りの項目

アイテムやカテゴリのリストをブラックリストに載せるには、search.rule.blacklistオブジェクトを追加してください。これらのアイテムやカテゴリは検索結果には一度も表示されません。

この例では、型otherのすべてのコンテンツをブラックリストに入りたいです。以下のコードはサンプルリクエストを示しています:

{
 "widget": {
 "items": 
 {
 "rfk\_id": "rfkid\_7",
 "entity": "content",
 "search": {
 "content": {},
 "rule": {
 "blacklist": {
 "filter": {
 "type": "eq",
 "name": "type",
 "value": "other"
 }
 }
 }
 }
 }
 
 },
 "context": {
 "locale": {
 "country": "us",
 "language": "en"
 },
 "user": {
 "uuid": "159871551-1g-i4-4x-1p-f5tdhddqwvywv7b9g2vy-1664852644904"
 }
 }
}

以下はその要請への回答です:

{
 "widgets": 
 {
 "rfk\_id": "rfkid\_7",
 "entity": "content",
 "content": 
 {
 "description": "Discover top moments...",
 "id": "https\_\_\_www\_sitecore\_com",
 "image": "https:imageurl.com/sitecore-home-hero-v01-052722\_72dpi.jpg?md=20220627T124154Z",
 "last\_modified": "2022-11-18 \`16:46\`:12Z",
 "source\_id": "407033",
 "subtitle": "Digital Experience Platform and Content Hub that apply the power of data science and marketing technology to shape your business around new possibilities.",
 "title": "Turn consumers into fans",
 "type": "Others",
 "url": "https://www.sitecore.com"
 },
 {
 "description": "It captures data...",
 "id": "https\_\_\_www\_sitecore\_com\_blog\_digital-transformation\_7-business-benefits-of-a-customer-data-platform",
 "image": "https:imageurl.com/gettyimages-1299625060\_insights\_feature.png?md=20220224T144643Z",
 "image\_url": "https://imageurl.com/79E042A6C3001AB18B&t=544x310",
 "last\_modified": "2022-04-05 \`04:57\`:22Z",
 "product": "Customer Data Platform",
 "source\_id": "407033",
 "subtitle": "From smashing data silos and building loyalty, to driving revenue, our blog explores 7 transformative business effects of a customer data platform.",
 "title": "7 business benefits of a customer data platform",
 "type": "Others",
 "url": "https://www.sitecore.com/blog/digital-transformation/7-business-benefits-of-a-customer-data-platform"
 },

 ...
 ,
 "total\_item": 4934,
 "limit": 10,
 "offset": 0
 }
 ,
 "dt": 30,
 "ts": 1669054635432
}

オブジェクトcontent応答では、どの項目もotherのtypeを持っていないことがわかります。

## アイテムのピン留め

検索結果の特定のスロットにアイテムをピン留めするには、search.rule.pinオブジェクトを使い、使いたいスロットとピンしたいアイテムのIDを指定します。

この例では、クラウドコンピューティングに関するブログを2番目のスロットにピン留めしたいと思います。

以下のコードはサンプルリクエストを示しています:

{
 "widget": {
 "items": 
 {
 "rfk\_id": "rfkid\_7",
 "entity": "content",
 "sources": 
 "388218",
 "390565"
 ,
 "search": {
 "content": {},
 "rule": {
 "pin": 
 {
 "slot": 2,
 "id": "https\_\_\_www\_sitecore\_com\_blog\_cloud\_cloud-computing-in-business-and-the-future-of-cx"
 }
 
 }
 }
 }
 
 },
 "context": {
 "locale": {
 "country": "us",
 "language": "en"
 },
 "user": {
 "uuid": "159871551-1g-i4-4x-1p-f5tdhddqwvywv7b9g2vy-1664852644904"
 }
 }
}

以下はその要請への回答です:

{
 "widgets": 
 {
 "rfk\_id": "rfkid\_7",
 "entity": "content",
 "content": 
 {
 "description": "October 13, 2021...",
 "id": "https\_\_\_www\_sitecore\_com\_company\_news-events\_news\_2021\_10\_majority-of-mena-brands-changed-customer-experiences-due-to-the-pandemic",
 "source\_id": "388218",
 "subtitle": null,
 "title": "Khaleej Times: Majority of Mena brands changed customer experiences due to the pandemic",
 "type": "news",
 "url": "https://www.sitecore.com/company/news-events/news/2021/10/majority-of-mena-brands-changed-customer-experiences-due-to-the-pandemic"
 },
 {
 "description": "Companies that survived...",
 "id": "https\_\_\_www\_sitecore\_com\_blog\_cloud\_cloud-computing-in-business-and-the-future-of-cx",
 "image\_url": "https://imageurl/cloud-computing-in-business-and-the-future-of-cx/gettyimages-1209700460\_heromedium\_mb.jpg?mw=600&md=20211006T181735Z&hash=827DB91BE20225F7C4BEFDF36BDD0249&t=544x310",
 "source\_id": "388218",
 "subtitle": "How CIOs can lead organizational transformation starting with marketing.",
 "title": "Cloud computing in business and the future of CX",
 "type": "blogs",
 "url": "https://www.sitecore.com/blog/cloud/cloud-computing-in-business-and-the-future-of-cx"
 },

 ...
 ,
 "total\_item": 2881,
 "limit": 10,
 "offset": 0
 }
 ,
 "dt": 52,
 "ts": 1669054542978
}

レスポンスcontentオブジェクトの検索結果の2番目の項目として、必要なブログが2番目の項目として表示されています。