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



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

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



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

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



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

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

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

#flushObject



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

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



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

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

#refreshObject



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

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

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

#regist_shard(options) ⇒ Object



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

def regist_shard(options)
  regist_json = MultiJson.encode(options)
  @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



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

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