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.

Parameters:

  • client (Riak::Client)

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

  • name (String)

    the name of the index



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)

Returns the client to operate on the index with

Returns:

  • (Riak::Client)

    the client to operate on the index with



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

def client
  @client
end

#nameString (readonly)

Returns the name of the index

Returns:

  • (String)

    the name of the index



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

Returns does this index exist on Riak?

Returns:

  • (Boolean)

    does this index exist on Riak?



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

def exists?
  !!index_data
end

#n_valInteger

Returns N-value/replication parameter of this index

Returns:

  • (Integer)

    N-value/replication parameter of this index



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

Parameters:

  • term (String)

    the query term

  • options (Hash) (defaults to: { })

    a hash of options to set attributes on the query

Returns:



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

Returns schema name of this index

Returns:

  • (String)

    schema name of this index



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

def schema
  index_data[:schema]
end