csdn-tire 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -7,11 +7,6 @@ Usage
7
7
 
8
8
  配置:
9
9
 
10
- ```
11
- # 设置搜索后端节点数量:
12
- Tire::Configuration.nodes_count(2)
13
- ```
14
-
15
10
  ```
16
11
  # 设置日志:
17
12
  Tire::Configuration.logger(STDOUT, :level => "debug")
@@ -23,22 +18,23 @@ Tire::Configuration.url("http://localhost:9200")
23
18
  ```
24
19
  或者在环境变量设置:
25
20
  ```
26
- export ELASTICSEARCH_URL=http://localhost:9200
21
+ export CSDNSEARCH_URL=http://localhost:9200
27
22
  ```
28
23
 
29
- 注册分片:index.regist_shard(total)
24
+ 注册分片:index.regist_shard(options)
30
25
  ```
31
26
  [1] pry(main)> index = Tire.index("index_name")
32
- => #<Tire::Index:0x9cd1564 @name="index_name">
33
- [2] pry(main)> index.regist_shard(6)
34
- # 2012-06-05 16:23:44:053 [_regist_shard] ("index_name")
27
+ => #<Tire::Index:0xb2b3b958 @name="index_name">
28
+ [2] pry(main)> index.regist_shard :cs1 => [0,1], :cs2 => [2]
29
+ # 2012-06-21 17:47:34:%L [_regist_shard] ("index_name")
35
30
  #
36
- curl -X PUT "http://192.168.6.35:9400/index_name/_shard" -d '{"cs1":[0,2,4],"cs2":[1,3,5]}'
31
+ curl -X PUT "http://192.168.6.35:9400/index_name/_shard" -d '{"cs2":[2],"cs1":[0,1]}'
37
32
 
38
- # 2012-06-05 16:23:44:053 [200]
33
+ # 2012-06-21 17:47:34:%L [200]
34
+ #
35
+ # "{\"ok\":true,\"acknowledged\":\"true\"}"
39
36
 
40
37
  => true
41
- [3] pry(main)>
42
38
  ```
43
39
 
44
40
  查看分片信息:index.shard_info
@@ -282,10 +278,20 @@ curl -X GET http://192.168.6.35:9400/bbs/csdn/_count -d '{"query":{"text":{"titl
282
278
  # "totalHits": 6
283
279
  # }
284
280
  ```
281
+
285
282
  集群状态:
283
+ ```
284
+ Tire::Cluster.state
285
+ Tire::Cluster.state(true)
286
+ ```
286
287
 
288
+ 索引列表:
289
+ ```
290
+ Tire::Cluster.index
287
291
  ```
288
- state = Tire.state.info
289
292
 
290
- more_state = Tire.state.info(true)
293
+ 主机信息:
291
294
  ```
