コンテンツの並べ替え

日本語翻訳に関する免責事項

このページの翻訳はAIによって自動的に行われました。可能な限り正確な翻訳を心掛けていますが、原文と異なる表現や解釈が含まれる場合があります。正確で公式な情報については、必ず英語の原文をご参照ください。

リクエストにwidget.items.search.sortオブジェクトを追加して、コンテンツをソートする、つまり、検索結果に表示される順序を決定できます。

メモ

コンテンツを並べ替える前に、管理者がSearchで並べ替えオプションを設定していることを確認してください。

widget.items.search.sortオブジェクトを使用する場合は、ソート オプションの名前をsort.value.nameとして渡します。

このオブジェクトのデータモデルについては、Search and Recommendation APIリファレンス を参照してください。

この例では、次のことを行います。

  • すべての結果をアルファベットの昇順に並べ替えます。以前に作成したtitleという並べ替えオプションがあります。要求では、titlenameとして渡し、ascorderとして渡します。

  • タイトルのみを取得します。このためには、widget.items.search.contentオブジェクトを使用し、fields配列にtitle渡します。

次のコード サンプルは、要求を作成する方法を示しています。

{
    "widget": {
        "items": [
            {
                "rfk_id": "rfkid_7",
                "entity": "content",
                "search": {
                    "content": {
                        "fields": [
                            "title"
                        ]
                    },
                    "sort": {
                        "value": [
                            {
                                "name": "title",
                                "order": "asc"
                            }
                        ]
                    },
                    "limit": 3,
                    "offset": 0
                }
            }
        ]
    },
    "context": {
        "locale": {
            "country": "us",
            "language": "en"
        },
        "user": {
            "uuid": "159871551-1g-i4-4x-1p-f5tdhddqwvywv7b9g2vy-1664852644904"
        }
    }

要求に対する応答は次のとおりです。

{
    "widgets": [
        {
            "rfk_id": "rfkid_7",
            "entity": "content",
            "content": [
                {
                    "id": "https___www_sitecore_com_knowledge-center_blog_2019_10_commerce-twitter-chat",
                    "source_id": "388218",
                    "title": "#ReinventingCommerce"
                },
                {
                    "id": "https___www_sitecore_com_knowledge-center_blog_2019_10_commerce-twitter-chat",
                    "source_id": "407033",
                    "title": "#ReinventingCommerce"
                },
                {
                    "id": "https___www_sitecore_com_webinars_2019_modular-content-creation-for-better-omni-channel",
                    "source_id": "388218",
                    "title": "**You need modular content creation for better omnichannel**"
                }
            ],
            "total_item": 5858,
            "limit": 3,
            "offset": 0
        }
    ],
    "dt": 66,
    "ts": 1669436439108
}

応答widgets.contentオブジェクトでは、すべてのコンテンツがtitleのアルファベット順で並べ替えられていることがわかります。

この記事を改善するための提案がある場合は、 お知らせください!