A few questions about numbers and dates

Hi,

I just noticed that Ferret seems to convert every field to a string
[ruby code appended for those interested], which has thwarted my attempt
to format Dates (to “dd/mm/yyyy”) and Floats (to “n.nn”) for consumption
further down the line based on the class of the field stored.

I considered pre-formatting Dates and Floats prior to indexing, which
would store the field exactly as I need for presentation purposes,
however I would lose sorting and range searching.

I’m wondering what approaches people are using to manage formatting post
retrieve from Ferret.

Any pointers appreciated,

Kind Regards

Neville

require ‘rubygems’
require ‘ferret’
require ‘date’

p Ferret::VERSION

@dir = Ferret::Store::RAMDirectory.new
@index = Ferret::Index::Index.new(:dir => @dir)

invoice = {:invoice_date => Date.new(2006,9,20), :invoice_value =>
44.50, :invoice_no => 45656, :invoice_to => ‘Nev’}

@index << invoice

doc = @index[0].load

doc.fields.each do |f|
p f
p doc[f].class
p doc[f]
end

==========================

ruby test_format.rb
“0.10.6”
:invoice_date
String
“2006-09-20”
:invoice_value
String
“44.5”
:invoice_no
String
“45656”
:invoice_to
String
“Nev”

On 9/28/06, Neville B. [email protected] wrote:

I’m wondering what approaches people are using to manage formatting post
retrieve from Ferret.

Any pointers appreciated,

Kind Regards

Neville

Hi Neville,

One possible solution is to add those fields twice, once in a
stored/unindexed field in the correct format for output and another in
an unstored/indexed field with the correct format for sorting and
range queries.

Actually, sorting will already work on those fields above, it is just
range queries you have to worry about, and even they will work on your
date field. I would certainly be amenable to developing a
FloatRangeQuery and IntegerRangeQuery with the right motivation. :wink:

Finally, I’ve mentioned before that I’m very interested in building an
object database based on Ferret. I mentioned it here:

http://www.ruby-forum.com/topic/82086#new

By turning documents into objects and giving fields types it would
solve the problems you have just mentioned plus many more.

Cheers,
Dave

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs