Module: Redd::Models::Searchable

Included in:
Session, Subreddit
Defined in:
lib/redd/models/searchable.rb

Overview

Applied to Session for site-wide and Subreddit for subreddit-specific search.

Instance Method Summary collapse

Instance Method Details

#search(query, **params) ⇒ Listing<Comment, Submission>

Search reddit.

Parameters:

  • query (String)

    the search query

  • params (Hash)

    the search params

Options Hash (**params):

  • :syntax (:cloudsearch, :lucene, :plain)

    the query's syntax

  • :after (String)

    return results after the given fullname

  • :before (String)

    return results before the given fullname

  • :count (Integer)

    the number of items already seen in the listing

  • :limit (1..100)

    the maximum number of things to return

  • :time (:hour, :day, :week, :month, :year, :all)

    the time period to restrict search results by

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

    the sort order of results

  • :restrict_to (String)

    restrict by subreddit (prefer Redd::Models::Subreddit#search)

Returns:

See Also:


22
23
24
25
26
27
28
29
30
31
32
# File 'lib/redd/models/searchable.rb', line 22

def search(query, **params)
  params[:q] = query
  params[:t] = params.delete(:time) if params.key?(:time)
  if params[:restrict_to]
    subreddit = params.delete(:restrict_to)
    params[:restrict_sr] = true
    @client.model(:get, "/r/#{subreddit}/search", params)
  else
    @client.model(:get, '/search', params)
  end
end