Class: Xapit::Client::IndexBuilder
- Inherits:
-
Object
- Object
- Xapit::Client::IndexBuilder
- Defined in:
- lib/xapit/client/index_builder.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Instance Method Summary collapse
- #add_document(member) ⇒ Object
- #document_data(member) ⇒ Object
- #facet(name, custom_name = nil, &block) ⇒ Object
- #facets ⇒ Object
- #field(*args, &block) ⇒ Object
-
#initialize ⇒ IndexBuilder
constructor
A new instance of IndexBuilder.
- #remove_document(member) ⇒ Object
- #sortable(*args, &block) ⇒ Object
- #text(*args, &block) ⇒ Object
- #update_document(member) ⇒ Object
Constructor Details
#initialize ⇒ IndexBuilder
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
#attributes ⇒ Object (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, | value = member.send(name) value = [:_block].call(value) if [:_block] data[:attributes][name] = .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) = {} [:name] = custom_name if custom_name add_attribute(:facet, name, , &block) end |
#facets ⇒ Object
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 |