class Riak::Search::Schema

A schema is a Riak Search 2 concept that describes how to index documents. They’re implemented as a standard Solr XML schema.

Attributes

name[R]

@return [String] the name of the schema

Public Class Methods

new(client, name) click to toggle source

Initializes a schema object, that may or may not exist.

@param [Riak::Client] client the client connected to the Riak cluster

you wish to operate on

@param [String] name the name of the schema

# File lib/riak/search/schema.rb, line 16
def initialize(client, name)
  @client = client
  @name = name
end

Public Instance Methods

content() click to toggle source

@return [String] the XML content of this schema

# File lib/riak/search/schema.rb, line 27
def content
  schema_data.content
end
create!(content) click to toggle source

@param [String] content the XML content of this schema @raise [Riak::SearchError::SchemaExistsError] if a schema with the given

name already exists
# File lib/riak/search/schema.rb, line 34
def create!(content)
  fail Riak::SearchError::SchemaExistsError.new name if exists?

  @client.backend do |b|
    b.create_search_schema name, content
  end

  @schema_data = nil

  true
end
exists?() click to toggle source

@return [Boolean] does this schema exist on Riak?

# File lib/riak/search/schema.rb, line 22
def exists?
  !!schema_data
end

Private Instance Methods

schema_data() click to toggle source
# File lib/riak/search/schema.rb, line 48
def schema_data
  return @schema_data if defined?(@schema_data) && @schema_data

  sd = nil

  begin
    sd = @client.backend do |b|
      b.get_search_schema name
    end
  rescue Riak::ProtobuffsFailedRequest => e
    return nil if e.not_found?
    raise e
  end

  @schema_data = sd
end