nodes: 0, module; 1, function_definition; 2, function_name:search; 3, parameters; 4, block; 5, identifier:query; 6, default_parameter; 7, expression_statement; 8, comment:# Build the SQL statement.; 9, expression_statement; 10, comment:# Execute the SQL.; 11, if_statement; 12, with_statement; 13, comment:# Wrap the SQL results.; 14, return_statement; 15, identifier:query_type; 16, identifier:DEFAULT_QUERY_TYPE; 17, comment:"""Search database using parsed query.
  
      Executes a database search query from the given ``query``
      (a ``Query`` object) and optionally accepts a list of search weights.
      By default, the search results are ordered by weight.
  
      :param query: containing terms, filters, and sorts.
      :type query: Query
      :returns: a sequence of records that match the query conditions
      :rtype: QueryResults (which is a sequence of QueryRecord objects)
      """; 18, assignment; 19, boolean_operator; 20, block; 21, with_clause; 22, block; 23, call; 24, pattern_list; 25, call; 26, comparison_operator:statement is None; 27, comparison_operator:arguments is None; 28, return_statement; 29, with_item; 30, with_statement; 31, identifier:QueryResults; 32, argument_list; 33, identifier:statement; 34, identifier:arguments; 35, identifier:_build_search; 36, argument_list; 37, identifier:statement; 38, None; 39, identifier:arguments; 40, None; 41, call; 42, as_pattern; 43, with_clause; 44, block; 45, identifier:search_results; 46, identifier:query; 47, identifier:query_type; 48, identifier:query; 49, identifier:QueryResults; 50, argument_list; 51, call; 52, as_pattern_target; 53, with_item; 54, expression_statement; 55, expression_statement; 56, list; 57, list; 58, string; 59, identifier:db_connect; 60, argument_list; 61, identifier:db_connection; 62, as_pattern; 63, call; 64, assignment; 65, string_content:AND; 66, call; 67, as_pattern_target; 68, attribute; 69, argument_list; 70, identifier:search_results; 71, call; 72, attribute; 73, argument_list; 74, identifier:cursor; 75, identifier:cursor; 76, identifier:execute; 77, identifier:statement; 78, identifier:arguments; 79, attribute; 80, argument_list; 81, identifier:db_connection; 82, identifier:cursor; 83, identifier:cursor; 84, identifier:fetchall
code: def search(query, query_type=DEFAULT_QUERY_TYPE):
      """Search database using parsed query.
  
      Executes a database search query from the given ``query``
      (a ``Query`` object) and optionally accepts a list of search weights.
      By default, the search results are ordered by weight.
  
      :param query: containing terms, filters, and sorts.
      :type query: Query
      :returns: a sequence of records that match the query conditions
      :rtype: QueryResults (which is a sequence of QueryRecord objects)
      """
  
      # Build the SQL statement.
      statement, arguments = _build_search(query)
  
      # Execute the SQL.
      if statement is None and arguments is None:
          return QueryResults([], [], 'AND')
      with db_connect() as db_connection:
          with db_connection.cursor() as cursor:
              cursor.execute(statement, arguments)
              search_results = cursor.fetchall()
      # Wrap the SQL results.
      return QueryResults(search_results, query, query_type)