Class: Riak::Search::Index

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

Overview

A Index is how Solr finds documents in Riak Search 2. A bucket or bucket type property must be configured to use the index in order for new and updated documents to be indexed and searchable.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, name) ⇒ Index

Initializes an index object, that may or may not exist.



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

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

Instance Attribute Details

#clientRiak::Client (readonly)



15
16
17
# File 'lib/riak/search/index.rb', line 15

def client
  @client
end

#nameString (readonly)



11
12
13
# File 'lib/riak/search/index.rb', line 11

def name
  @name
end

Instance Method Details

#create!(schema = nil, n_val = nil, timeout = nil) ⇒ Object

Attempt to create this index

Raises:



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/riak/search/index.rb', line 46

def create!(schema = nil, n_val = nil, timeout = nil)
  raise Riak::SearchError::IndexExistsError.new name if exists?

  @client.backend do |b|
    b.create_search_index name, schema, n_val, timeout
  end

  @index_data = nil

  true
end

#exists?Boolean



28
29
30
# File 'lib/riak/search/index.rb', line 28

def exists?
  !!index_data
end

#n_valInteger



33
34
35
# File 'lib/riak/search/index.rb', line 33

def n_val
  index_data[:n_val]
end

#query(term, options = { }) ⇒ Riak::Search::Query

Create a Query using this index and client



63
64
65
# File 'lib/riak/search/index.rb', line 63

def query(term, options = {  })
  Riak::Search::Query.new(@client, self, term, options)
end

#schemaString



38
39
40
# File 'lib/riak/search/index.rb', line 38

def schema
  index_data[:schema]
end