Class Ferret::Index::FieldInfos
In: lib/ferret/field_infos.rb
ext/r_index.c
Parent: Object

Summary

The FieldInfos class holds all the field descriptors for an index. It is this class that is used to create a new index using the FieldInfos#create_index method. If you are happy with the default properties for FieldInfo then you don‘t need to worry about this class. IndexWriter can create the index for you. Otherwise you should set up the index like in the example;

Example

  field_infos = FieldInfos.new(:term_vector => :no)

  field_infos.add_field(:title, :index => :untokenized, :term_vector => :no,
                        :boost => 10.0)

  field_infos.add_field(:content)

  field_infos.add_field(:created_on, :index => :untokenized_omit_norms,
                        :term_vector => :no)

  field_infos.add_field(:image, :store => :compressed, :index => :no,
                        :term_vector => :no)

  field_infos.create_index("/path/to/index")

Default Properties

See FieldInfo for the available field property values.

When you create the FieldInfos object you specify the default properties for the fields. Often you‘ll specify all of the fields in the index before you create the index so the default values won‘t come into play. However, it is possible to continue to dynamically add fields as indexing goes along. If you add a document to the index which has fields that the index doesn‘t know about then the default properties are used for the new field.

Methods

<<   []   add   add_field   create_index   each   fields   load   new   size   to_a   to_s   tokenized_fields  

Public Class methods

Load FieldInfos from a YAML file. The YAML file should look something like this: default:

  store: :yes
  index: :yes
  term_vector: :no

fields:

  id:
    index: :untokenized
    term_vector: :no

  title:
    boost: 20.0
    term_vector: :no

  content:
    term_vector: :with_positions_offsets

Create a new FieldInfos object which uses the default values for fields specified in the default hash parameter. See FieldInfo for available property values.

Public Instance methods

Add a FieldInfo object. Use the FieldInfos#add_field method where possible.

Get the FieldInfo object. FieldInfo objects can be referenced by either their field-number of the field-name (which must be a symbol). For example;

  fi = fis[:name]
  fi = fis[2]

Add a FieldInfo object. Use the FieldInfos#add_field method where possible.

Add a new field to the FieldInfos object. See FieldInfo for a description of the available properties.

Create a new index in the directory specified. The directory dir can either be a string path representing a directory on the file-system or an actual directory object. Care should be taken when using this method. Any existing index (or other files for that matter) will be deleted from the directory and overwritten by the new index.

Return a list of the field names (as symbols) of all the fieldcs in the index.

Return the number of fields in the FieldInfos object.

Return an array of the FieldInfo objects contained but this FieldInfos object.

Return a string representation of the FieldInfos object.

Return a list of the field names (as symbols) of all the tokenized fields in the index.

[Validate]