# Discourses API get just the number of search results

**URL:** <https://meta.discourse.org/t/discourses-api-get-just-the-number-of-search-results/76548>\
**Category:** Development\
**Tags:** rest-api\
**Created:** [2017 年12 月 21 日 10:18 UTC](https://meta.discourse.org/t/discourses-api-get-just-the-number-of-search-results/76548 "2017-12-21T10:18:45Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

作者： ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
发布日期： [2019 年10 月 18 日 22:27 UTC](https://meta.discourse.org/t/discourses-api-get-just-the-number-of-search-results/76548/7 "2019-10-18T22:27:25Z")

</div>

> [@vsoch](#):
>
> 当通过请求传入时，page 变量似乎不起作用。

Discourse API gem 使用的是 `/search/query` 路由。它[似乎不支持分页](https://github.com/discourse/discourse/blob/master/app/controllers/search_controller.rb#L68)。而 Discourse UI 使用的是 `/search` 路由，它[支持分页](https://github.com/discourse/discourse/blob/master/app/controllers/search_controller.rb#L13)。

你可以在浏览器中测试这一点：访问 `http://forum.example.com/search.json?q=test`，然后尝试 `http://forum.example.com/search.json?q=test&page=2`。

你可能需要找到一种不使用 Discourse API gem 的方式来调用 API。如果你的目标是获取站点上的所有主题和帖子，使用 `/search` 路由似乎并不是最佳方案。

你可以尝试调用 `http://forum.example.com/c/your-category-slug.json`。如果该请求未返回类别中的所有主题，则响应的 `topic_list` 中将包含一个 `more_topics_url` 属性，该属性会提供下一页主题的链接，例如 `"/c/site-feedback?page=2"`。你需要在 URL 后添加 `.json` 以获取 JSON 数据（例如 `/c/site-feedback.json?page=2`）。

---

_[View the full topic](https://meta.discourse.org/t/discourses-api-get-just-the-number-of-search-results/76548)._
