Bonjour à tous,

J'ai mon moteur de recherche interne qui ne trouve pas les produits. Du moins, quand on tape un mot clé il affiche une liste déroulante avec les produits qui possèdent le mot clé mais si on clique sur un des produits dans la liste déroulante, il ne va pas sur le produit et n'affiche aucun résultat de la recherche.

En gros il y a deux problèmes distincts avec le moteur de recherche du site.

1. Lorsqu'on tape un mot clé dans la barre de recherche, il propose une mini liste en dessous de la barre de recherche sous forme autocomplétion des produits contenants ce mot clé mais si on clique sur une des propositions le lien qui dirige vers le produit ne fonctionne pas et donc il n'affiche aucun résultat. Cela est géré par la function_search du controller et par search_project du model. Le site est en CMS

2. sans utiliser l'autocomplétion, en tapant simplement un mot clé et cliqué sur recherche, il doit faire apparaitre sur la page le liste des produits trouvés contenant le mot clé. Hors la page n'affiche pas de résultats. Cette partie du code où le résultat est affiché sur la page est à la ligne 50 du dernier code fourni dans mon post.

Voici le controller Home.php:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
function search($offset=0)
{  
    if (! class_exists('Alternate')){
        include_once(APPPATH.'libraries/Alternate'.EXT);
    }
    $obj =& get_instance();
    $obj->altpage = new Alternate();
    $obj->ci_is_loaded[] = 'altpage';
    $limit = 9;
    if($this->input->post('searchprj')!='')
    {          
        $match = $this->input->post('searchprj');
    }
    elseif($this->session->userdata('match')!='')
    {
        $match='none';
    }
    else
    {
        $match='none';
    }
    $data['searchprj'] = '';
    $match=str_replace(array('"'),'',str_replace(array(",","`"),'',$match));
 
    $config['base_url'] = site_url('home/search/');
    $config['total_rows'] = $this->home_model->search_project_count($match);
    $config['per_page'] = $limit;      
    $this->altpage->initialize($config);     
    $data['page_link'] = $this->altpage->create_links();
 
    $data['result'] = $this->home_model->search_project($offset, $limit,$match);
    $data['result_selection'] = $this->home_model->selection();
    $data['result_popular'] = $this->home_model->popular();
    $data['result_endingsoon'] = $this->home_model->ending_soon();
    $data['result_all_project'] = $this->home_model->all_project();
    $data['result_all_project_featured'] = $this->home_model->all_project_featured();
    $data['result_alternative_projects'] = $this->home_model->alternative_projects();
    $data['match'] = $match;
    $data['offset'] = $offset;
    $data['limit'] = $limit;
    $data['total_rows'] = $config['total_rows'];
    $data['per_page'] = $limit;
 
    $data['site_setting'] = $this->home_model->select_site_setting();
 
    $data['searchprj'] = $this->input->post('searchprj');
    $data['donation'] = $this->home_model->get_latest_donations();
    $data['category'] = $this->home_model->get_category();
    $data['dvd_category'] = $this->home_model->get_dvd_category();
    $data['alternative_category'] = $this->home_model->get_alternative_category();
    $data['gallery']=$this->home_model->get_gallery();
    $data['idea']=$this->home_model->get_idea();
    $data['advertise']=$this->home_model->get_advertise();
    $data['header_menu']=$this->home_model->dynamic_menu(0);
    $data['footer_menu']=$this->home_model->dynamic_menu_footer(0);
    $data['right_menu']=$this->home_model->dynamic_menu_right(0);
    if($match=='' || $match=='none') {  $match_seo='Search'; } else { $match_seo=$match; }
    $meta = $this->home_model->select_meta_setting();
    $this->home_model->select_text();
    $this->template->write('meta_title',$match_seo.'-'. $meta['title'], TRUE);
    $this->template->write('meta_description', $meta['meta_description'], TRUE);
    $this->template->write('meta_keyword', $meta['meta_keyword'], TRUE);
    $this->template->write_view('header', 'header', $data, TRUE);
    $this->template->write_view('search', 'search', $data, TRUE);
    $this->template->write_view('main_content', 'search_project_list', $data, TRUE);
    $this->template->write_view('footer', 'footer',$data, TRUE);
    $this->template->render();
}
 
function search_ajax($n = '',$match='none')
{
    $limit = 9;
    $data['offset'] = $n;
    $data['limit'] = $limit;
    $data['site_setting'] = $this->home_model->select_site_setting();
    $data['total_rows'] = $this->home_model->search_project_count($match);
    $data['per_page'] = $limit;
    $data['result'] = $this->home_model->search_project($n, $limit,$match);
    $this->load->view('search_project_list_ajax', $data);
}
 
