def search(request, abbr):
if not request.GET:<EOL><INDENT>return render(request, templatename('<STR_LIT>'),<EOL>{'<STR_LIT>': abbr})<EOL><DEDENT>search_text = unicode(request.GET['<STR_LIT>']).encode('<STR_LIT:utf8>')<EOL>if re.search(r'<STR_LIT>', search_text):<EOL><INDENT>url = '<STR_LIT>' % abbr<EOL>url += urllib.urlencode([('<STR_LIT>', search_text)])<EOL>return redirect(url)<EOL><DEDENT>else:<EOL><INDENT>found_by_id = False<EOL>kwargs = {}<EOL>if abbr != '<STR_LIT:all>':<EOL><INDENT>kwargs['<STR_LIT>'] = abbr<EOL><DEDENT>bill_results = Bill.search(search_text, sort='<STR_LIT>', **kwargs)<EOL>bill_result_count = len(bill_results)<EOL>more_bills_available = (bill_result_count > <NUM_LIT:5>)<EOL>bill_results = bill_results[:<NUM_LIT:5>]<EOL>textbits = search_text.split()<EOL>textbits = filter(lambda s: <NUM_LIT:2> < len(s), textbits)<EOL>textbits = filter(lambda s: '<STR_LIT:.>' not in s, textbits)<EOL>andspec = []<EOL>for text in textbits:<EOL><INDENT>andspec.append({'<STR_LIT>': {'<STR_LIT>': text, '<STR_LIT>': '<STR_LIT:i>'}})<EOL><DEDENT>if andspec:<EOL><INDENT>spec = {'<STR_LIT>': andspec}<EOL><DEDENT>else:<EOL><INDENT>spec = {'<STR_LIT>': {'<STR_LIT>': search_text, '<STR_LIT>': '<STR_LIT:i>'}}<EOL><DEDENT>if abbr != '<STR_LIT:all>':<EOL><INDENT>spec[settings.LEVEL_FIELD] = abbr<EOL><DEDENT>legislator_results = list(db.legislators.find(spec).sort(<EOL>[('<STR_LIT>', -<NUM_LIT:1>)]))<EOL><DEDENT>if abbr != '<STR_LIT:all>':<EOL><INDENT>metadata = Metadata.get_object(abbr)<EOL><DEDENT>else:<EOL><INDENT>metadata = None<EOL><DEDENT>return render(<EOL>request, templatename('<STR_LIT>'),<EOL>dict(search_text=search_text,<EOL>abbr=abbr,<EOL>metadata=metadata,<EOL>found_by_id=found_by_id,<EOL>bill_results=bill_results,<EOL>bill_result_count=bill_result_count,<EOL>more_bills_available=more_bills_available,<EOL>legislators_list=legislator_results,<EOL>column_headers_tmplname=None,  <EOL>rowtemplate_name=templatename('<STR_LIT>'<EOL>'<STR_LIT>'),<EOL>show_chamber_column=True,<EOL>nav_active=None))<EOL>
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