chengkun
2025-05-22 3b321a2882db082c68aaf8771e0f55daa58a63d3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
<?php
/**
sphinx 辅助类
*/
class sphinxhelper
{
  //生成sphinx.conf 文件
  public function generateConf()
  {
    global $config, $db_config;
    $config['sphinx_path'] = rtrim($config['sphinx_path'], '/');
    $config['sphinx_path'] = rtrim($config['sphinx_path'], "\\");
 
    $content = <<<str
source common
{
  type      = mysql
  sql_host    = {$db_config['dbhost']}
  sql_user    = {$db_config['dbuser']}
  sql_pass    = {$db_config['dbpass']}
  sql_db      = {$db_config['dbname']}
  sql_port    = 3306
 
  sql_query_pre   = SET NAMES utf8
  
  sql_ranged_throttle = 0
}
 
index common
{
  path      = {$config['sphinx_path']}/data/common
 
  #charset_type = utf-8
  
  charset_table = 0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F
  
  #一元分词
  ngram_len = 1
  
  #中文分词
  ngram_chars = U+3000..U+2FA1F
  
  docinfo     = extern
 
  dict      = keywords
 
  mlock     = 0
 
  #morphology   = none
  morphology    = stem_en
  
  min_word_len    = 1
 
 
  html_strip    = 0
  
  expand_keywords = 1
}
 
source company_job : common
{
  sql_query   = \
    SELECT id, name, com_name, \
      did, uid, edate, state, sdate, rec_time, r_status, status, pr, hy, job1, job1_son, job_post, \
      provinceid, cityid, three_cityid, edu, exp, report, type, sex, is_graduate, mun, \
      maxsalary, minsalary, urgent_time, lastupdate, \
      com_provinceid, xsdate \
      FROM {$db_config['def']}company_job
      
  sql_attr_uint = did
  sql_attr_uint = uid
  
  sql_attr_uint = job1  
  sql_attr_uint = job1_son
  sql_attr_uint = job_post
  
  sql_attr_uint = com_provinceid
  sql_attr_uint = provinceid
  sql_attr_uint = cityid
  sql_attr_uint = three_cityid
  
  sql_attr_uint = hy
  sql_attr_timestamp = sdate
  sql_attr_timestamp = rec_time
  sql_attr_uint = r_status
  sql_attr_uint = status
  sql_attr_uint = pr
  sql_attr_uint = edu
  sql_attr_uint = exp
  sql_attr_uint = report
  sql_attr_uint = type
  sql_attr_uint = sex
  sql_attr_uint = is_graduate
  sql_attr_uint = mun
  
  sql_attr_uint = minsalary
  sql_attr_uint = maxsalary
  
  sql_attr_timestamp = edate
  sql_attr_uint = state
  sql_attr_timestamp = xsdate
  sql_attr_timestamp = lastupdate
  sql_attr_uint = urgent_time
  
  # sql_attr_string = com_name
}
 
source company_job_add : company_job
{
  sql_query   = \
    SELECT id, name, com_name, \
      did, uid, edate, state, sdate, rec_time, r_status, status, pr, hy, job1, job1_son, job_post, \
      provinceid, cityid, three_cityid, edu, exp, report, type, sex, is_graduate, mun, \
      maxsalary, minsalary, urgent_time, lastupdate, \
      com_provinceid, xsdate \
      FROM {$db_config['def']}company_job \
      where id > (select config from {$db_config['def']}admin_config where name='company_job_max_id' limit 1)
}
 
index company_job : common
{
  source      = company_job
  path      = {$config['sphinx_path']}/data/company_job
}
 
index company_job_add : common
{
  source      = company_job_add
  path      = {$config['sphinx_path']}/data/company_job_add
}
 
source resume_expect : common
{
  sql_query   = \
    SELECT id, uid, name, hy, hy != '' as hy_not_empty, job_classid, provinceid, cityid, three_cityid, \
      salary, jobstatus, type, report, defaults, is_entrust, doc, \
      hits, lastupdate, cloudtype, integrity, height_status, \
      statusbody, status_time, rec, top, topdate, rec_resume, source, \
      tmpid, ctime, dnum, did, uname, uname != '' as uname_not_empty, idcard_status, \
      status, r_status, edu, exp, sex, photo != '' as photo_not_empty, phototype, birthday, minsalary, maxsalary, \
      whour, avghour, label \
      FROM {$db_config['def']}resume_expect
 
  sql_attr_uint = did
  sql_attr_uint = uid
  sql_attr_uint = hy
  sql_field_string = job_classid
  sql_attr_uint = provinceid
  sql_attr_uint = cityid
  sql_attr_uint = three_cityid
    
  sql_attr_uint = r_status
  sql_attr_uint = status
  
  sql_attr_uint = edu
  sql_attr_uint = exp
  sql_attr_uint = report
  sql_attr_uint = type
  sql_attr_uint = sex
  
 
  sql_attr_uint = defaults
  sql_attr_uint = height_status
  sql_attr_uint = topdate
  sql_attr_uint = rec_resume
  
  sql_attr_timestamp = lastupdate
  
  #sql_field_string = name
  #sql_attr_string  = name
  
  #sql_attr_multi = string job_classid_multi from field job_classid
  
  sql_attr_uint = photo_not_empty
  sql_attr_uint = uname_not_empty
  sql_attr_uint = hy_not_empty
  
  sql_attr_uint = minsalary
  sql_attr_uint = maxsalary
}
 
 
source resume_expect_add : resume_expect
{
  sql_query   = \
    SELECT id, uid, name, hy, hy != '' as hy_not_empty, job_classid, provinceid, cityid, three_cityid, \
      salary, jobstatus, type, report, defaults, is_entrust, doc, \
      hits, lastupdate, cloudtype, integrity, height_status, \
      statusbody, status_time, rec, top, topdate, rec_resume, source, \
      tmpid, ctime, dnum, did, uname, uname != '' as uname_not_empty, idcard_status, \
      status, r_status, edu, exp, sex, photo != '' as photo_not_empty, phototype, birthday, minsalary, maxsalary, \
      whour, avghour, label \
      FROM {$db_config['def']}resume_expect \
      where id > (select config from {$db_config['def']}admin_config where name='resume_expect_max_id' limit 1)
}
 
index resume_expect : common
{
  source      = resume_expect
  path      = {$config['sphinx_path']}/data/resume_expect
}
index resume_expect_add : common
{
  source      = resume_expect_add
  path      = {$config['sphinx_path']}/data/resume_expect_add
}
 
source once_job : common
{
  sql_query   = \
    SELECT id, did, status, edate, ctime, title, companyname \
      FROM {$db_config['def']}once_job
 
  sql_attr_uint = did
  sql_attr_uint = status
  sql_attr_uint = edate
  sql_attr_uint = ctime
}
 
source once_job_add : once_job
{
  sql_query   = \
    SELECT id, did, status, edate, ctime, title, companyname \
      FROM {$db_config['def']}once_job \
      where id > (select config from {$db_config['def']}admin_config where name='once_job_max_id' limit 1)
}
 
index once_job : common
{
  source      = once_job
  path      = {$config['sphinx_path']}/data/once_job
}
index once_job_add : common
{
  source      = once_job_add
  path      = {$config['sphinx_path']}/data/once_job_add
}
 
source resume_tiny : common
{
  sql_query   = \
    SELECT id, did, status, username, job, lastupdate \
      FROM {$db_config['def']}resume_tiny
 
  sql_attr_uint = did
  sql_attr_uint = status
  sql_attr_uint = lastupdate
}
 
source resume_tiny_add : resume_tiny
{
  sql_query   = \
    SELECT id, did, status, username, job, lastupdate \
      FROM {$db_config['def']}resume_tiny \
      where id > (select config from {$db_config['def']}admin_config where name='resume_tiny_max_id' limit 1)
}
 
index resume_tiny : common
{
  source      = resume_tiny
  path      = {$config['sphinx_path']}/data/resume_tiny
}
index resume_tiny_add : common
{
  source      = resume_tiny_add
  path      = {$config['sphinx_path']}/data/resume_tiny_add
}
 
source news_base : common
{
  sql_query   = \
    SELECT id, did, nid, \
      FIND_IN_SET('t', `describe`) as describe_t, \
      FIND_IN_SET('tj', `describe`) as describe_tj, \
      FIND_IN_SET('indextj', `describe`) as describe_indextj, \
      FIND_IN_SET('db', `describe`) as describe_db, \
      newsphoto != '' newsphoto_not_empty, \
      title, \
      datetime, hits \
      FROM {$db_config['def']}news_base
 
  sql_attr_uint = did
  sql_attr_uint = nid
  sql_attr_uint = describe_t
  sql_attr_uint = describe_tj
  sql_attr_uint = describe_indextj
  sql_attr_uint = describe_db
  sql_attr_uint = newsphoto_not_empty
  sql_attr_uint = datetime
  sql_attr_uint = hits
}
 
source news_base_add : news_base
{
  sql_query   = \
    SELECT id, did, nid, \
      FIND_IN_SET('t', `describe`) as describe_t, \
      FIND_IN_SET('tj', `describe`) as describe_tj, \
      FIND_IN_SET('indextj', `describe`) as describe_indextj, \
      FIND_IN_SET('db', `describe`) as describe_db, \
      newsphoto != '' newsphoto_not_empty, \
      title, \
      datetime, hits \
      FROM {$db_config['def']}news_base \
      where id > (select config from {$db_config['def']}admin_config where name='news_base_max_id' limit 1)
}
 
index news_base : common
{
  source      = news_base
  path      = {$config['sphinx_path']}/data/news_base
}
index news_base_add : common
{
  source      = news_base_add
  path      = {$config['sphinx_path']}/data/news_base_add
}
 
source partjob : common
{
  sql_query   = \
    SELECT id, did state, r_status, name, \
      provinceid, cityid, three_cityid, rec_time, type, \
      billing_cycle, lastupdate \
      FROM {$db_config['def']}partjob
 
  sql_attr_uint = did
  sql_attr_uint = state
  sql_attr_uint = r_status
  sql_attr_uint = rec_time
  sql_attr_uint = type
  sql_attr_uint = billing_cycle
  
  sql_attr_uint = provinceid
  sql_attr_uint = cityid
  sql_attr_uint = three_cityid
  sql_attr_uint = lastupdate
}
 
source partjob_add : partjob
{
  sql_query   = \
    SELECT id, did, state, r_status, name, \
      provinceid, cityid, three_cityid, rec_time, type, \
      billing_cycle, lastupdate \
      FROM {$db_config['def']}partjob \
      where id > (select config from {$db_config['def']}admin_config where name='partjob_max_id' limit 1)
}
 
index partjob : common
{
  source      = partjob
  path      = {$config['sphinx_path']}/data/partjob
}
index partjob_add : common
{
  source      = partjob_add
  path      = {$config['sphinx_path']}/data/partjob_add
}
 
source company : common
{
  sql_query   = \
    SELECT uid, did, name, hy, pr, mun, \
      provinceid, cityid, three_cityid, \
      r_status, yyzz_status, \
      lastupdate, jobtime, rec, hottime, \
      name != '' as name_not_empty, \
      hy != '' as hy_not_empty, \
      logo != '' as logo_not_empty, \
      linkman != '' as linkman_not_empty, \
      linktel != '' as linktel_not_empty, \
      linkmail != '' as linkmail_not_empty, \
      jobtime != '' as jobtime_not_empty \
      FROM {$db_config['def']}company
 
  sql_attr_uint = did
  sql_attr_uint = hy
  sql_attr_uint = pr
  sql_attr_uint = mun
  # sql_attr_uint = uid
  sql_attr_uint = provinceid
  sql_attr_uint = cityid
  sql_attr_uint = three_cityid
  sql_attr_uint = r_status
  sql_attr_uint = yyzz_status
  sql_attr_uint = lastupdate
  sql_attr_uint = jobtime
  sql_attr_uint = rec
  sql_attr_uint = hottime
  
  sql_attr_uint = name_not_empty
  sql_attr_uint = hy_not_empty
  sql_attr_uint = logo_not_empty
  sql_attr_uint = linkman_not_empty
  sql_attr_uint = linktel_not_empty
  sql_attr_uint = linkmail_not_empty
  sql_attr_uint = jobtime_not_empty
}
 
source company_add : company
{
  sql_query   = \
    SELECT uid, did, name, hy, pr, mun, \
      provinceid, cityid, three_cityid, \
      r_status, yyzz_status, \
      lastupdate, jobtime, rec, hottime, \
      name != '' as name_not_empty, \
      hy != '' as hy_not_empty, \
      logo != '' as logo_not_empty, \
      linkman != '' as linkman_not_empty, \
      linktel != '' as linktel_not_empty, \
      linkmail != '' as linkmail_not_empty, \
      jobtime != '' as jobtime_not_empty \
      FROM {$db_config['def']}company \
      where uid > (select config from {$db_config['def']}admin_config where name='company_max_id' limit 1)
}
 
index company : common
{
  source      = company
  path      = {$config['sphinx_path']}/data/company
}
index company_add : common
{
  source      = company_add
  path      = {$config['sphinx_path']}/data/company_add
}
#############################################################################
## indexer settings
#############################################################################
indexer
{
  mem_limit   = 128M
}
 
#############################################################################
## searchd settings
#############################################################################
searchd
  # expansion_limit = 1
  
  listen      = 9312
  listen      = 9306:mysql41
 
  log     = {$config['sphinx_path']}/log/searchd.log
 
  query_log   = {$config['sphinx_path']}/log/query.log
 
  # client read timeout, seconds
  # optional, default is 5
  read_timeout    = 5
 
  # request timeout, seconds
  # optional, default is 5 minutes
  client_timeout    = 300
 
  max_children    = 30
 
  persistent_connections_limit  = 30
 
  pid_file    = {$config['sphinx_path']}/log/searchd.pid
 
  seamless_rotate   = 1
 
  preopen_indexes   = 1
 
  unlink_old    = 1
 
  mva_updates_pool  = 1M
 
  max_packet_size   = 8M
 
  max_filters   = 256
 
  max_filter_values = 4096
 
  max_batch_queries = 32
 
  workers     = threads # for RT to work
}
str;
    
    //linux中涉及权限问题,不可在 /home/wwwroot/www.job.com/ 目录之外操作文件,所以利用sh文件来执行
    if(isServerOsWindows() === false){
      $content = str_replace("\r\n", PHP_EOL, $content);
      
      // file_put_contents($config['sphinx_path'] . '/sphinx.conf', $content);
      file_put_contents(APP_PATH . 'data/sphinx/sphinx.conf', $content);
 
      $shPath = APP_PATH . 'data/sphinx/mkdir.sh';
      $s0 = APP_PATH . 'data/sphinx/sphinx.conf';
      $s1 = $config['sphinx_path'] . '/sphinx.conf';
      exec("sh $shPath $s0 $s1");
    }
    else{
      file_put_contents($config['sphinx_path'] . '/bin/sphinx.conf', $content);
    }
 
    // if(!is_dir($config['sphinx_path'] . '/data/')){
    //   mkdir($config['sphinx_path'] . '/data/', 777, true);
    // }
    
    // if(!is_dir($config['sphinx_path'] . '/log/')){
    //   mkdir($config['sphinx_path'] . '/log/', 777, true);
    // }
 
    
  }
}