From: Robert Klemme Date: 2008-12-06T21:18:52+09:00 Subject: Re: Proximity searches in Ruby On 06.12.2008 00:29, Ilan Berci wrote: > No proximity searches with 1.8.. you would need a full fledged text > search engine such as lucerne, sphinx for that type of capability Or, depending on requirements (especially performance) cook your own. def proximity_search(text, distance, w1, w2) w1 = w1.downcase w2 = w2.downcase index1 = [] index2 = [] text.scan(/\w+/).each_with_index do |w,idx| case when w1 == w.downcase index1 << idx when w2 == w.downcase index2 << idx end end found = false index1.each do |i1| index2.each do |i2| if (i1 - i2).abs <= distance found = true yield i1, i2 if block_given? end end end found end text = <