This is not a trivial question, or you could just search Google for
it. Some parts may already be built, but I suspect you'll have to do
a fair amount of invention on your own.
Given that you're using Rails, I assume you're searching elements
that are in a database. You might look at any of the number of full
text search components that are available for rails (acts_as_solr,
acts_as_ferret). I don't know the extent to which any of these
handle UTF-8, word stemming, etc., so you might have to implement