Class: ExistDB::IndexFactory::IndexFactory

Inherits:
Object
  • Object
show all
Includes:
Meta
Defined in:
lib/existdb/index_factory.rb

Overview

Example: ExistDB::IndexFactory.configure do

collection '/db/PartList'
range 'qtyOnHand' => Fixnum, 'qtyOnOrder' => Fixnum
lucene '//part', 'name', 'description'

end

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Meta

#initialize_with_options, #named_or_ordered_options

Constructor Details

#initialize(*options, &block) ⇒ IndexFactory

Returns a new instance of IndexFactory.



23
24
25
26
# File 'lib/existdb/index_factory.rb', line 23

def initialize(*options, &block)
    initialize_with_options(options, [:collection])
    self.instance_eval(&block)
end

Instance Attribute Details

#collection(col = nil) ⇒ Object



70
71
72
73
# File 'lib/existdb/index_factory.rb', line 70

def collection(col = nil)
    @collection = col if col
    return @collection
end

Instance Method Details

#configureObject



75
76
77
78
79
# File 'lib/existdb/index_factory.rb', line 75

def configure
    raise "Specify a collection" unless @collection
    col = collection.create_collection(configuration_collection_name)
    res = Resource.new(:parent => col, :name => configuration_file, :xml => to_s)
end

#lucene(*targets) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/existdb/index_factory.rb', line 52

def lucene(*targets)
    @lucenes ||= Array.new
    targets.each do |target|
        if target.is_a?(Hash) then
            target.each do |key, value|
                tgt_name = key.to_s
                tgt_type = tgt_name.index('/') ? 'path' : 'qname'
                index_type = type_convert(value)
                @lucenes << %|<text #{tgt_type}="#{tgt_name}" type="#{index_type}"/>|
            end
        elsif target.respond_to?(:to_s) then
            tgt_name = target.to_s
            tgt_type = tgt_name.index('/') ? 'path' : 'qname'
            @lucenes << %|<text #{tgt_type}="#{tgt_name}"/>|
        end
    end
end

#range(*targets) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/existdb/index_factory.rb', line 34

def range(*targets)
    @ranges ||= Array.new
    targets.each do |target|
        if target.is_a?(Hash) then
            target.each do |key, value|
                tgt_name = key.to_s
                tgt_type = tgt_name.index('/') ? 'path' : 'qname'
                index_type = type_convert(value)
                @ranges << %|<create #{tgt_type}="#{tgt_name}" type="#{index_type}"/>|
            end
        elsif target.respond_to?(:to_s) then
            tgt_name = target.to_s
            tgt_type = tgt_name.index('/') ? 'path' : 'qname'
            @ranges << %|<create #{tgt_type}="#{tgt_name}"/>|
        end
    end
end

#to_sObject



28
29
30
31
32
# File 'lib/existdb/index_factory.rb', line 28

def to_s
    wrapper do
        ranges.to_s + lucenes.to_s
    end
end