Index: wp-includes/query.php
===================================================================
--- wp-includes/query.php	(revision 21569)
+++ wp-includes/query.php	(working copy)
@@ -2185,9 +2185,11 @@
 				preg_match_all('/".*?("|$)|((?<=[\r\n\t ",+])|^)[^\r\n\t ",+]+/', $q['s'], $matches);
 				$q['search_terms'] = array_map('_search_terms_tidy', $matches[0]);
 			}
+			$q['search_terms'] = array_filter( (array) $q['search_terms'] );
+
 			$n = !empty($q['exact']) ? '' : '%';
 			$searchand = '';
-			foreach( (array) $q['search_terms'] as $term ) {
+			foreach ( $q['search_terms'] as $term ) {
 				$term = esc_sql( like_escape( $term ) );
 				$search .= "{$searchand}(($wpdb->posts.post_title LIKE '{$n}{$term}{$n}') OR ($wpdb->posts.post_content LIKE '{$n}{$term}{$n}'))";
 				$searchand = ' AND ';
@@ -2377,6 +2379,35 @@
 				$orderby .= " {$q['order']}";
 		}
 
+		// Order search results by relevance
+		if ( !empty( $q['search_terms'] ) && empty( $q['exact'] ) ) {
+			$orderby_search = '(CASE ';
+
+			if ( count($q['search_terms']) > 1 ) {
+				$orderby_search_s = esc_sql( like_escape( $q['s'] ) );
+				$orderby_search .= "WHEN $wpdb->posts.post_title LIKE '%$orderby_search_s%' THEN 1 ";
+				$orderby_search .= "WHEN $wpdb->posts.post_content LIKE '%$orderby_search_s%' THEN 2 ";
+			}
+
+			$orderby_search_title = $orderby_search_content = array();
+
+			foreach ( $q['search_terms'] as $term ) {
+				$term = esc_sql( like_escape( $term ) );
+				$orderby_search_title[] = "$wpdb->posts.post_title LIKE '%$term%'";
+				$orderby_search_content[] = "$wpdb->posts.post_content LIKE '%$term%'";
+			}
+
+			$orderby_search .= 'WHEN ' . implode( ' AND ', $orderby_search_title ) . ' THEN 3 ';
+			$orderby_search .= 'WHEN ' . implode( ' AND ', $orderby_search_content ) . ' THEN 4 ';
+
+			if ( count($q['search_terms']) > 1 )
+				$orderby_search .= 'WHEN ' . implode( ' OR ', $orderby_search_title ) . ' THEN 5 ';
+
+			$orderby_search .= 'ELSE 6 END), ';
+
+			$orderby = $orderby_search . $orderby;
+		}
+
 		if ( is_array( $post_type ) ) {
 			$post_type_cap = 'multiple_post_type';
 		} else {
