You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
3.7 KiB

7 years ago
5 years ago
7 years ago
5 years ago
7 years ago
5 years ago
7 years ago
5 years ago
7 years ago
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. class Search_model extends WB_Model
  4. {
  5. /**
  6. * 카테고리별 검색 결과를 가져온다.
  7. * @param $search_text
  8. * @param $search_type
  9. */
  10. function search_result_detail( $search_text, $brd_key ="", $limit=0, $page=1)
  11. {
  12. $search_array = explode(" ", $search_text);
  13. $this->db->select("board_post.*, board.brd_title");
  14. $this->db->from('board_post');
  15. $this->db->join("board", "board.brd_key=board_post.brd_key", "inner" );
  16. $this->db->where('post_status','Y');
  17. $this->db->group_start();
  18. foreach( $search_array as $st )
  19. {
  20. $this->db->like("post_title", trim($st));
  21. $this->db->or_like("post_nickname", trim($st));
  22. //$this->db->or_like("post_content", trim($st));
  23. }
  24. $this->db->group_end();
  25. $this->db->order_by("post_idx DESC");
  26. if( $brd_key )
  27. {
  28. $this->db->where('board_post.brd_key', $brd_key);
  29. }
  30. if( $limit > 0 )
  31. {
  32. $start = ($page-1) * $limit;
  33. $this->db->limit($limit, $start);
  34. }
  35. $result = $this->db->get();
  36. $list = $result->result_array();
  37. $this->load->library('boardlib');
  38. foreach($list as &$row)
  39. {
  40. $b = $this->boardlib->get($row['brd_key']);
  41. $row = $this->boardlib->post_process($b, $row, '', TRUE, TRUE);
  42. }
  43. return $list;
  44. }
  45. function search_result( $search_text, $board_key = "total" ,$page =1 )
  46. {
  47. $return = array();
  48. // 검색어를 공백으로 나누어 OR 검색을 한다.
  49. $search_array = explode(" ", $search_text);
  50. // 일단 검색어와 일치하는 각각의 개수를 가져온다.
  51. $this->db->select("board_post.brd_key,brd_title, COUNT(*) AS `cnt`");
  52. $this->db->from("board_post");
  53. $this->db->join("board","board.brd_key=board_post.brd_key","inner");
  54. $this->db->where('post_status','Y');
  55. foreach($search_array as $st)
  56. {
  57. $this->db->like("post_title", trim($st));
  58. $this->db->or_like("post_nickname", trim($st));
  59. //$this->db->or_like("post_content", trim($st));
  60. }
  61. $this->db->group_by("board_post.brd_key");
  62. $result = $this->db->get();
  63. $search_count = $result->result_array();
  64. // 각 카테고리별 검색수 초기화
  65. $return['count']['total'] = 0;
  66. $return['title'] = array();
  67. $return['title']['total'] = langs('공통/search/search_total');
  68. // ROW를 돌면서 카테고리별 검색수를 합산해준다.
  69. foreach($search_count as $ct)
  70. {
  71. $return['count'][ $ct['brd_key'] ] = (int)$ct['cnt'];
  72. $return['title'][ $ct['brd_key'] ] = $ct['brd_title'];
  73. $return['count']['total'] += (int)$ct['cnt'];
  74. }
  75. // 실제 검색결과를 가져온다.
  76. $return['list']['total'] = array();
  77. // 검색타입에 따라 가져오는 숫자를 달리한다.
  78. if( $board_key == 'total' )
  79. {
  80. $return['list']['total'] = $this->search_result_detail($search_text,"",8);
  81. foreach($return['count'] as $brd=>$row)
  82. {
  83. if($brd =='total') continue;
  84. $return['list'][$brd] = $this->search_result_detail($search_text,$brd, 4);
  85. }
  86. }
  87. else {
  88. $return['list'][$board_key] = $this->search_result_detail($search_text, $board_key, 5, $page);
  89. unset($return['list']['total']);
  90. }
  91. $return['board_key'] = $board_key;
  92. return $return;
  93. }
  94. }