refactors SQL search in msg feed for efficiency