Index: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php
===================================================================
--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php	(revision 2961)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php	(working copy)
@@ -76,6 +76,11 @@
 require __DIR__ . '/inc/autocomplete.php';
 
 /**
+ * Search query.
+ */
+require __DIR__ . '/inc/search.php';
+
+/**
  * Set the content width based on the theme's design and stylesheet.
  */
 if ( ! isset( $content_width ) ) {
@@ -97,8 +102,6 @@
 
 	add_filter( 'post_type_link', __NAMESPACE__ . '\\method_permalink', 10, 2 );
 	add_filter( 'term_link', __NAMESPACE__ . '\\taxonomy_permalink', 10, 3 );
-	add_filter( 'posts_orderby', __NAMESPACE__ . '\\search_posts_orderby', 10, 2 );
-	add_filter( 'the_posts', __NAMESPACE__ . '\\rerun_empty_exact_search', 10, 2 );
 
 	add_theme_support( 'automatic-feed-links' );
 	add_theme_support( 'post-thumbnails' );
@@ -201,132 +204,9 @@
 		$query->set( 'wp-parser-source-file', str_replace( array( '.php', '/' ), array( '-php', '_' ), $query->query['wp-parser-source-file'] ) );
 	}
 
-	if ( $query->is_search() ) {
-
-		// If user has '()' at end of a search string, assume they want a specific function/method.
-		$s = htmlentities( $query->get( 's' ) );
-		if ( '()' === substr( $s, -2 ) ) {
-			// Enable exact search
-			$query->set( 'exact',     true );
-			// Modify the search query to omit the parentheses
-			$query->set( 's',         substr( $s, 0, -2 ) ); // remove '()'
-			// Restrict search to function-like content
-			$query->set( 'post_type', array( 'wp-parser-function', 'wp-parser-method' ) );
-		}
-	}
+	// For search queries see DevHub_Search::pre_get_posts()
 }
 