295
+ Tire::Cluster.host
296
+ ```
297
+
data/lib/tire/cluster.rb CHANGED
@@ -10,9 +10,9 @@ module Tire
10
10
  # [{"host":"192.168.6.35","master":false,"online":false,"port":9500},{"host":"192.168.6.35","master":false,"online":true,"port":9400}]
11
11
  def self.state(more = false)
12
12
  desc_url = more ? "#{url}/_state?more=true" : "#{url}/_state?more=false"
13
- response = Configuration.client.get(desc_url)
14
- if response.success?
15
- MultiJson.decode(response.body)
13
+ @response = Configuration.client.get(desc_url)
14
+ if @response.success?
15
+ MultiJson.decode(@response.body)
16
16
  else
17
17
  []
18
18
  end
@@ -25,13 +25,13 @@ module Tire
25
25
  def self.index
26
26
  desc_url = "#{url}/_index"
27
27
 
28
- response = Configuration.client.get(desc_url)
29
- if response.failure?
28
+ @response = Configuration.client.get(desc_url)
29
+ if @response.failure?
30
30
  STDERR.puts "[REQUEST FAILED] \n"
31
- raise response.to_s
31
+ raise @response.to_s
32
32
  end
33
33
 
34
- MultiJson.decode(response.body)
34
+ MultiJson.decode(@response.body)
35
35
  ensure
36
36
  curl = %Q|curl -X GET #{desc_url}|
37
37
  logged('CLUSTER INDEX', curl)
@@ -41,13 +41,13 @@ module Tire
41
41
  def self.host
42
42
  path = "#{url}/_host"
43
43
 
44
- response = Configuration.client.get(path)
45
- if response.failure?
44
+ @response = Configuration.client.get(path)
45
+ if @response.failure?
46
46
  STDERR.puts "[REQUEST FAILED] \n"
47
- raise response.to_s
47
+ raise @response.to_s
48
48
  end
49
49
 
50
- MultiJson.decode(response.body)
50
+ MultiJson.decode(@response.body)
51
51
  ensure
52
52
  curl = %Q|curl -X GET #{path}|
53
53
  logged('CLUSTER HOST', curl)
@@ -2,11 +2,6 @@
2
2
  module Tire
3
3
 
4
4
  class Configuration
5
-
6
- def self.nodes_count(n=2)
7
- @nodes_count ||= n
8
- end
9
-
10
5
  def self.url(value=nil)
11
6
  @url = (value ? value.to_s.gsub(%r|/*$|, '') : nil) || @url || ENV['CSDNSEARCH_URL'] || "http://localhost:9200"
12
7
  end
data/lib/tire/index.rb CHANGED
@@ -13,9 +13,8 @@ module Tire
13
13
  "#{Configuration.url}/#{@name}"
14
14
  end
15
15
 
16
- def regist_shard(total = 6)
17
- notes_count = Configuration.nodes_count
18
- regist_json = MultiJson.encode(build_regist_options(total, notes_count))
16
+ def regist_shard(options)
17
+ regist_json = MultiJson.encode(options)
19
18
  @response = Configuration.client.put("#{url}/_shard", regist_json)
20
19
  @response.success?
21
20
 
@@ -88,11 +87,5 @@ module Tire
88
87
  logged('REFRESH', curl)
89
88
  end
90
89
 
91
- private
92
-
93
- def build_regist_options(total, notes_count)
94
- Hash[(0..total - 1).group_by{|x| x.modulo notes_count}.map{|key, value| ["cs#{key + 1}", value]}]
95
- end
96
-
97
90
  end
98
91
  end
data/lib/tire/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module Tire
3
- VERSION = "0.7.0"
3
+ VERSION = "0.7.1"
4
4
  end
metadata CHANGED
@@ -1,218 +1,208 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: csdn-tire
3
- version: !ruby/object:Gem::Version
4
- version: 0.7.0
3
+ version: !ruby/object:Gem::Version
4
+ hash: 1
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 7
9
+ - 1
10
+ version: 0.7.1
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Hooopo
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2012-06-20 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2012-06-21 00:00:00 +08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
15
22
  name: rake
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
- - !ruby/object:Gem::Dependency
31
- name: rest-client
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ~>
36
- - !ruby/object:Gem::Version
37
- version: '1.6'
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
38
33
  type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rest-client
39
37
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
38
+ requirement: &id002 !ruby/object:Gem::Requirement
41
39
  none: false
42
- requirements:
40
+ requirements:
43
41
  - - ~>
44
- - !ruby/object:Gem::Version
45
- version: '1.6'
46
- - !ruby/object:Gem::Dependency
47
- name: multi_json
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ~>
52
- - !ruby/object:Gem::Version
53
- version: '1.0'
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 1
46
+ - 6
47
+ version: "1.6"
54
48
  type: :runtime
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: multi_json
55
52
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
53
+ requirement: &id003 !ruby/object:Gem::Requirement
57
54
  none: false
58
- requirements:
55
+ requirements:
59
56
  - - ~>
60
- - !ruby/object:Gem::Version
61
- version: '1.0'
62
- - !ruby/object:Gem::Dependency
63
- name: hashr
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ~>
68
- - !ruby/object:Gem::Version
69
- version: 0.0.19
57
+ - !ruby/object:Gem::Version
58
+ hash: 15
59
+ segments:
60
+ - 1
61
+ - 0
62
+ version: "1.0"
70
63
  type: :runtime
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: hashr
71
67
  prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
68
+ requirement: &id004 !ruby/object:Gem::Requirement
73
69
  none: false
74
- requirements:
70
+ requirements:
75
71
  - - ~>
76
- - !ruby/object:Gem::Version
72
+ - !ruby/object:Gem::Version
73
+ hash: 57
74
+ segments:
75
+ - 0
76
+ - 0
77
+ - 19
77
78
  version: 0.0.19
78
- - !ruby/object:Gem::Dependency
79
- name: activesupport
80
- requirement: !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
83
- - - ! '>='
84
- - !ruby/object:Gem::Version
85
- version: '2.3'
86
79
  type: :runtime
80
+ version_requirements: *id004
81
+ - !ruby/object:Gem::Dependency
82
+ name: activesupport
87
83
  prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
84
+ requirement: &id005 !ruby/object:Gem::Requirement
89
85
  none: false
90
- requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
93
- version: '2.3'
94
- - !ruby/object:Gem::Dependency
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 5
90
+ segments:
91
+ - 2
92
+ - 3
93
+ version: "2.3"
94
+ type: :runtime
95
+ version_requirements: *id005
96
+ - !ruby/object:Gem::Dependency
95
97
  name: bundler
96
- requirement: !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ~>
100
- - !ruby/object:Gem::Version
101
- version: '1.0'
102
- type: :development
103
98
  prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
99
+ requirement: &id006 !ruby/object:Gem::Requirement
105
100
  none: false
106
- requirements:
101
+ requirements:
107
102
  - - ~>
108
- - !ruby/object:Gem::Version
109
- version: '1.0'
110
- - !ruby/object:Gem::Dependency
111
- name: yajl-ruby
112
- requirement: !ruby/object:Gem::Requirement
113
- none: false
114
- requirements:
115
- - - ~>
116
- - !ruby/object:Gem::Version
117
- version: '1.0'
103
+ - !ruby/object:Gem::Version
104
+ hash: 15
105
+ segments:
106
+ - 1
107
+ - 0
108
+ version: "1.0"
118
109
  type: :development
110
+ version_requirements: *id006
111
+ - !ruby/object:Gem::Dependency
112
+ name: yajl-ruby
119
113
  prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
114
+ requirement: &id007 !ruby/object:Gem::Requirement
121
115
  none: false
122
- requirements:
116
+ requirements:
123
117
  - - ~>
124
- - !ruby/object:Gem::Version
125
- version: '1.0'
126
- - !ruby/object:Gem::Dependency
127
- name: shoulda
128
- requirement: !ruby/object:Gem::Requirement
129
- none: false
130
- requirements:
131
- - - ! '>='
132
- - !ruby/object:Gem::Version
133
- version: '0'
118
+ - !ruby/object:Gem::Version
119
+ hash: 15
120
+ segments:
121
+ - 1
122
+ - 0
123
+ version: "1.0"
134
124
  type: :development
125
+ version_requirements: *id007
126
+ - !ruby/object:Gem::Dependency
127
+ name: shoulda
135
128
  prerelease: false
136
- version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
- requirements:
139
- - - ! '>='
140
- - !ruby/object:Gem::Version
141
- version: '0'
142
- - !ruby/object:Gem::Dependency
143
- name: mocha
144
- requirement: !ruby/object:Gem::Requirement
129
+ requirement: &id008 !ruby/object:Gem::Requirement
145
130
  none: false
146
- requirements:
147
- - - ! '>='
148
- - !ruby/object:Gem::Version
149
- version: '0'
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ hash: 3
135
+ segments:
136
+ - 0
137
+ version: "0"
150
138
  type: :development
139
+ version_requirements: *id008
140
+ - !ruby/object:Gem::Dependency
141
+ name: mocha
151
142
  prerelease: false
152
- version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
- requirements:
155
- - - ! '>='
156
- - !ruby/object:Gem::Version
157
- version: '0'
158
- - !ruby/object:Gem::Dependency
159
- name: bson_ext
160
- requirement: !ruby/object:Gem::Requirement
143
+ requirement: &id009 !ruby/object:Gem::Requirement
161
144
  none: false
162
- requirements:
163
- - - ! '>='
164
- - !ruby/object:Gem::Version
165
- version: '0'
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ hash: 3
149
+ segments:
150
+ - 0
151
+ version: "0"
166
152
  type: :development
153
+ version_requirements: *id009
154
+ - !ruby/object:Gem::Dependency
155
+ name: bson_ext
167
156
  prerelease: false
168
- version_requirements: !ruby/object:Gem::Requirement
169
- none: false
170
- requirements:
171
- - - ! '>='
172
- - !ruby/object:Gem::Version
173
- version: '0'
174
- - !ruby/object:Gem::Dependency
175
- name: curb
176
- requirement: !ruby/object:Gem::Requirement
157
+ requirement: &id010 !ruby/object:Gem::Requirement
177
158
  none: false
178
- requirements:
179
- - - ! '>='
180
- - !ruby/object:Gem::Version
181
- version: '0'
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ hash: 3
163
+ segments:
164
+ - 0
165
+ version: "0"
182
166
  type: :development
167
+ version_requirements: *id010
168
+ - !ruby/object:Gem::Dependency
169
+ name: curb
183
170
  prerelease: false
184
- version_requirements: !ruby/object:Gem::Requirement
185
- none: false
186
- requirements:
187
- - - ! '>='
188
- - !ruby/object:Gem::Version
189
- version: '0'
190
- - !ruby/object:Gem::Dependency
191
- name: minitest
192
- requirement: !ruby/object:Gem::Requirement
171
+ requirement: &id011 !ruby/object:Gem::Requirement
193
172
  none: false
194
- requirements:
195
- - - ! '>='
196
- - !ruby/object:Gem::Version
197
- version: '0'
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ hash: 3
177
+ segments:
178
+ - 0
179
+ version: "0"
198
180
  type: :development
181
+ version_requirements: *id011
182
+ - !ruby/object:Gem::Dependency
183
+ name: minitest
199
184
  prerelease: false
200
- version_requirements: !ruby/object:Gem::Requirement
185
+ requirement: &id012 !ruby/object:Gem::Requirement
201
186
  none: false
202
- requirements:
203
- - - ! '>='
204
- - !ruby/object:Gem::Version
205
- version: '0'
206
- description: ! ' Tire is a Ruby client for the CSDNSearch search engine/database.
207
-
208
- '
187
+ requirements:
188
+ - - ">="
189
+ - !ruby/object:Gem::Version
190
+ hash: 3
191
+ segments:
192
+ - 0
193
+ version: "0"
194
+ type: :development
195
+ version_requirements: *id012
196
+ description: " Tire is a Ruby client for the CSDNSearch search engine/database.\n"
209
197
  email: wangxz@csdn.net
210
198
  executables: []
199
+
211
200
  extensions: []
212
- extra_rdoc_files:
201
+
202
+ extra_rdoc_files:
213
203
  - README.markdown
214
204
  - MIT-LICENSE
215
- files:
205
+ files:
216
206
  - .gitignore
217
207
  - .travis.yml
218
208
  - Gemfile
@@ -246,29 +236,41 @@ files:
246
236
  - test/unit/http_response_test.rb
247
237
  - test/unit/logger_test.rb
248
238
  - tire.gemspec
239
+ has_rdoc: true
249
240
  homepage: https://github.com/csdn-dev/tire
250
241
  licenses: []
242
+
251
243
  post_install_message:
252
- rdoc_options:
244
+ rdoc_options:
253
245
  - --charset=UTF-8
254
- require_paths:
246
+ require_paths:
255
247
  - lib
256
- required_ruby_version: !ruby/object:Gem::Requirement
248
+ required_ruby_version: !ruby/object:Gem::Requirement
257
249
  none: false
258
- requirements:
259
- - - ! '>='
260
- - !ruby/object:Gem::Version
261
- version: '0'
262
- required_rubygems_version: !ruby/object:Gem::Requirement
250
+ requirements:
251
+ - - ">="
252
+ - !ruby/object:Gem::Version
253
+ hash: 3
254
+ segments:
255
+ - 0
256
+ version: "0"
257
+ required_rubygems_version: !ruby/object:Gem::Requirement
263
258
  none: false
264
- requirements:
265
- - - ! '>='
266
- - !ruby/object:Gem::Version
259
+ requirements:
260
+ - - ">="
261
+ - !ruby/object:Gem::Version
262
+ hash: 23
263
+ segments:
264
+ - 1
265
+ - 3
266
+ - 6
267
267
  version: 1.3.6
268
268
  requirements: []
269
+
269
270
  rubyforge_project: tire
270
- rubygems_version: 1.8.24
271
+ rubygems_version: 1.3.9.4
271
272
  signing_key:
272
273
  specification_version: 3
273
274
  summary: Ruby client for CSDNSearch
274
275
  test_files: []
276
+