Drifter

1원 짜리 팁 검색창에 오타 입력 후 검색 하면 .... 검색결과에 오타와 관련된 상품 보여주기

1771548037_nvuqap1Zza.webp

1772072923_idMBgxVWyH.webp
shop.suggest.php 를 lib
폴더에 업로드 합니다.
(45번줄 에서 적당히 값을 조절해 줍니다. 임계값)
아래를 참고 하셔서 수정해 줍니다.

사용중 이신 폴더로 이동 후 search.skin.php 상단


<?php

// [검색어 변수 확인]
$search_word = isset($stx) && trim($stx) ? trim($stx) : (isset($q) ? trim($q) : trim($_GET['q'] ?? ''));
$recommend_words = array();

// [1번: 자모 분리 함수 정의]
if (!function_exists('get_jamo_eyoom')) {
    function get_jamo_eyoom($str) {
        $cho = array("ㄱ","ㄲ","ㄴ","ㄷ","ㄸ","ㄹ","ㅁ","ㅂ","ㅃ","ㅅ","ㅆ","ㅇ","ㅈ","ㅉ","ㅊ","ㅋ","ㅌ","ㅍ","ㅎ");
        $jung = array("ㅏ","ㅐ","ㅑ","ㅒ","ㅓ","ㅔ","ㅕ","ㅖ","ㅗ","ㅘ","ㅙ","ㅚ","ㅛ","ㅜ","ㅝ","ㅞ","ㅟ","ㅠ","ㅡ","ㅢ","ㅣ");
        $jong = array("","ㄱ","ㄲ","ㄳ","ㄴ","ㄵ","ㄶ","ㄷ","ㄹ","ㄺ","ㄻ","ㄼ","ㄽ","ㄾ","ㄿ","ㅀ","ㅁ","ㅂ","ㅄ","ㅅ","ㅆ","ㅇ","ㅈ","ㅊ","ㅋ","ㅌ","ㅍ","ㅎ");
        $result = "";
        $str = preg_replace("/[^a-zA-Z0-9가-힣]/u", "", $str);
        for ($i=0; $i<mb_strlen($str, 'UTF-8'); $i++) {
            $char = mb_substr($str, $i, 1, 'UTF-8');
            $code = function_exists('mb_ord') ? mb_ord($char, 'UTF-8') : unpack('V', iconv('UTF-8', 'UCS-4LE', $char))[1];
            if ($code >= 44032 && $code <= 55203) {
                $temp = $code - 44032;
                $result .= $cho[(int)($temp / 588)].$jung[(int)(($temp % 588) / 28)].$jong[(int)($temp % 28)];
            } else { $result .= $char; }
        }
        return $result;
    }
}

// [2번: 상품 비교 및 추천어 추출 로직]
if ($total_count == 0 && $search_word) {
    $stx_jamo = get_jamo_eyoom($search_word);
    $suggestions = array();
    
    // DB에서 판매중인 상품 최근 1,000개 비교
    $sql = " SELECT it_name FROM {$g5['g5_shop_item_table']} WHERE it_use = '1' ORDER BY it_id DESC LIMIT 1000 ";
    $res = sql_query($sql);

    while($row = sql_fetch_array($res)) {
        $item_name = $row['it_name'];
        $item_jamo = get_jamo_eyoom($item_name);
        
        // 검색어 길이에 맞춰 상품명 앞부분만 비교 (오타 교정 확률 UP)
        $target_jamo = mb_substr($item_jamo, 0, mb_strlen($stx_jamo, 'UTF-8') + 3);
        $dist = levenshtein($stx_jamo, $target_jamo);
        
        // 포함 여부 체크 (자모가 포함되어 있으면 우선 추천)
        $is_contain = (strpos($item_jamo, $stx_jamo) !== false);

        if (($dist >= 1 && $dist <= 12) || $is_contain) {
            $suggestions[$item_name] = $dist;
        }
    }
    asort($suggestions);
    $recommend_words = array_slice(array_keys($suggestions), 0, 3);
}

?>

보여 주고 싶은곳 적절한 위치에 ....

<!-- 이윰 테마 호환 추천 상품 바로가기 -->
<?php if (!empty($recommend_words)) { ?>
<div style="clear:both; display:block; width:100%; margin:0 0 25px 0; padding:25px; border:1px solid #e2e2e2; background:#f9f9f9; text-align:center; box-sizing:border-box; border-radius:5px;">
    <p style="margin:0 0 15px; color:#333; font-size:16px; font-weight:bold;">
        <i class="fa fa-lightbulb-o" style="color:#ff5722;"></i> 찾으시는 결과가 없나요? 이 상품을 찾으시나요?
    </p>
    <div style="display:flex; flex-wrap:wrap; justify-content:center; gap:10px;">
        <?php 
        foreach($recommend_words as $word) { 
            // 1. 상품명($word)으로 실제 it_id를 조회합니다.
            $row = sql_fetch(" select it_id from {$g5['g5_shop_item_table']} where it_name = '".sql_real_escape_string($word)."' and it_use = '1' limit 1 ");
            
            // 2. 상품 ID가 있으면 상세페이지로, 없으면 기존 검색 링크로 연결
            if ($row['it_id']) {
                $direct_url = G5_SHOP_URL . "/item.php?it_id=" . $row['it_id'];
            } else {
                $direct_url = "./search.php?q=" . urlencode($word);
            }
        ?>
            <a href="<?php echo $direct_url; ?>" style="display:inline-block; padding:8px 18px; border:1px solid #d1d1d1; background:#fff; color:#333; border-radius:30px; font-size:14px; text-decoration:none; transition:all 0.2s; box-shadow:0 2px 4px rgba(0,0,0,0.03);">
                # <?php echo $word; ?>
            </a>
        <?php } ?>
    </div>
</div>
<?php } ?>
<!-- // 추천 검색어 끝 -->

* 클릭시 상품명을 재검색 하는게 아니라 해당 상품으로
보내게끔 수정 했습니다. 2602210233.

적용 - https://ysmoto.kr/shop/search.php?q=OIK

 

첨부파일

shop.suggest.lib.php (2 KB) 0회 2026-02-20 08:48
Screen_Recording_20260225_204836_Samsung Internet.mp4 (5.5 MB)
0회 다운로드 2026-02-25 20:48
|
댓글을 작성하시려면 로그인이 필요합니다.

영카트5 팁자료실

+
제목 글쓴이 날짜 조회
14시간 전 조회 10
5일 전 조회 72
1주 전 조회 60
1주 전 조회 65
1주 전 조회 73
1주 전 조회 158
2주 전 조회 81
3주 전 조회 270
4주 전 조회 389
2개월 전 조회 712
2개월 전 조회 665
2개월 전 조회 723
3개월 전 조회 909
4개월 전 조회 1,105
4개월 전 조회 686
4개월 전 조회 857
4개월 전 조회 996
4개월 전 조회 814
4개월 전 조회 865
4개월 전 조회 907
5개월 전 조회 1,008
5개월 전 조회 830
5개월 전 조회 811
5개월 전 조회 990
5개월 전 조회 979
5개월 전 조회 852
6개월 전 조회 1,140
6개월 전 조회 1,180
6개월 전 조회 967
6개월 전 조회 1,028