<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 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)