Discourses API get just the number of search results

@sam님 감사합니다! (GET 요청만 봐도) 꽤 직관적이라는 것을 알 수 있습니다. 2페이지를 가져오려면 page 옵션을 추가로 추가하면 됩니다. 또한 discourse_api 함수로 "options"를 정의할 수 있다는 것도 확인할 수 있습니다:

# frozen_string_literal: true
module DiscourseApi
  module API
    module Search
      # Returns search results that match the specified term.
      #
      # @param term [String] a search term
      # @param options [Hash] A customizable set of options
      # @option options [String] :type_filter Returns results of the specified type.
      # @return [Array] Return results as an array of Hashes.
      def search(term, options = {})
        raise ArgumentError.new("#{term} is required but not specified") unless term
        raise ArgumentError.new("#{term} is required but not specified") unless !term.empty?

        response = get('/search/query', options.merge(term: term))
        response[:body]
      end
    end
  end
end

그러면 - 이걸 시도해 보면, 1페이지와 2페이지에서 서로 다른 결과가 나올 것으로 예상합니다. 아니면 조금 더 간격을 두고 1페이지와 3페이지를 시도해 보겠습니다. 쿼리는 모든 Q&A 주제에 대한 것입니다:

 query = category["name"] + " #" + category["slug"]
=> "Q&A #q-a"

이제 discourse_api 클라이언트를 사용하여 1페이지와 3페이지를 가져오겠습니다:

topics1 = client.search(query, options={"page": "1"})
topics3 = client.search(query, options={"page": "3"})

각 페이지의 첫 번째 주제를 확인할 수 있습니다:

=> {"id"=>220, "title"=>"Why am I exceeding the quota?", "fancy_title"=>"Why am I exceeding the quota?", "slug"=>"why-am-i-exceeding-the-quota", "posts_count"=>3, "reply_count"=>0, "highest_post_number"=>3, "image_url"=>nil, "created_at"=>"2018-06-01T12:56:12.120Z", "last_posted_at"=>"2018-06-15T16:41:44.736Z", "bumped"=>true, "bumped_at"=>"2018-06-15T16:41:44.736Z", "unseen"=>false, "pinned"=>false, "unpinned"=>nil, "visible"=>true, "closed"=>false, "archived"=>false, "bookmarked"=>nil, "liked"=>nil, "tags"=>["storage", "quota"], "category_id"=>26, "has_accepted_answer"=>false}

irb(main):148:0> topics3['topics'][0]
=> {"id"=>220, "title"=>"Why am I exceeding the quota?", "fancy_title"=>"Why am I exceeding the quota?", "slug"=>"why-am-i-exceeding-the-quota", "posts_count"=>3, "reply_count"=>0, "highest_post_number"=>3, "image_url"=>nil, "created_at"=>"2018-06-01T12:56:12.120Z", "last_posted_at"=>"2018-06-15T16:41:44.736Z", "bumped"=>true, "bumped_at"=>"2018-06-15T16:41:44.736Z", "unseen"=>false, "pinned"=>false, "unpinned"=>nil, "visible"=>true, "closed"=>false, "archived"=>false, "bookmarked"=>nil, "liked"=>nil, "tags"=>["storage", "quota"], "category_id"=>26, "has_accepted_answer"=>false}

완전히 동일합니다. 이는 page 변수가 작동하지 않는다는 뜻인 것 같습니다. Chrome 개발자 도구를 검사하면, 포스트가 창에서 자동으로 로드되므로 아래로 스크롤할 때 포인트가 트리거된다는 것을 확인할 수 있으며, page=2가 올바른 파라미터임을 확인할 수 있습니다:

Request URL: https://ask.cyberinfrastructure.org/search?q=Q%26A%20%23q-a&page=2
Request Method: GET
Status Code: 200  (from ServiceWorker)
Referrer Policy: strict-origin-when-cross-origin

아니면 더 좋게, 파라미터 목록을 보면 됩니다:

Query String Parameters
q: Q&A #q-a
page: 2

이것은 폼 제출이 아니므로, 예시에서처럼 "Form Data"를 볼 수 없습니다.