Module: MarkMapper::Plugins::Indexable::ClassMethods

Defined in:
lib/mark_mapper/plugins/indexable.rb

Instance Method Summary collapse

Instance Method Details

#index(name, options = {}) ⇒ Object

Defines all the MarkLogic indexes for this document

Model.index :first_name, :type => String, :facet => true

Examples:

Define an index.

Options Hash (options):

  • :type (String)

    The atomic type of the element to index.

  • :facet (Boolean)

    Whether to facet on this element index or not

Raises:

  • (InvalidIndexType)

Since:

  • 0.0.1


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/mark_mapper/plugins/indexable.rb', line 31

def index(name, options = {})
  options[:type] ||= String
  options[:type] = options[:type].xs_type if options[:type].respond_to?(:xs_type)

  raise InvalidIndexType, "Invalid index type: #{options[:type]}" unless [Boolean.xs_type, Integer.xs_type, String.xs_type, Float.xs_type].include? options[:type]

  new_index =
    begin
      case options[:kind]
        when "field" then MarkLogic::DatabaseSettings::RangeFieldIndex.new(name, options)
        when "path" then MarkLogic::DatabaseSettings::RangePathIndex.new(name, options)
        else MarkLogic::DatabaseSettings::RangeElementIndex.new(name, options)
      end
    end

  if !index_defs.has_key?(name.to_s)
    index_defs[name.to_s] = new_index
    MarkMapper.application.add_index(new_index)
  end
end

#index_defsObject

Get all the defined indexes for this document

@return[ Hash ] A hash containing all the index definitions

Examples:

Get the indexes hash

person.index_defs

Since:

  • 0.0.1


15
16
17
# File 'lib/mark_mapper/plugins/indexable.rb', line 15

def index_defs
  @index_defs ||= {}
end

#remove_index(name) ⇒ Object

Removes the definition for an index Used for testing

Model.remove_index :name

Examples:

Remove an index

Since:

  • 0.0.1


61
62
63
# File 'lib/mark_mapper/plugins/indexable.rb', line 61

def remove_index(name)
  index_defs.delete name.to_s
end