Class: Xapit::Client::IndexBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/xapit/client/index_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeIndexBuilder

Returns a new instance of IndexBuilder.



5
6
7
# File 'lib/xapit/client/index_builder.rb', line 5

def initialize
  @attributes = {}
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



4
5
6
# File 'lib/xapit/client/index_builder.rb', line 4

def attributes
  @attributes
end

Instance Method Details

#add_document(member) ⇒ Object



27
28
29
# File 'lib/xapit/client/index_builder.rb', line 27

def add_document(member)
  Xapit.database.add_document(document_data(member))
end

#document_data(member) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/xapit/client/index_builder.rb', line 39

def document_data(member)
  data = {:class => member.class.name, :id => member.id, :attributes => {}}
  attributes.each do |name, options|
    value = member.send(name)
    value = options[:_block].call(value) if options[:_block]
    data[:attributes][name] = options.merge(:value => value)
  end
  data
end

#facet(name, custom_name = nil, &block) ⇒ Object



21
22
23
24
25
# File 'lib/xapit/client/index_builder.rb', line 21

def facet(name, custom_name = nil, &block)
  options = {}
  options[:name] = custom_name if custom_name
  add_attribute(:facet, name, options, &block)
end

#facetsObject



49
50
51
52
53
# File 'lib/xapit/client/index_builder.rb', line 49

def facets
  attributes.keys.select do |attribute|
    attributes[attribute][:facet]
  end
end

#field(*args, &block) ⇒ Object



13
14
15
# File 'lib/xapit/client/index_builder.rb', line 13

def field(*args, &block)
  add_attribute(:field, *args, &block)
end

#remove_document(member) ⇒ Object



31
32
33
# File 'lib/xapit/client/index_builder.rb', line 31

def remove_document(member)
  Xapit.database.remove_document(document_data(member))
end

#sortable(*args, &block) ⇒ Object



17
18
19
# File 'lib/xapit/client/index_builder.rb', line 17

def sortable(*args, &block)
  add_attribute(:sortable, *args, &block)
end

#text(*args, &block) ⇒ Object



9
10
11
# File 'lib/xapit/client/index_builder.rb', line 9

def text(*args, &block)
  add_attribute(:text, *args, &block)
end

#update_document(member) ⇒ Object



35
36
37
# File 'lib/xapit/client/index_builder.rb', line 35

def update_document(member)
  Xapit.database.update_document(document_data(member))
end