On 7/17/06, Gary Elliott <[EMAIL PROTECTED]> wrote:
> This is a "me too" post. I would love to replace the query filter we
> use on tourb.us with this.
>
> gary
>

Maybe Gary, or someone else can help me, but I've put the query filter
problem aside, and I'm trying to do this by finding locations within a
bounding box using Range queries on the longitude and latitude.
Unfortunately I'm running into some problems, since I'm comparing
numeric values that can be positive or negative, and as far as I can
tell, Ferret (actually I've only been able to find information about
Lucene, but I'm assuming it's the same) does the comparisons
lexicographically, and not numerically.

So I've tried to replicate the encoding as they do in
http://wiki.apache.org/jakarta-lucene/SearchNumericalFields, but I'm
encountering some strange behaviour that is throwing me off.

So I index a bunch of documents, and see the following line of output:
Adding field latitude_string with value '004915010' to index
So that is the encoded version of 49.1501.
Now if I do the following query, I should get this record back:
>> Person.ferret_index.search_each("latitude_string:['000000000' '099999999']")
=> 0

But I don't, and I can verify that lexicographically, ruby sees
'004915010' as lying between '000000000' and '099999999':
>> '000000000' <= '004915010' and '004915010' <= '099999999'
=> true

But the query returns no results. I've tried a few more, as follows:
>> Person.ferret_index.search_each("latitude_string:(> '000000000')") do end
=> 7
>> Person.ferret_index.search_each("latitude_string:(< '099900000')") do end
=> 0

And so clearly it is not seeing that '004915010' < '099999999'. If I
remove the quotes, it works properly, but the problem is then with the
negative values.
>> Person.ferret_index.search_each("latitude_string:(> -00000000)") do end
=> 0
>> Person.ferret_index.search_each("latitude_string:(> '-00000000')") do end
=> 7

So the quotes affect things, but then what if I need to search between
a negative value and a positive value.
>> Person.ferret_index.search_each("latitude_string:(< 099999999)") do end
=> 7
>> Person.ferret_index.search_each("longitude_string:(> '-00000000')") do end
=> 7
>> Person.ferret_index.search_each("latitude_string:['-00000000'
099999999]") do end
=> 0

For now should I just not be using range queries at all, and just
quote negative values? I'd have to do more testing to see if it's
accurate, but it seems to be the only way that works...maybe I could
make all values positive by adding a constant to them all?

Any ideas why this is occuring? Am I doing this completely backwards,
is there an easier way to do the numeric comparisons? I'm very sorry
if this is an issue that has been discussed before, but I did look
through the archives and didn't find anything...

-- 
Cheers,
Jordan Frank
[EMAIL PROTECTED]
_______________________________________________
Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk

Reply via email to