특정 단어를 검색에서 제외시키려면... > 그누4 질문답변

그누4 질문답변

그누보드4 관련 질문은 QA 로 이전됩니다. QA 그누보드4 바로가기
기존 게시물은 열람만 가능합니다.

특정 단어를 검색에서 제외시키려면... 정보

특정 단어를 검색에서 제외시키려면...

본문

<?
include_once("./_common.php");

include_once("$g4[path]/head.sub.php");


function getmicrotime()
{
  list($usec, $sec) = explode(" ", microtime());
  return ((float)$usec + (float)$sec);
};

$time1 = getmicrotime();

// 검섹 테이블 정의
$g7['table_prefix']        = "g7_"; //
$g7['content']            = $g7['table_prefix'] ."content";  //통합게시물
$g7['words']              = $g7['table_prefix'] ."words";    //단어별 저장
$g7['word_key']            = $g7['table_prefix'] ."word_key"; //정보모음 tmp
$g7['tmp']                = $g7['table_prefix'] ."tmp";

if (!$sop || !($sop == "and" || $sop == "or")) $sop = "or"; // 연산자 and , or

$sfl = "word";
$q  = trim($q);

if($match == '1')
$match_checked = "checked";

$op1 = "";
//구분자
$s = array();
$s = explode(" ", $q);
$s_total_num = count($s);
$s_num = 1; //첫번째단어만 검색


/*******************두번째 단어에 대한 유사어 **************/
if($s_total_num > 1){
  $s_sub_word = $s[1]; // 2번째 공통단어
  //echo $s_sub_word;

$str = "(";
 for ($i=0; $i<1; $i++)
 {
//2글자 이내는 제외
if(strlen($s_sub_word) < 3) continue;

        $search_str = $s_sub_word;

        $str .= $op1;
        $str .= "(";

        $op2 = "";
$str .= $op2;

      switch ($match) {
        case "1" :
    $str .= "$sfl like '$search_str%' ";
            break;
        default :
            $str .= "INSTR($sfl, '$search_str')";
            break;
      }

$op2 = " or ";
        $str .= ")";

        $op1 = " $sop ";

 }
$str .= ")";

$sql_search2 = $str;

 $sql2 = " select id,word from $g7[words] where $sql_search2 order by word ";
 $result2 = sql_query($sql2, false);
 $row2[cnt] = @mysql_num_rows($result2);


  /******$row2[cnt] start****/
 if($row2[cnt]){

      for ($t=0; $list2=sql_fetch_array($result2); $t++)
      {


              $g4_search2[id][] = $list2[id];

  //해당 id 에 포함되어있는 게시물수량
  $w_num2 = sql_fetch(" select count(*) as cnt from $g7[word_key] where w_id = '$list2[id]' ");

// echo $list2[word]; 
  }
    $total_arr2 = count($g4_search2[id]);
    $total_count2 = 0;

    $w_id2  = "w_id";
$str2 = "(";
    $op12 = "";

    for ($u=0; $u<$total_arr2; $u++)
    {

$search_o2 = $g4_search2[id][$u];



        $str2 .= $op12;
        $str2 .= "(";

        $op22 = "";
$str2 .= $op22;


$str2 .= " $w_id2 = '$search_o2' ";

$op22 = " or ";
        $str2 .= ")";

        $op12 = " or ";


}
$str2 .= ")";

$sql_search2 = $str2;


/************두번째 단어 임시테이블 저장 저장 ***************/

$tmp_table2 = "tmp2";

//2차 검색값 호출
$tmp_insert2 = sql_query(" select distinct p_id from $g7[word_key] where $sql_search2 ");
   
//임시테이블 생성 , html_idx int, INDEX(html_idx))
sql_query("create temporary table $tmp_table2(id varchar(10), INDEX(id))");

while ($tmp_row2 = sql_fetch_array($tmp_insert2)) {
          sql_query("insert into $tmp_table2 set id = '$tmp_row2[p_id]' ");
}


/************두번째 단어 임시테이블 저장 저장 ***************/


 
 }/******$row2[cnt] end****/

}
/*******************두번째 단어에 대한 유사어 **************/

$time2 = getmicrotime();

