Ticket #21688: 21688-3.patch
| File 21688-3.patch, 3.6 KB (added by azaozz, 9 months ago) |
|---|
-
wp-includes/default-filters.php
192 192 add_filter( 'editable_slug', 'urldecode' ); 193 193 add_filter( 'editable_slug', 'esc_textarea' ); 194 194 add_filter( 'nav_menu_meta_box_object', '_wp_nav_menu_meta_box_object' ); 195 add_filter( 'wp_search_stopwords', 'wp_search_stopwords' ); 195 196 196 197 // Actions 197 198 add_action( 'wp_head', 'wp_enqueue_scripts', 1 ); -
wp-includes/functions.php
3637 3637 return true; 3638 3638 } 3639 3639 3640 /** 3641 * Common stopwords (terms) that are excluded from the separate term matching when searching for posts. 3642 * The list of English stopwords is the approximate search engines list. MySQL has a much longer default list of full-text stopwords. 3643 * 3644 * @since 3.5.0 3645 * @param array optional Terms to exclude when searching 3646 * 3647 * @return array 3648 */ 3649 function wp_search_stopwords( $in = array() ) { 3650 $_words = explode( ',', _x('about,are,com,for,from,how,that,the,this,was,what,when,where,who,will,with,www', 'Comma separated list of common words to exclude when searching.') ); 3651 $words = array(); 3652 3653 foreach( $_words as $word ) { 3654 $word = trim($word, "\r\n\t "); 3655 if ( !$word ) 3656 continue; 3657 $words[] = $word; 3658 } 3659 3660 return array_merge( $in, $words ); 3661 } 3662 -
wp-includes/query.php
2174 2174 } 2175 2175 2176 2176 // If a search pattern is specified, load the posts that match 2177 if ( !empty($q['s']) ) { 2177 // Sanity check: search string shouldn't be more than 1600 characters 2178 // (some browsers won't send more than 2000 characters incl. the URL in a urlencoded GET request). 2179 if ( !empty($q['s']) && strlen($q['s']) < 1600 ) { 2178 2180 // added slashes screw with quote grouping when done early, so done later 2179 2181 $q['s'] = stripslashes($q['s']); 2180 2182 if ( empty( $_GET['s'] ) && $this->is_main_query() ) … … 2183 2185 $q['search_terms'] = array($q['s']); 2184 2186 } else { 2185 2187 preg_match_all('/".*?("|$)|((?<=[\r\n\t ",+])|^)[^\r\n\t ",+]+/', $q['s'], $matches); 2186 $q['search_terms'] = array_map('_search_terms_tidy', $matches[0]); 2188 $q['_search_terms'] = array_map('_search_terms_tidy', $matches[0]); 2189 $q['search_terms'] = array(); 2190 $stopwords = apply_filters_ref_array( 'wp_search_stopwords', array( array(), &$this ) ); 2191 2192 foreach ( (array) $q['_search_terms'] as $term ) { 2193 if ( empty($term) || strlen($term) < 3 || in_array( $term, $stopwords, true ) ) 2194 continue; 2195 $q['search_terms'][] = $term; 2196 } 2197 2198 unset($q['_search_terms']); 2199 // if the search string has only short terms or stopwords, or is more than 10 terms long, match it as sentence 2200 if ( empty($q['search_terms']) || count($q['search_terms']) > 10 ) 2201 $q['search_terms'] = array($q['s']); 2187 2202 } 2203 2188 2204 $n = !empty($q['exact']) ? '' : '%'; 2189 2205 $searchand = ''; 2190 foreach( (array)$q['search_terms'] as $term ) {2206 foreach( $q['search_terms'] as $term ) { 2191 2207 $term = esc_sql( like_escape( $term ) ); 2192 2208 $search .= "{$searchand}(($wpdb->posts.post_title LIKE '{$n}{$term}{$n}') OR ($wpdb->posts.post_content LIKE '{$n}{$term}{$n}'))"; 2193 2209 $searchand = ' AND ';
