Hi i’m using ferret to enable geographical postcode. I take a postcode
and distance in miles from the user, strip off the outcode and then
retrieve the associated x y coordinates in metres from the db. Then i
get two temp x’s and y’s and search for all results that are within the
box, see code below.
Problems start to occur when i search on big distances so for example
40 miles from “G1”
VoObject.ferret_index.search(" x:[206826 335573] AND y:[590526
719273]").total_hits
=> 165
300 miles
VoObject.ferret_index.search(“y:[172098 1137702]”).total_hits
Ferret::QueryParser::QueryParseException: Error occured in q_range.c:121
-
range_new
Upper bound must be greater than lower bound. “1137702” <
“172098”from
/usr/lib/ruby/gems/1.8/gems/ferret-0.10.1/lib/ferret/index.rb:572:in
parse' from /usr/lib/ruby/gems/1.8/gems/ferret-0.10.1/lib/ferret/index.rb:572:in
process_query’
from
/usr/lib/ruby/gems/1.8/gems/ferret-0.10.1/lib/ferret/index.rb:560:in
do_search' from /usr/lib/ruby/gems/1.8/gems/ferret-0.10.1/lib/ferret/index.rb:233:in
search’
from /usr/lib/ruby/1.8/monitor.rb:229:in synchronize' from /usr/lib/ruby/gems/1.8/gems/ferret-0.10.1/lib/ferret/index.rb:232:in
search’
from (irb):16
So what am i doing wrong? How have other people used ferret for
geographical searches? Is there another way that i can define the range
so that it works properly?
because I’m also getting other crazy and just plain wrong results
VoObject.ferret_index.search(“y:[0 9]”).total_hits
=> 167
thats telling me that all the test data is with 8 metres of the
origin…
thanks in advance.
clare
if their_outcode && their_outcode.size > 0
temp_hwz = HwzPostcode.find(:first, :conditions => [‘outcode =
?’,their_outcode])
range_x_left = temp_hwz.x - (postcode_distance.to_f1.60934 * 1000)
range_x_right = temp_hwz.x + (postcode_distance.to_f1.60934 * 1000)
range_y_top = temp_hwz.y + (postcode_distance.to_f1.60934 * 1000)
range_y_bottom = temp_hwz.y - (postcode_distance.to_f1.60934 * 1000)
query += " AND x:[#{range_x_left.to_i} #{range_x_right.to_i}] AND
y:[#{range_y_bottom.to_i} #{range_y_top.to_i}]"
end