Class: Tire::Index

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/tire/index.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

escape, #logged, unescape

Constructor Details

#initialize(name) ⇒ Index

Returns a new instance of Index.



8
9
10
# File 'lib/tire/index.rb', line 8

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/tire/index.rb', line 6

def name
  @name
end

#responseObject (readonly)

Returns the value of attribute response.



6
7
8
# File 'lib/tire/index.rb', line 6

def response
  @response
end

Instance Method Details

#bulk(type, document) ⇒ Object



64
65
66
67
68
69
70
71
# File 'lib/tire/index.rb', line 64

def bulk(type, document)
  @response = Configuration.client.put("#{url}/#{type}/_bulk", MultiJson.encode(document))
  @response.success?

ensure
  curl = %Q|curl -X PUT #{url}/#{type}/_pulk -d '#{MultiJson.encode(document)}'|
  logged('BULK', curl)
end

#create_mapping(type, options) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/tire/index.rb', line 54

def create_mapping(type, options)
  @options = options
  @response = Configuration.client.put("#{url}/#{type}/_mapping", MultiJson.encode(options))
  @response.success?

ensure
  curl = %Q|curl -X PUT #{url}/#{type}/_mapping -d '#{MultiJson.encode(options)}'|
  logged('CREATE MAPPING', curl)
end

#deleteObject



40
41
42
43
44
45
46
47
# File 'lib/tire/index.rb', line 40

def delete
  @response = Configuration.client.delete url
  @response.success?

ensure
  curl = %Q|curl -X DELETE #{url}|
  logged('DELETE', curl)
end

#flushObject



73
74
75
76
77
78
79
80
# File 'lib/tire/index.rb', line 73

def flush
  @response = Configuration.client.put("#{url}/_flush", "")
  @response.success?

ensure
  curl = %Q|curl -X PUT #{url}/_flush|
  logged('FLUSH', curl)
end

#mapping(type = "csdn") ⇒ Object



49
50
51
52
# File 'lib/tire/index.rb', line 49

def mapping(type = "csdn")
  @response = Configuration.client.get("#{url}/#{type}/_mapping")
  MultiJson.decode(@response.body)
end

#refreshObject



82
83
84
85
86
87
88
89
# File 'lib/tire/index.rb', line 82

def refresh
  @response = Configuration.client.put("#{url}/_refresh", "")
  @response.success?

ensure
  curl = %Q|curl -X PUT #{url}/_refresh|
  logged('REFRESH', curl)
end

#regist_shard(total = 6) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/tire/index.rb', line 16

def regist_shard(total = 6)
  notes_count = Configuration.nodes_count
  regist_json = MultiJson.encode(build_regist_options(total, notes_count))
  @response = Configuration.client.put("#{url}/_shard", regist_json)
  @response.success?

ensure
  curl = %Q|curl -X PUT "#{url}/_shard" -d '#{regist_json}'|
  logged('_regist_shard', curl)
end

#shard_infoObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/tire/index.rb', line 27

def shard_info
  @response = Configuration.client.get("#{url}/_shard")
  if @response.failure?
    STDERR.puts "[REQUEST FAILED] \n"
    raise @response.to_s
  end
  
  MultiJson.decode(@response.body)
ensure
  curl = %Q|curl -X GET #{url}/_shard|
  logged('_regist_shard_info', curl)
end

#urlObject



12
13
14
# File 'lib/tire/index.rb', line 12

def url
  "#{Configuration.url}/#{@name}"
end