Skip to:
Content

BuddyPress.org

Ticket #7442: bp-search-use-joins.patch

File bp-search-use-joins.patch, 2.2 KB (added by brandonliles, 8 years ago)
  • src/bp-core/classes/class-bp-user-query.php

    diff --git a/src/bp-core/classes/class-bp-user-query.php b/src/bp-core/classes/class-bp-user-query.php
    index 34ecfbd..dee67a6 100644
    a b class BP_User_Query { 
    413413                                $search_terms_space   = '%' . $search_terms . '%';
    414414                        }
    415415
    416                         $sql['where']['search'] = $wpdb->prepare(
    417                                 "u.{$this->uid_name} IN ( SELECT ID FROM {$wpdb->users} WHERE ( user_login LIKE %s OR user_login LIKE %s OR user_nicename LIKE %s OR user_nicename LIKE %s ) )",
     416                        $sql['select'] .= $wpdb->prepare(
     417                                " JOIN {$wpdb->users} r ON r.ID = u.{$this->uid_name} AND ( r.user_login LIKE %s OR r.user_login LIKE %s OR r.user_nicename LIKE %s OR r.user_nicename LIKE %s ) )",
    418418                                $search_terms_nospace,
    419419                                $search_terms_space,
    420420                                $search_terms_nospace,
  • src/bp-xprofile/bp-xprofile-functions.php

    diff --git a/src/bp-xprofile/bp-xprofile-functions.php b/src/bp-xprofile/bp-xprofile-functions.php
    index fb1bf33..227680d 100644
    a b function xprofile_avatar_upload_dir( $directory = 'avatars', $user_id = 0 ) { 
    760760function bp_xprofile_bp_user_query_search( $sql, BP_User_Query $query ) {
    761761        global $wpdb;
    762762
    763         if ( empty( $query->query_vars['search_terms'] ) || empty( $sql['where']['search'] ) ) {
     763        if ( empty( $query->query_vars['search_terms'] ) ) {
    764764                return $sql;
    765765        }
    766766
    function bp_xprofile_bp_user_query_search( $sql, BP_User_Query $query ) { 
    781781
    782782        // Combine the core search (against wp_users) into a single OR clause
    783783        // with the xprofile_data search.
    784         $search_xprofile = $wpdb->prepare(
    785                 "u.{$query->uid_name} IN ( SELECT user_id FROM {$bp->profile->table_name_data} WHERE value LIKE %s OR value LIKE %s )",
     784        $sql['select'] .= $wpdb->prepare(
     785                " JOIN {$bp->profile->table_name_data} p ON p.user_id = u.{$query->uid_name} AND ( p.value LIKE %s OR p.value LIKE %s )",
    786786                $search_terms_nospace,
    787787                $search_terms_space
    788788        );
    789789
    790         $search_core     = $sql['where']['search'];
    791         $search_combined = "( {$search_xprofile} OR {$search_core} )";
    792         $sql['where']['search'] = $search_combined;
    793 
    794790        return $sql;
    795791}
    796792add_action( 'bp_user_query_uid_clauses', 'bp_xprofile_bp_user_query_search', 10, 2 );