Skip to:
Content

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

File bp-search-use-joins2.patch, 2.0 KB (added by brandonliles, 16 months ago)
  • src/bp-core/classes/class-bp-user-query.php

     
    412412                                $search_terms_nospace = '%' . $search_terms . '%';
    413413                                $search_terms_space   = '%' . $search_terms . '%';
    414414                        }
    415 
    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 ) )",
     415                       
     416                        $sql['select'] .= $wpdb->prepare(
     417                                " LEFT 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,
    421421                                $search_terms_space
    422422                        );
     423
     424                        $sql['where']['search'] = "r.ID IS NOT NULL";
    423425                }
    424426
    425427                // Only use $member_type__in if $member_type is not set.
  • src/bp-xprofile/bp-xprofile-functions.php

     
    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                " LEFT 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
    790790        $search_core     = $sql['where']['search'];
    791         $search_combined = "( {$search_xprofile} OR {$search_core} )";
    792         $sql['where']['search'] = $search_combined;
     791        $search_combined = " ( p.id IS NOT NULL OR {$search_core} )";
     792        $sql['where']['search']  = $search_combined;
    793793
    794794        return $sql;
    795795}