app/helpers/full_text_helper.rb
# Find word and show surrounding words
# Returns an array of strings, e.g.  ["...The hookers and the hustlers...",
# "...with drug dealers and hustlers...", "...were hustlers..."]
Find word and show surrounding words
Returns an array of strings, e.g.
Find word and show surrounding words Returns an array of strings e . g .
def find_word(string, search_term)
    r1 = /\w+\W/
    r2 = /\W\w+/
    string.scan(/(#{r1}{0,7}#{search_term}s?#{r2}{0,7})/i)[0...10].map { |r| "..." + r.first + "..." }
  end
def find_word ( string , search_term ) r1 = / \w + \W / r2 = / \W \w + / string . scan ( / ( #{ r1 } {0,7} #{ search_term } s? #{ r2 } {0,7}) /i ) [ 0 ... 10 ] . map { | r | "..." + r . first + "..." } end
Find word and show surrounding words
Returns an array of strings, e.g.
Find word and show surrounding words Returns an array of strings e . g .
# Only show first 10 results
string
<not_specific>
search_term
<not_specific>