Class: Ferret::Index::FieldInfos

Inherits:
Object
  • Object
show all
Defined in:
ext/r_index.c,
lib/ferret/field_infos.rb

Overview

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.

Class Method Summary collapse

Class Method Details

.load(yaml_str) ⇒ Object

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


24
25
26
27
28
29
30
31
# File 'lib/ferret/field_infos.rb', line 24

def self.load(yaml_str)
  info = YAML.load(yaml_str)
  convert_strings_to_symbols(info)
  fis = FieldInfos.new(info[:default])
  fields = info[:fields]
  fields.keys.each {|key| fis.add_field(key, fields[key])} if fields
  fis
end