refactor embedded autosuggest javascript to func

Prior to this commit, the javascript function for filtering autosuggest
results lived as a interpolated string in a ruby helper. This commit
moves the core logic of that function out to a higher order function
that takes the input class, still available from the ruby helper, and
returns a function that filters on that specific class.