Improve code that checks whether or not to shadow on top of search result