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.


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)


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

def name
  @name
end

Instance Method Details

#contentString


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

def content
  schema_data.content
end

#create!(content) ⇒ Object

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


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

def exists?
  !!schema_data
end