Module: Riagent::SearchSchema
- Defined in:
- lib/riagent/search_schema.rb
Overview
Generates RiakJson::CollectionSchema objects (translated into Solr schemas by RiakJson) from annotated document attributes. Usage: <code>
class SampleModel
include Riagent::ActiveDocument
collection_type :riak_json
attribute :name, required: true, search_index: { as: :text }
end
puts SampleModel.schema.inspect
# => <RiakJson::CollectionSchema:0x000001050eef10 @fields=[{:name=>"name", :type=>"text", :require=>true}]>
SampleModel.save_solr_schema() # sets that schema for the collection
</code>
Instance Method Summary collapse
-
#save_solr_schema ⇒ Object
Saves the generated Solr indexing schema to RiakJson.
-
#schema ⇒ Object
Returns a CollectionSchema instance, derived from the document attributes.
Instance Method Details
#save_solr_schema ⇒ Object
Saves the generated Solr indexing schema to RiakJson. Usage: <code>
SampleModel.save_solr_schema()
</code>
54 55 56 |
# File 'lib/riagent/search_schema.rb', line 54 def save_solr_schema self.collection.set_schema(self.schema) end |
#schema ⇒ Object
Returns a CollectionSchema instance, derived from the document attributes
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/riagent/search_schema.rb', line 38 def schema schema = RiakJson::CollectionSchema.new self.attribute_set.each do | attribute | if attribute..include? :search_index field_type = attribute.[:search_index][:as] schema.add_field(field_type, attribute.[:name], attribute.[:required]) end end schema end |