docs: def search(request, abbr):
      '''
      Context:
          - search_text
          - abbr
          - metadata
          - found_by_id
          - bill_results
          - more_bills_available
          - legislators_list
          - nav_active
  
      Tempaltes:
          - billy/web/public/search_results_no_query.html
          - billy/web/public/search_results_bills_legislators.html
          - billy/web/public/bills_list_row_with_abbr_and_session.html
      '''
      if not request.GET:
          return render(request, templatename('search_results_no_query'),
                        {'abbr': abbr})
  
      search_text = unicode(request.GET['search_text']).encode('utf8')
  
      # First try to get by bill_id.
      if re.search(r'\d', search_text):
          url = '/%s/bills?' % abbr
          url += urllib.urlencode([('search_text', search_text)])
          return redirect(url)
  
      else:
          found_by_id = False
          kwargs = {}
          if abbr != 'all':
              kwargs['abbr'] = abbr
          bill_results = Bill.search(search_text, sort='last', **kwargs)
  
          # Limit the bills if it's a search.
          bill_result_count = len(bill_results)
          more_bills_available = (bill_result_count > 5)
          bill_results = bill_results[:5]
  
          # See if any legislator names match. First split up name to avoid
          # the Richard S. Madaleno problem. See Jira issue OS-32.
          textbits = search_text.split()
          textbits = filter(lambda s: 2 < len(s), textbits)
          textbits = filter(lambda s: '.' not in s, textbits)
          andspec = []
          for text in textbits:
              andspec.append({'full_name': {'$regex': text, '$options': 'i'}})
          if andspec:
              spec = {'$and': andspec}
          else:
              spec = {'full_name': {'$regex': search_text, '$options': 'i'}}
  
          # Run the query.
          if abbr != 'all':
              spec[settings.LEVEL_FIELD] = abbr
          legislator_results = list(db.legislators.find(spec).sort(
              [('active', -1)]))
  
      if abbr != 'all':
          metadata = Metadata.get_object(abbr)
      else:
          metadata = None
  
      return render(
          request, templatename('search_results_bills_legislators'),
          dict(search_text=search_text,
               abbr=abbr,
               metadata=metadata,
               found_by_id=found_by_id,
               bill_results=bill_results,
               bill_result_count=bill_result_count,
               more_bills_available=more_bills_available,
               legislators_list=legislator_results,
               column_headers_tmplname=None,  # not used
               rowtemplate_name=templatename('bills_list_row_with'
                                             '_abbr_and_session'),
               show_chamber_column=True,
               nav_active=None))