search_admin.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. defined('IN_PHPCMS') or exit('No permission resources.');
  3. pc_base::load_app_class('admin','admin',0);
  4. pc_base::load_sys_class('form','',0);
  5. class search_admin extends admin {
  6. function __construct() {
  7. parent::__construct();
  8. $this->siteid = $this->get_siteid();
  9. $this->db = pc_base::load_model('search_model');
  10. $this->module_db = pc_base::load_model('module_model');
  11. $this->type_db = pc_base::load_model('type_model');
  12. }
  13. public function setting() {
  14. $siteid = get_siteid();
  15. if(isset($_POST['dosubmit'])) {
  16. //合并数据库缓存与新提交缓存
  17. $r = $this->module_db->get_one(array('module'=>'search'));
  18. $search_setting = string2array($r['setting']);
  19. $search_setting[$siteid] = $_POST['setting'];
  20. $setting = array2string($search_setting);
  21. setcache('search', $search_setting);
  22. $this->module_db->update(array('setting'=>$setting),array('module'=>'search'));
  23. showmessage(L('operation_success'),HTTP_REFERER);
  24. } else {
  25. $r = $this->module_db->get_one(array('module'=>'search'));
  26. $setting = string2array($r['setting']);
  27. if($setting[$siteid]){
  28. extract($setting[$siteid]);
  29. }
  30. $big_menu = array('javascript:window.top.art.dialog({id:\'add\',iframe:\'?m=search&c=search_type&a=add\', title:\''.L('add_search_type').'\', width:\'580\', height:\'240\', lock:true}, function(){var d = window.top.art.dialog({id:\'add\'}).data.iframe;var form = d.document.getElementById(\'dosubmit\');form.click();return false;}, function(){window.top.art.dialog({id:\'add\'}).close()});void(0);', L('add_search_type'));
  31. include $this->admin_tpl('setting');
  32. }
  33. }
  34. /**
  35. * 创建索引
  36. */
  37. public function createindex() {
  38. if(isset($_GET['dosubmit'])) {
  39. //重建索引首先清空表所有数据,然后根据搜索类型接口重新全部重建索引
  40. if(!isset($_GET['have_truncate'])) {
  41. $db_tablepre = $this->db->db_tablepre;
  42. //删除该站点全文索引
  43. $this->db->delete(array('siteid'=>$this->siteid));
  44. $types = $this->type_db->select(array('siteid'=> $this->siteid,'module'=>'search'));
  45. setcache('search_types',$types, 'search');
  46. } else{
  47. $types = getcache('search_types', 'search');
  48. }
  49. //$key typeid 的索引
  50. $key = isset($_GET['key']) ? intval($_GET['key']) : 0;
  51. foreach ($types as $_k=>$_v) {
  52. if($key==$_k) {
  53. $typeid = $_v['typeid'];
  54. if($_v['modelid']) {
  55. if ($_v['typedir']!=='yp') {
  56. $search_api = pc_base::load_app_class('search_api','content');
  57. } else {
  58. $search_api = pc_base::load_app_class('search_api',$_v['typedir']);
  59. }
  60. if(!isset($_GET['total'])) {
  61. $total = $search_api->total($_v['modelid']);
  62. } else {
  63. $total = intval($_GET['total']);
  64. $search_api->set_model($_v['modelid']);
  65. }
  66. } else {
  67. $module = trim($_v['typedir']);
  68. $search_api = pc_base::load_app_class('search_api',$module);
  69. if(!isset($_GET['total'])) {
  70. $total = $search_api->total();
  71. } else {
  72. $total = intval($_GET['total']);
  73. }
  74. }
  75. $pagesize = $_GET['pagesize'] ? intval($_GET['pagesize']) : 50;
  76. $page = max(intval($_GET['page']), 1);
  77. $pages = ceil($total/$pagesize);
  78. $datas = $search_api->fulltext_api($pagesize,$page);
  79. foreach ($datas as $id=>$r) {
  80. $this->db->update_search($typeid ,$id, $r['fulltextcontent'],$r['title'],$r['adddate'], 1);
  81. }
  82. $page++;
  83. if($pages>=$page) showmessage("正在更新 <span style='color:#ff0000;font-size:14px;text-decoration:underline;' >{$_v['name']}</span> - 总数:{$total} - 当前第 <font color='red'>{$page}</font> 页","?m=search&c=search_admin&a=createindex&menuid=909&page={$page}&total={$total}&key={$key}&pagesize={$pagesize}&have_truncate=1&dosubmit=1");
  84. $key++;
  85. showmessage("开始更新: <span style='color:#ff0000;font-size:14px;text-decoration:underline;' >{$_v['name']}</span> - 总数:{$total}条","?m=search&c=search_admin&a=createindex&menuid=909&page=1&key={$key}&pagesize={$pagesize}&have_truncate=1&dosubmit=1");
  86. }
  87. }
  88. showmessage('全站索引更新完成','blank');
  89. } else {
  90. $big_menu = array('javascript:window.top.art.dialog({id:\'add\',iframe:\'?m=search&c=search_type&a=add\', title:\''.L('add_search_type').'\', width:\'580\', height:\'240\', lock:true}, function(){var d = window.top.art.dialog({id:\'add\'}).data.iframe;var form = d.document.getElementById(\'dosubmit\');form.click();return false;}, function(){window.top.art.dialog({id:\'add\'}).close()});void(0);', L('add_search_type'));
  91. include $this->admin_tpl('createindex');
  92. }
  93. }
  94. public function public_test_sphinx() {
  95. $sphinxhost = !empty($_POST['sphinxhost']) ? $_POST['sphinxhost'] : exit('-1');
  96. $sphinxport = !empty($_POST['sphinxport']) ? intval($_POST['sphinxport']) : exit('-2');
  97. $fp = @fsockopen($sphinxhost, $sphinxport, $errno, $errstr , 2);
  98. if (!$fp) {
  99. exit($errno.':'.$errstr);
  100. } else {
  101. exit('1');
  102. }
  103. }
  104. }
  105. ?>