completed search function via DB queries