class RiakJson::CollectionSchema

Helper object for creating RiakJson schemas.

Attributes

fields[RW]

Public Class Methods

new() click to toggle source
# File lib/riak_json/collection_schema.rb, line 26
def initialize
  @fields = []
end
valid_field_types() click to toggle source
# File lib/riak_json/collection_schema.rb, line 69
def self.valid_field_types
  [:text, :string, :multi_string, :integer, :location, :location_rpt]
end

Public Instance Methods

add_field(field_type, field_name, required=false) click to toggle source
# File lib/riak_json/collection_schema.rb, line 30
def add_field(field_type, field_name, required=false)
  unless self.class.valid_field_types.include? field_type.to_sym
    raise Exception, "Invalid field type"
  end
  self.fields << { name: field_name.to_s, type: field_type.to_s, require: required }
end
add_integer_field(field_name, required=false) click to toggle source
# File lib/riak_json/collection_schema.rb, line 49
def add_integer_field(field_name, required=false)
  self.add_field(:integer, field_name, required)
end
add_location_field(field_name, required=false) click to toggle source

Add a ‘location’ type field (Solr class solr.LatLonType) to the schema See wiki.apache.org/solr/SpatialSearch

# File lib/riak_json/collection_schema.rb, line 39
def add_location_field(field_name, required=false)
  self.add_field(:location, field_name, required)
end
add_location_rpt_field(field_name, required=false) click to toggle source

Add a ‘location_rpt’ type field (Solr class solr.SpatialRecursivePrefixTreeFieldType) to the schema See wiki.apache.org/solr/SolrAdaptersForLuceneSpatial4

# File lib/riak_json/collection_schema.rb, line 45
def add_location_rpt_field(field_name, required=false)
  self.add_field(:location_rpt, field_name, required)
end
add_multi_string_field(field_name, required=false) click to toggle source
# File lib/riak_json/collection_schema.rb, line 53
def add_multi_string_field(field_name, required=false)
  self.add_field(:multi_string, field_name, required)
end
add_string_field(field_name, required=false) click to toggle source
# File lib/riak_json/collection_schema.rb, line 57
def add_string_field(field_name, required=false)
  self.add_field(:string, field_name, required)
end
add_text_field(field_name, required=false) click to toggle source
# File lib/riak_json/collection_schema.rb, line 61
def add_text_field(field_name, required=false)
  self.add_field(:text, field_name, required)
end
build() click to toggle source
# File lib/riak_json/collection_schema.rb, line 65
def build
  self.fields.to_json
end