Completely rewrote the entire search function.  It now works as intended.