Module: RedditKit::Client::Search

Included in:
RedditKit::Client
Defined in:
lib/redditkit/client/search.rb

Overview

Methods for searching reddit’s links.

Instance Method Summary collapse

Instance Method Details

#search(query, options = {}) ⇒ RedditKit::PaginatedResponse

Search for links.

Parameters:

  • query (String)

    The search query.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • subreddit (String, RedditKit::Subreddit)

    The optional subreddit to search.

  • restrict_to_subreddit (true, false)

    Whether to search only in a specified subreddit.

  • limit (1..100)

    The number of links to return.

  • count (String)

    The number of results to return before or after. This is different from ‘limit`.

  • sort (relevance, new, hot, top, comments)

    The sorting order for search results.

  • before (String)

    Only return links before this full name.

  • after (String)

    Only return links after this full name.

  • syntax (cloudsearch, lucene, plain)
  • time (hour, day, week, month, year, all)

    Show results with a specific time period.

Returns:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/redditkit/client/search.rb', line 20

def search(query, options = {})
  path = "%s/search.json" % ('r/' + options[:subreddit] if options[:subreddit])
  parameters = { :q => query,
                 :restrict_sr => options[:restrict_to_subreddit],
                 :limit       => options[:limit],
                 :count       => options[:count],
                 :sort        => options[:sort],
                 :before      => options[:before],
                 :after       => options[:after],
                 :syntax      => options[:syntax],
                 :t           => options[:time]
  }

  objects_from_response(:get, path, parameters)
end