code: def search(self, query, subreddit=None, sort=None, syntax=None,
                 period=None, *args, **kwargs):
          params = {'q': query}
          if 'params' in kwargs:
              params.update(kwargs['params'])
              kwargs.pop('params')
          if sort:
              params['sort'] = sort
          if syntax:
              params['syntax'] = syntax
          if period:
              params['t'] = period
          if subreddit:
              params['restrict_sr'] = 'on'
              subreddit = six.text_type(subreddit)
          else:
              subreddit = 'all'
          url = self.config['search'].format(subreddit=subreddit)
          depth = 2
          while depth > 0:
              depth -= 1
              try:
                  for item in self.get_content(url, params=params, *args,
                                               **kwargs):
                      yield item
                  break
              except errors.RedirectException as exc:
                  parsed = urlparse(exc.response_url)
                  params = dict((k, ",".join(v)) for k, v in
                                parse_qs(parsed.query).items())
                  url = urlunparse(parsed[:3] + ("", "", ""))
                  if 'already_submitted' in params:
                      yield self.get_submission(url)
                      break