-/**
- * Filter the SQL for the ORDER BY clause for search queries.
- *
- * Adds ORDER BY condition with spaces replaced with underscores in 'post_title'.
- * Adds ORDER BY condition to order by title length.
- *
- * @param string   $orderby The ORDER BY clause of the query.
- * @param WP_Query $query   The WP_Query instance (passed by reference).
- * @return string  Filtered order by clause
- */
-function search_posts_orderby( $orderby, $query ) {
-	global $wpdb;
-
-	if ( $query->is_main_query() && is_search() && ! $query->get( 'exact' ) ) {
-
-		$search_order_by_title = $query->get( 'search_orderby_title' );
-
-		// Check if search_orderby_title is set by WP_Query::parse_search.
-		if ( is_array( $search_order_by_title ) && $search_order_by_title ) {
-
-			// Get search orderby query.
-			$orderby = parse_search_order( $query->query_vars );
-
-			// Add order by title length.
-			$orderby .= " , CHAR_LENGTH( $wpdb->posts.post_title ) ASC, $wpdb->posts.post_title ASC";
-		}
-	}
-
-	return $orderby;
-}
-
-/**
- * Generate SQL for the ORDER BY condition based on passed search terms.
- *
- * Similar to WP_Query::parse_search_order.
- * Adds ORDER BY condition with spaces replaced with underscores in 'post_title'.
- *
- * @global wpdb $wpdb WordPress database abstraction object.
- *
- * @param array   $q Query variables.
- * @return string ORDER BY clause.
- */
-function parse_search_order( $q ) {
-	global $wpdb;
-
-	if ( $q['search_terms_count'] > 1 ) {
-		$num_terms = count( $q['search_orderby_title'] );
-
-		// If the search terms contain negative queries, don't bother ordering by sentence matches.
-		$like = $_like = '';
-		if ( ! preg_match( '/(?:\s|^)\-/', $q['s'] ) ) {
-			$like = '%' . $wpdb->esc_like( $q['s'] ) . '%';
-		}
-
-		$search_orderby = '';
-
-		// Sentence match in 'post_title'.
-		if ( $like ) {
-			$search_orderby .= $wpdb->prepare( "WHEN $wpdb->posts.post_title LIKE %s THEN 1 ", $like );
-			$_like =  str_replace( '-', '_', sanitize_title_with_dashes( $q['s'] ) );
-			$_like = '%' . $wpdb->esc_like( $_like ) . '%';
-			if ( $_like !== $like ) {
-				// Sentence match in 'post_title' with spaces replaced with underscores.
-				$search_orderby .= $wpdb->prepare( "WHEN $wpdb->posts.post_title LIKE %s THEN 2 ", $_like );
-			}
-		}
-
-		// Sanity limit, sort as sentence when more than 6 terms.
-		// (few searches are longer than 6 terms and most titles are not)
-		if ( $num_terms < 7 ) {
-			// all words in title
-			$search_orderby .= 'WHEN ' . implode( ' AND ', $q['search_orderby_title'] ) . ' THEN 3 ';
-			// any word in title, not needed when $num_terms == 1
-			if ( $num_terms > 1 )
-				$search_orderby .= 'WHEN ' . implode( ' OR ', $q['search_orderby_title'] ) . ' THEN 4 ';
-		}
-
-		// Sentence match in 'post_content'.
-		if ( $like ) {
-			$search_orderby .= $wpdb->prepare( "WHEN $wpdb->posts.post_content LIKE %s THEN 5 ", $like );
-		}
-
-		if ( $search_orderby ) {
-			$search_orderby = '(CASE ' . $search_orderby . 'ELSE 6 END)';
-		}
-	} else {
-		// Single word or sentence search.
-		$search_orderby = reset( $q['search_orderby_title'] ) . ' DESC';
-	}
-
-	return $search_orderby;
-}
-
-/**
- * Rerun an exact search with the same criteria except exactness if no posts
- * were found.
- *
- * @access public
- *
- * @param  array    $posts Array of posts after the main query
- * @param  WP_Query $query WP_Query object
- * @return array
- */
-function rerun_empty_exact_search( $posts, $query ) {
-	if ( is_search() && true === $query->get( 'exact' ) && ! $query->found_posts ) {
-		$query->set( 'exact', false );
-		$posts = $query->get_posts();
-	}
-	return $posts;
-}
-
 function register_nav_menus() {
 
 	\register_nav_menus( array(
Index: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php
===================================================================
--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php	(revision 2961)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php	(working copy)
@@ -380,6 +380,95 @@
 	}
 
 	/**
+	 * Checks if the current page is a handbook page.
+	 * 
+	 * @param  string  $post_type Optional. Handbook post type.
+	 * @return boolean            True if the current page is a handbook post type page.
+	 */
+	function is_handbook( $post_type = '' ) {
+		global $wp_rewrite;
+
+		$handbooks = get_handbook_post_types();
+
+		if ( is_admin() || empty( $handbooks ) ) {
+			return false;
+		}
+
+		$path = trailingslashit( $_SERVER['REQUEST_URI'] );
+
+		foreach ( $handbooks as $handbook ) {
+
+			if ( $wp_rewrite->using_permalinks() ) {
+
+				// plugins or themes (plural)
+				$struct = str_replace( '-handbook' , 's', $handbook );
+				$struct = preg_quote( $struct, '/' );
+
+				// match handbook. e.g. /plugins/ or /plugins? or /plugins#
+				if ( preg_match("/^\/{$struct}[\/|?|#]/", $path, $matches )  ) {
+					if ( !$post_type || ( $handbook === $post_type ) ) {
+						return true;
+					}
+				}
+			} else {
+				$qv_post_type = get_query_var( 'post_type' );
+				if ( ( $qv_post_type === $handbook ) || ( $qv_post_type === $post_type ) ) {
+					return true;
+				}
+			}
+		}
+
+		return false;
+	}
+
+	/**
+	 * Get the curent handbook post type.
+	 *  
+	 * @return string|bool Post type or false if current page is not a handbook page.
+	 */
+	function get_current_handbook_post_type() {
+		$handbooks = get_handbook_post_types();
+		foreach ( $handbooks as $handbook ) {
+			if ( is_handbook( $handbook ) ) {
+				return $handbook;
+			}
+		}
+
+		return false;
+	}
+
+	/**
+	 * Get all handbook post types.
+	 * 
+	 * @return array Array with handbook post type names.
+	 */
+	function get_handbook_post_types() {
+		if ( !class_exists( '\WPorg_Handbook_Init' ) ) {
+			return array();
+		}
+
+		$post_types = \WPorg_Handbook_Init::get_post_types();
+		$post_types = array_map( function( $value ) { return $value . '-handbook'; }, $post_types );
+
+		return $post_types;
+	}
+
+	/**
+	 * Returns post types to search in depending on the site section.
+	 * Site sections used are handbooks or reference.
+	 *
+	 * @return array Array with post types.
+	 */
+	function get_search_post_types() {
+		if ( is_handbook() ) {
+			$post_types = get_current_handbook_post_type();
+		} else {
+			$post_types = get_parsed_post_types();
+		}
+		return $post_types;
+	}
+
+	/**
 	 * Get site section root URL based on URL path.
 	 *
 	 * @return string
Index: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/js/autocomplete.js
===================================================================
--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/js/autocomplete.js	(revision 2961)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/js/autocomplete.js	(working copy)
@@ -11,8 +11,12 @@
 		return;
 	}
 
-	var form = $( '.searchform' ),
-		searchfield = $( '#search-field', form ),
+	var form = $( '.searchform' ).not(".searchform-handbook");
+	if( !form.length ) {
+		return;
+	}
+	
+	var	searchfield = $( '#search-field', form ),
 		processing = false,
 		search = '';
 
Index: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/searchform.php
===================================================================
--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/searchform.php	(revision 2961)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/searchform.php	(working copy)
@@ -32,8 +32,12 @@
 	?></div>
 
 <?php } ?>
-
-	<form role="search" method="get" class="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
+<?php 
+	$handbook = DevHub\get_current_handbook_post_type();
+	$handbook = $handbook ? str_replace( '-handbook' , 's/', $handbook ) : '';
+	$class    = $handbook ? ' searchform-handbook' : '';
+?>
+	<form role="search" method="get" class="searchform<?php echo $class ?>" action="<?php echo esc_url( home_url( "/$handbook" ) ); ?>">
 		<div>
 		<label>
 			<label for="search-field" class="screen-reader-text"><?php _ex( 'Search for:', 'label', 'wporg' ); ?></label>
@@ -41,31 +45,33 @@
 		</label>
 		<input type="submit" class="shiny-blue search-submit" value="<?php echo esc_attr_x( 'Search', 'submit button', 'wporg' ); ?>">
 		</div>
+		<?php if( !$handbook ) : ?>
+			<div class="search-post-type">
+				<span><?php _e( 'Filter by type:', 'wporg' ); ?></span>
+				<?php
+					$search_post_types = array(
+						'wp-parser-function' => __( 'Functions', 'wporg' ),
+						'wp-parser-hook'     => __( 'Hooks',     'wporg' ),
+						'wp-parser-class'    => __( 'Classes',   'wporg' ),
+						'wp-parser-method'   => __( 'Methods',   'wporg' ),
+					);
 
-		<div class="search-post-type">
-			<span><?php _e( 'Filter by type:', 'wporg' ); ?></span>
-			<?php
-				$search_post_types = array(
-					'wp-parser-function' => __( 'Functions', 'wporg' ),
-					'wp-parser-hook'     => __( 'Hooks',     'wporg' ),
-					'wp-parser-class'    => __( 'Classes',   'wporg' ),
-					'wp-parser-method'   => __( 'Methods',   'wporg' ),
-				);
-				
-				$qv_post_type = array_filter( (array) get_query_var( 'post_type' ) );	
+					$qv_post_type = array_filter( (array) get_query_var( 'post_type' ) );
+					$no_filters = get_query_var('empty_post_type_search');
 
-				if ( ! is_search() || in_array( 'any', $qv_post_type ) ) {
-					// no filters used
-					$qv_post_type = array();
-				}
-						
-				foreach ( $search_post_types as $post_type => $label ) {
-					$checked = checked( in_array( $post_type, $qv_post_type ), true, false );
-				?>
+					if ( ! is_search() || in_array( 'any', $qv_post_type ) || $no_filters ) {
+						// no filters used
+						$qv_post_type = array();
+					}
+
+					foreach ( $search_post_types as $post_type => $label ) {
+						$checked = checked( in_array( $post_type, $qv_post_type ), true, false );
+					?>
 						<label><input type="checkbox" name="post_type[]" value="<?php echo esc_attr( $post_type ); ?>"
 						<?php echo $checked; ?> /> <?php echo $label; ?></label>
-			<?php } ?>
-		</div>
+				<?php } ?>
+			</div>
+		<?php endif; ?>
 	</form>
 
 </div><!-- /search-guide -->
