On 9/19/06, David Sheldon <[EMAIL PROTECTED]> wrote:
> David Balmain wrote:
>
> > Is there any reason you need them all to be in the same field? Or am I
> > misunderstanding you? You do realize that different fields can have
> > different properties right?
>
> Yes, I want them all in different fields, named after the property, that
> way you could search for someone's name by 'name:Bob' or their year of
> matriculation with 'matriculation:1978'. The problem is that on creation
> of the index I do not know what properties will be associated with users
> so cannot define their field infos. Previously I was able to just
> specify the properties when adding that field to the document.
>
> David
I'm assuming the matriculation field is always going to be a number.
It won't change at a later date. So you can just set up the field
whenever you use it for the first time.
require 'rubygems'
require 'ferret'
i = Ferret::I.new
puts i.field_infos
if not i.field_infos[:matriculation]
i.field_infos.add_field(:matriculation,
:index => :untokenized)
end
puts i.field_infos
i << {:matriculation => 1978}
Of course you only need to do this for fields which vary from the
norm. Whatever properties you instantiated the FieldInfos with will be
used for fields added with the FieldInfos#add_field method unless
otherwise specified. So if most of your fields are number or date
fields you'd create the FieldInfos like this:
fis = FieldInfos.new(:index => :untokenized_omit_norms, :term_vector => :no)
Now when you add a text field you'll need to explicitly set it to
tokenized and store term vectors:
if not i.field_infos[:content]
i.field_infos.add_field(:content,
:term_vector => :with_positions_offsets,
:index => :yes)
end
Let me know if this helps or not.
Cheers,
Dave
_______________________________________________
Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk