Struggling with pagination within search/query.json

AI-generated summary

The discussion revolves around challenges with pagination in the Discourse API, particularly when using search/query.json to retrieve posts within a date range. danielt initially struggled with pagination, noting that page 2 and page 3 returned identical results for complex queries, unlike simpler searches. vinothkannans clarified that the query string should use & instead of ? for subsequent pages, correcting the URL structure. pfaffman shared a Ruby script for downloading topics, though it doesn’t handle date filtering. danielt acknowledged the mistake in URL formatting and questioned how to access additional posts when more_posts is true. sam confirmed pagination support and referenced the Discourse API documentation. faheem asked about the meaning of term in the API, and blake explained that term refers to a search query, not a time period, and suggested reverse-engineering the UI’s API calls to understand pagination. faheem expressed a desire to fetch all topics in a category at once, but blake clarified that multiple API calls are necessary due to performance constraints, and suggested using data explore queries as an alternative.

I’m trying to grab the posts within a date interval from our discourse server using the API. I’m struggling quite a lot with pagination.

Firstly I tried using search.json but that limits us to 50 results:
https://meta.discourse.org/search.json?q=after:2016-01-01%20before:2017-01-01

I tried to use the paginated query instead (but page 2 and page 3 end up the same for some queries):
https://meta.discourse.org/search/query.json?term=after:2016-01-01%20before:2017-01-01
https://meta.discourse.org/search/query.json?term=after:2016-01-01%20before:2017-01-01?page=2
https://meta.discourse.org/search/query.json?term=after:2016-01-01%20before:2017-01-01?page=3

That’s odd because simpler queries appear to paginate correctly:
https://meta.discourse.org/search/query.json?term=API
https://meta.discourse.org/search/query.json?term=API?page=2
https://meta.discourse.org/search/query.json?term=API?page=3
https://meta.discourse.org/search/query.json?term=API?page=51 (more_pages becomes null here, although we can fetch higher pages)

Is is possible to combine advanced search and pagination?

Second (3rd, 4th, etc.,) query string should look like below. & symbol instead of ?

https://meta.discourse.org/search/query.json?term=after:2016-01-01%20before:2017-01-01&page=2
https://meta.discourse.org/search/query.json?term=API&page=2

not like this

https://meta.discourse.org/search/query.json?term=after:2016-01-01%20before:2017-01-01?page=2
https://meta.discourse.org/search/query.json?term=API?page=2

I don’t know if it’ll help, but I wrote a little ruby program that will download all of a topic or category. (It doesn’t pay attention to dates, though.)

Oops. Getting the links wrong is what made me believe discourse support pagination using page=X in the first place (my own bad conversion from curl to a web browser).

Perhaps I should have ask a more general question: If search/query.json has a grouped_search_result with more_posts set true, how do I get to see the additional posts?

I know this is quite late, but yes we certainly support pagination now, search for something with lots of results and then use:

Reverse engineer the Discourse API

To find all the endpoints.

Discourse API の使い方を理解しようとしています。
以下の URL では、term は期間や時間枠を指すのだと推測しています。これは erm=after:2016-01-01%20before:2017-01-01 などの表記に基づいています。しかし、term=API が何を指すのかは明確ではありません。どなたか解説していただけませんか?

実際には、2 つの検索エンドポイントがあります。/search.json?q= と /search/query?term= です。

term は単に検索語を意味し、期間や時間には関係ありません。

検索 API を理解するには、Reverse engineer the Discourse API に従い、API を通じて行いたい検索を実行し、UI がどのように同じ API リクエストを行っているかを確認するのが最善です。

@blake さん、こんにちは
返信ありがとうございます。

実は、ページ全体のコンテンツ(私の場合はカテゴリ内のトピック一覧、Obtaining a list of topics from a category を参照)を取得したいと考えています。可能であれば、ページを一つずつ処理したくありません。また、この場合、リバースエンジニアリングは機能しないと思います。Discourse はスクロールに応じてページを動的に展開するだけで、ページ全体を表示するオプションは私の知る限り存在しないからです。これを実現する方法はありますか?

カテゴリのすべてのトピックを取得する単一の API 呼び出しはありません。複数の API 呼び出しを行う必要があります。これは、カテゴリに 100 万件以上のトピックが含まれている可能性があり、その場合、大規模なクエリとなり、サイトのパフォーマンスに影響を与える可能性があるためです。スクロールをリバースエンジニアリングすると、Discourse UI が追加のトピックを取得するためにどのように API 呼び出しを行っているかがわかります。その動作を API で再現できます。

達成しようとしている内容によっては、カテゴリ内のトピック数を取得するためにデータエクスプローアクエリを使用し、保存されたクエリに対して API 呼び出しを行うこともできます。