شكرًا لك يا @sam! يمكنني أن أرى (حتى من طلب GET) أن الأمر يجب أن يكون بديهيًا إلى حد ما - عندما أريد الحصول على الصفحة 2، أضيف خيارًا إضافيًا للصفحة. كما يمكنني أيضًا رؤية أن “الخيارات” شيء يمكنني تعريفه باستخدام دالة discourse_api:
# 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. الاستعلام هو عن جميع مواضيع الأسئلة والأجوبة:
query = category["name"] + " #" + category["slug"]
=> "Q&A #q-a"
الآن دعنا نسترجع الصفحتين 1 و 3 باستخدام عميل discourse_api:
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}
هي نفسها تمامًا، مما أعتقد أنه يعني أن متغير الصفحة لا يعمل؟ عندما أفحص في أدوات مطوري 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
هذا ليس نموذج إرسال، لذا لا أرى أي “بيانات نموذج” حسب المثال.