This won't solve the issue of searching users by anything but their first or last name. It seems impossible to search for any other field. We used to add students by country selection which is now impossible. Going through the code to see where this behaviour changed wasn't successfult. Too many references that seem unclear to me.
There is an open issue on the tracker: https://tracker.moodle.org/browse/MDL-41784
If someone could point me in the right direction I'd be more than happy to fix this issue just locally.