Class: Riak::Search::Schema

Inherits:
Object show all
Defined in:
lib/riak/search/schema.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, name) ⇒ Schema

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

Parameters:

  • client (Riak::Client)

    the client connected to the Riak cluster you wish to operate on

  • name (String)

    the name of the schema



16
17
18
19
# File 'lib/riak/search/schema.rb', line 16

def initialize(client, name)
  @client = client
  @name = name
end

Instance Attribute Details

#nameString (readonly)

Returns the name of the schema.

Returns:

  • (String)

    the name of the schema



9
10
11
# File 'lib/riak/search/schema.rb', line 9

def name
  @name
end

Instance Method Details

#contentString

Returns the XML content of this schema.

Returns:

  • (String)

    the XML content of this schema



27
28
29
# File 'lib/riak/search/schema.rb', line 27

def content
  schema_data.content
end

#create!(content) ⇒ Object

Parameters:

  • content (String)

    the XML content of this schema

Raises:



34
35
36
37
38
39
40
41
42
43
44
# 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?Boolean

Returns does this schema exist on Riak?.

Returns:

  • (Boolean)

    does this schema exist on Riak?



22
23
24
# File 'lib/riak/search/schema.rb', line 22

def exists?
  !!schema_data
end