function search_autocomplete($text='')
{
    $titles = $this->home_model->auto_comp_text($text);
    if($titles)
    {
        $str = '<ul id="srhdiv">';
        foreach($titles as $title)
        {              
            $str .= '<li onclick="selecttext(this);">'.$title['project_title'].'</li>';
        }
        $str .= '</ul>';
        echo $str;
        die();
    }
}
et les fonctions du model Home_model.php:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
function search_project_count($match)
{
	if($match!='none')
	{
		$matchf = explode("'",$match);
		$match = $matchf[0];
 
		$query="select * from project p, user u where p.user_id=u.user_id and p.user_id!='' and p.user_id<>0 and p.active=1 and (p.end_date>='".date('Y-m-d H:i:s')."' or p.unlimited_days='1') and p.status not in (2,3,5) and (p.project_title like '%".$match."%' or p.description like '%".$match."%') order by project_id desc";
	}
	else
	{
		$query="select * from project p, user u where p.user_id=u.user_id and p.user_id!='' and p.user_id<>0 and p.active=1 and (p.end_date>='".date('Y-m-d H:i:s')."' or p.unlimited_days='1') and p.status not in (2,3,5) order by project_id desc";
	}
	$s_result=$this->db->query($query);
	return $s_result->num_rows();
}
 
function search_project($offset, $limit,$match)
{
	if($match!='none')
	{
	  $matchf = explode("'",$match);
	$match = $matchf[0];
 
	  $query2="select p.*,u.user_name,u.image as uimg,u.country from project p, user u where p.user_id=u.user_id and p.user_id!='' and p.user_id<>0  and p.active=1 and p.end_date>='".date('Y-m-d H:i:s')."' and p.status not in (2,3,5) and  (p.project_title like '%".$match."%' or p.description like '%".$match."%') order by project_id desc LIMIT ".$limit." OFFSET ".$offset." ";
	}
	else
	{
	   $query2="select p.*,u.user_name,u.image as uimg,u.country from project p, user u where p.user_id=u.user_id and p.user_id!='' and p.user_id<>0 and p.active=1 and p.end_date>='".date('Y-m-d H:i:s')."' and p.status not in (2,3,5) order by project_id desc LIMIT ".$limit." OFFSET ".$offset." ";
	}
	$s_result2=$this->db->query($query2);
	if($s_result2->num_rows()>0)
	{
		return $s_result2->result();
	}
	return 0;
}
 
function auto_comp_text($text)
{
	 $query = "
select * from project left join user on project.user_id=user.user_id  where project.active=1 and  (project.project_title like '%".$text."%' or user.user_name like '%".$text."%' or user.last_name like '%".$text."%' or project.project_summary like '%".$text."%') order by project.project_title asc limit 10";
	$result = $this->db->query($query);
	if($result->num_rows()>0)
	{
		return $result->result_array();
	}
	return 0;
}

Voici ci-dessous la page du site search_project_list.php qui affiche les résultats de la recherche à la ligne 52. Cette page est géré depuis le controler Home.php à la ligne 65. C'est justement là qu'il ne trouve pas les produits incluant le mot clé tapé dans le champs recherche.
Code javascript : Sélectionner tout - Visualiser dans une fenêtre à part
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
<script type="text/javascript">
function ajaxpage(n){
    var xmlHttp;
    try{
        xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari
    }
    catch (e){
        try{
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
        }
        catch (e){
            try{
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e){
                alert("<?php echo NO_AJAX;?>");
                return false;
            }
        }
    }
    xmlHttp.onreadystatechange=function(){
        if(xmlHttp.readyState==4){
            setTimeout(function(){
               document.getElementById('ajaxdiv').innerHTML=xmlHttp.responseText;
               document.id('ajaxdiv').tween('opacity', 1);
           },500);
       }
   }
    document.id('ajaxdiv').tween('opacity', 0);
    xmlHttp.open("GET","<?php echo site_url('home/search_ajax');?>/"+n+"/"+'<?php echo urlencode($match); ?>'+"/"+<?php echo time(); ?>,true);
    xmlHttp.send(null);
}
</script>
    <div class="section_top">
        <div class="main">
                <div class="txt_heading" style="padding:40px 0px;">
                    <h1><?php echo SHARE_SEARCH;?></h1>
                </div>
                <div class="card_section">
                <?php
                    if($match!="none"){
                        echo '<h2 class="project_title">'.RESULT_FOUND_FOR . ' "'.$match.'"</h2>';
                    }
                ?>
                <link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>js2/skin.css" />
                    <div class="card_section_left">
                        <div class="card_section_left_t">
                            <?php
                                    if($result)
                                    { ?>
                                        <div class="project_title"><?php echo SELECTION;?></div>
                                        <?php
                                            foreach($result as $rs)
                                            {
                                                $data['site_setting'] = $site_setting;
                                                $data['rs'] = $rs;
                                                $this->load->view('common_card',$data);
                                            }
                                    }
                                ?>
 
 
 
                </div>

Pouvez vous m'aider à trouver le bug ? merci beaucoup