WordPress.org

Make WordPress Core


Ignore:
Timestamp:
02/23/2016 08:13:22 PM (5 years ago)
Author:
boonebgorges
Message:

Query: Search should match post_excerpt in addition to title and content.

When ordering search results, exact matches in the post excerpt are weighted
above those in post content, but below those in the post title.

Props swissspidy, sebastian.pisula.
FIxes #35762.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/query.php

    r36632 r36647  
    21572157
    21582158            $like = $n . $wpdb->esc_like( $term ) . $n;
    2159             $search .= $wpdb->prepare( "{$searchand}(($wpdb->posts.post_title $like_op %s) $andor_op ($wpdb->posts.post_content $like_op %s))", $like, $like );
     2159            $search .= $wpdb->prepare( "{$searchand}(($wpdb->posts.post_title $like_op %s) $andor_op ($wpdb->posts.post_excerpt $like_op %s) $andor_op ($wpdb->posts.post_content $like_op %s))", $like, $like, $like );
    21602160            $searchand = ' AND ';
    21612161        }
     
    22812281            }
    22822282
    2283             // sentence match in 'post_content'
     2283            // Sentence match in 'post_content' and 'post_excerpt'.
    22842284            if ( $like ) {
    2285                 $search_orderby .= $wpdb->prepare( "WHEN $wpdb->posts.post_content LIKE %s THEN 4 ", $like );
     2285                $search_orderby .= $wpdb->prepare( "WHEN $wpdb->posts.post_excerpt LIKE %s THEN 4 ", $like );
     2286                $search_orderby .= $wpdb->prepare( "WHEN $wpdb->posts.post_content LIKE %s THEN 5 ", $like );
    22862287            }
    22872288
    22882289            if ( $search_orderby ) {
    2289                 $search_orderby = '(CASE ' . $search_orderby . 'ELSE 5 END)';
     2290                $search_orderby = '(CASE ' . $search_orderby . 'ELSE 6 END)';
    22902291            }
    22912292        } else {
Note: See TracChangeset for help on using the changeset viewer.