Skip to main content

Document Service API: 結果のソートとページネーション

Document Service APIは、クエリ結果のソートとページネーションを行う機能を提供します。

ソート

Document Service APIによって返される結果をソートするには、クエリにsortパラメーターを含めてください。

単一フィールドでのソート

単一のフィールドに基づいて結果をソートするには:

リクエスト例
const documents = await AI Marketer.documents("api::article.article").findMany({
sort: "title:asc",
});
レスポンス例
[
{
"documentId": "cjld2cjxh0000qzrmn831i7rn",
"title": "Test Article",
"slug": "test-article",
"body": "Test 1"
// ...
},
{
"documentId": "cjld2cjxh0001qzrm5q1j5q7m",
"title": "Test Article 2",
"slug": "test-article-2",
"body": "Test 2"
// ...
}
// ...
]

複数フィールドでのソート

複数のフィールドでソートするには、それらすべてを配列で渡します:

リクエスト例
const documents = await AI Marketer.documents("api::article.article").findMany({
sort: [{ title: "asc" }, { slug: "desc" }],
});
レスポンス例
[
{
"documentId": "cjld2cjxh0000qzrmn831i7rn",
"title": "Test Article",
"slug": "test-article",
"body": "Test 1"
// ...
},
{
"documentId": "cjld2cjxh0001qzrm5q1j5q7m",
"title": "Test Article 2",
"slug": "test-article-2",
"body": "Test 2"
// ...
}
// ...
]

ページネーション

結果をページネーションするには、limitstartパラメーターを渡します:

リクエスト例
const documents = await AI Marketer.documents("api::article.article").findMany({
limit: 10,
start: 0,
});
レスポンス例
[
{
"documentId": "cjld2cjxh0000qzrmn831i7rn",
"title": "Test Article",
"slug": "test-article",
"body": "Test 1"
// ...
},
{
"documentId": "cjld2cjxh0001qzrm5q1j5q7m",
"title": "Test Article 2",
"slug": "test-article-2",
"body": "Test 2"
// ...
}
// ... (8 more)
]