$op1 = "";
$str = "(";
 for ($i=0; $i<$s_num; $i++)
 {
//2글자 이내는 제외
if(strlen($s[$i]) < 3) continue;

        $search_str = $s[$i];

        $str .= $op1;
        $str .= "(";

        $op2 = "";
$str .= $op2;

      switch ($match) {
        case "1" :
    $str .= "$sfl like '$search_str%' ";
            break;
        default :
            $str .= "INSTR($sfl, '$search_str')";
            break;
      }

$op2 = " or ";
        $str .= ")";

        $op1 = " $sop ";

 }
$str .= ")";

$sql_search = $str;




if($q){

 $sql = " select id,word from $g7[words] where $sql_search order by word ";
 $result = sql_query($sql, false);
 $row[cnt] = @mysql_num_rows($result);
}

/*********************************/
 if($row[cnt]){

      $word_str = "<b>관련검색</b> ($row[cnt])<br>";
      for ($s=0; $row=sql_fetch_array($result); $s++)
      {


              $g4_search[id][] = $row[id];

  //해당 id 에 포함되어있는 게시물수량
  $w_num = sql_fetch(" select count(*) as cnt from $g7[word_key] where w_id = '$row[id]' ");


    $word_str .= "<a href='$g4[path]/g7_search/search.php?q=".$row[word]."&match=1'>".$row[word]."</a>";
    $word_str .= "<br>";


  }




    $total_arr = count($g4_search[id]);
    $total_count = 0;

    $w_id  = "w_id";
$str = "(";
    $op1 = "";

    for ($i=0; $i<$total_arr; $i++)
    {

$search_o = $g4_search[id][$i];



        $str .= $op1;
        $str .= "(";

        $op2 = "";
$str .= $op2;


$str .= " $w_id = '$search_o' ";

$op2 = " or ";
        $str .= ")";

        $op1 = " or ";


}
$str .= ")";

$sql_search = $str;

/************첫번째 단어 임시테이블 저장 저장 ***************/
$tmp_table1 = "tmp1";

//1차 검색값 호출
$tmp_insert = sql_query(" select distinct p_id from $g7[word_key] where $sql_search ");
   
//임시테이블 생성
sql_query("create temporary table $tmp_table1(id varchar(10), INDEX(id) )");

while ($tmp_row = sql_fetch_array($tmp_insert)) {
          sql_query("insert into $tmp_table1 set id = '$tmp_row[p_id]' ");
}





if($tmp_table2 and $tmp_table1){//2개 단어 비교
//공통포함
$common_row = sql_fetch(" select count(*) as cnt from $tmp_table1 a, $tmp_table2 b where a.id = b.id");
}
else{//1개 단어만 존재
$common_row = sql_fetch(" select count(*) as cnt from $tmp_table1 a ");
}



if($tmp_table2 and $tmp_table1){
      $sql_common2 = " from $tmp_table1 a, $tmp_table2 b ";
      $sql_search2 = " where a.id = b.id ";
}
else{
      $sql_common2 = " from $tmp_table1 a ";
      $sql_search2 = " ";
}

$total_count = $common_row[cnt];

    $rows = 10;

    $total_page  = ceil($total_count / $rows);  // 전체 페이지 계산
    if ($page == "") { $page = 1; } // 페이지가 없으면 첫 페이지 (1 페이지)
    $from_record = ($page - 1) * $rows; // 시작 열을 구함

    $sql_order2 = " order by a.id desc ";

    $tmp_list = sql_query(" select *
                            $sql_common2
$sql_search2 
$sql_order2 
  limit $from_record, $rows ");


/************첫번째 단어 임시테이블 저장 저장 ***************/


$time3 = getmicrotime();



 }


$pagelist = get_paging("10", $page, $total_page, "$_SERVER[PHP_SELF]?$qstr&q=$q&page=");
/*********************************/

?>

<style type="text/css">
#content_text{float:left;margin-top:20px;margin-left:20px;}
h1 {text-align:left;padding:0px;font:1.20em verdana;}

.searchbox { clear:both; width:900px; table-layout:fixed; margin:5px 0 0 0; }
.searchbox ul {margin:0;list-style-type:none;list-style-image:none;height:22px;}
.searchbox li {float:left;margin-right:5px;}

#total_cont { clear:both; width:100%; height:31px;background:#fff url(<?=$g4[path]?>/g7_search/img/total.gif) 100% 0px repeat-x; table-layout:fixed; margin:5px 0 0 0; }
#total_cont #title {float:left;margin-left:10px;margin-top:5px;};
#total_cont #content {float:right;margin-right:10px;margin-top:5px;font: 13px/20px arial!important;/*color:#4E2207;*/text-decoration:none;};

#search_detail {clear:both; width:100%;}
#search_detail #result {float:left;width:600px;}
#search_detail #result ul {margin:0;list-style-type:none;list-style-image:none;height:14px;}
#search_detail #result li {float:left;margin-right:5px;}

#search_detail #relate {float:right;width:30%;font:bold 13px/20px arial!important;color:#4e4c4c;text-decoration:none;}


</style>


<div id="content_text">
<form id="s" method="get" action="search.php">
  <div class="searchbox">
  <ul>
    <li>
  <input type="text" size="35" name="q" id="q" class="s_text" value="<?php
  $q = '';
  if (isset($_GET['q'])) {
      if (isset($q_plus) && $q_plus == 1) {
        $q = urldecode($_GET['q']);
      }
      else {
        $q = $_GET['q'];
      }
  }
  echo $q;
  ?>" />
</li>
<li><input type="submit" name="Submit" value="Go!" class="s_text" /></li>
<li><input type=checkbox value='1' name='match' <?=$match_checked?> >일치</li>

  </ul>
  </div>
</form>
 
<div style="clear:both;line-height:10px;"></div>
<div id="total_cont">
  <div id="title">
  <?
  if($q){
$pass1 = sprintf( "%4.4f", $time2 - $time1 );
$pass2 = sprintf( "%4.4f", $time3 - $time2 );
$pass3 = sprintf( "%4.4f", $time3 - $time1 );



echo " 2번째단어:".$pass1."초 &nbsp;&nbsp;";
echo " 1번째단어:".$pass2."초 &nbsp;&nbsp;";
echo " 총시간:".$pass3."초 ";
}
  ?>
  </div>
  <div id="content" >
  <?  if($q){?><b><?=$q?></b>에 대한 약<b><? echo number_format($total_count);?></b>개 결과페이지 중 <b><?=$rows*$page - $rows + 1?> - <?=$rows*$page?></b><?}?>
  </div>
</div>

<div id="search_detail">
  <div id="result" style="margin-top:10px;">


  <?

while ($tmp_list2 = sql_fetch_array($tmp_list)) {

      //관련 단어
      $relate_list = sql_query(" select w_id, p_id from $g7[word_key] where p_id = '$tmp_list2[id]' ");
 
  $p_row  = sql_fetch(" select url, url_title,content, last_crawled from  $g7[content] where id = '$tmp_list2[id]' ");

    echo "<ul style='margin-top:5px;'><li>";
echo "<a href='$p_row[url]' target='_blank'><font color='#0000cc'>$p_row[url_title]</font></a>";
echo "</li></ul>";
    echo "<ul style='margin-top:7px;height:45px'><li>";
//$text = eregi_replace("<[^>]*>","",$p_row[content]);
// echo $text;


        echo  cut_str(trim(strip_tags($p_row[content])),300,""); 
// echo cut_hangul_last(get_text($text));
echo "</li></ul>";//
}


if ($total_count == 0 and $q)
    echo "<ul style='margin-top:100px;'><li style='height:250px;align:center'>자료가 없습니다.</li>";


  ?>
  <ul >
      <li style='margin-top:50px;width:700px;float:right'><?=$pagelist?></li>
  </ul>



  </div>

  <div id="relate"><?=$word_str?>

  </div>

</div>


</div>


<?

function get_num($hp)
{
    $hp = str_replace('-', '', trim($hp));
    if (preg_match("/^([0123456789]{0,4})([0-9]{3,4})([0-9]{4})$/", $hp))
        return true;
    else
        return false;
}



?>

-------------------------------------------------------------------------------------------------

위 코드는 뮤존님의 검색엔진 소스인데, 특정 단어를 검색에서 제외시키려면 어떻게 해야 하나요?;;
  • 복사

댓글 전체

© SIRSOFT
현재 페이지 제일 처음으로