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 = <<EOT
Hello world, how are you today? I said "Hello"
to the other guy but he would not answer although
all the world could hear me.
EOT
proximity_search text, 3, "hello", "World" do |a,b|
printf "Found at positions %3d and %3d\n", a, b
end
p proximity_search(text, 3, "hello", "World")
Cheers
robert