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



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

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



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

def client
  @client
end

#nameString (readonly)

Returns the name of the index.

Returns:

  • (String)

    the name of the index



25
26
27
# File 'lib/riak/search/index.rb', line 25

def name
  @name
end

Instance Method Details

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

Attempt to create this index

Raises:



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/riak/search/index.rb', line 60

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?



42
43
44
# File 'lib/riak/search/index.rb', line 42

def exists?
  !!index_data
end

#n_valInteger

Returns N-value/replication parameter of this index.

Returns:

  • (Integer)

    N-value/replication parameter of this index



47
48
49
# File 'lib/riak/search/index.rb', line 47

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:



77
78
79
# File 'lib/riak/search/index.rb', line 77

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



52
53
54
# File 'lib/riak/search/index.rb', line 52

def schema
  index_data[:schema]
end