Problème de moteur de recherche interne
Posté : 28 avr. 2013, 18:55
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 affiche un résultat de la recherche "aucun résultat trouvé".
Voici le controller:
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 affiche un résultat de la recherche "aucun résultat trouvé".
Voici le controller:
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);
/* if($_SESSION['lang_code'] == 'fr') {
$this->template->write_view('sidebar', 'category_french', $data, TRUE);
} else {
$this->template->write_view('sidebar', 'category', $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:
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 le code du champs du moteur de recherche sur la page du site:
<script type="text/javascript" language="javascript">
function remove_text()
{
if(document.getElementById('searchprj').value == "<?php echo SEARCH;?>" || document.getElementById('searchprj').value == "<?php echo PLEASE_ENTER_SEARCH_KEYWORD;?>")
{
document.getElementById('searchprj').value = "";
}
}
function set_text()
{
if(document.getElementById('searchprj').value == "")
{
document.getElementById('searchprj').value = document.getElementById('searchval').value;
}
}
function form_validate()
{
if(document.getElementById('searchprj').value == "" || document.getElementById('searchprj').value == "<?php echo SEARCH;?>" || document.getElementById('searchprj').value == "<?php echo PLEASE_ENTER_SEARCH_KEYWORD; ?>")
{
document.getElementById('searchprj').value = "<?php echo PLEASE_ENTER_SEARCH_KEYWORD; ?>";
document.getElementById('searchval').value = "<?php echo PLEASE_ENTER_SEARCH_KEYWORD; ?>";
return false;
}else{
document.frmsearch.submit();
}
}
</script>
<div class="search" align="right">
<?php
$attributes = array('name'=>'frmsearch', 'onsubmit'=>'return form_validate()','autocomplete'=>'off');
echo form_open('home/search',$attributes);
?>
<div class="search_txtbox">
<input type="text" name="searchprj" id="searchprj" class="searchtext" value="<?php echo PLEASE_ENTER_SEARCH_KEYWORD; ?>" onfocus="remove_text();" onblur="set_text()" onkeyup="autotext();" />
</div>
<input type="button" class="search_btn" value="" onclick="form_validate();" />
<input type="hidden" name="searchval" id="searchval" value="<?php echo PLEASE_ENTER_SEARCH_KEYWORD; ?>" />
</form>
<div id="autoc" ></div>
</div>
Voici ci-dessous la page du site qui affiche les résultats de la recherche. C'est justement là qu'il ne trouve pas les produits incluant le mot clé tapé dans le champs recherche.
<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_alternative_projects)
{ ?>
<div class="project_title"><?php echo SELECTION;?></div>
<?php
foreach($result_alternative_projects as $rs)
{
$data['site_setting'] = $site_setting;
$data['rs'] = $rs;
$this->load->view('common_card',$data);
}
}
?>
<?php
if($result_all_project)
{ ?>
<div class="project_title"><?php echo POPULARS;?></div>
<?php
foreach($result_all_project as $rs)
{
$data['site_setting'] = $site_setting;
$data['rs'] = $rs;
$this->load->view('common_card',$data);
}
}
?>
<?php
if($result_selection)
{ ?>
<div class="project_title"><?php echo SELECTION;?></div>
<?php
foreach($result_selection as $rs)
{
$data['site_setting'] = $site_setting;
$data['rs'] = $rs;
$this->load->view('common_card',$data);
}
}
?>
<div class="clear"></div>
</div>
<div class="card_section_left_b">
<?php
if($result_popular)
{
?> <div class="project_title"><?php echo POPULARS;?></div>
<?php
foreach($result_popular as $rs)
{
$data['site_setting'] = $site_setting;
$data['rs'] = $rs;
$this->load->view('common_card',$data);
}
}
?>
<div class="clear"></div>
<?php if($result_endingsoon)
{
?>
<div class="project_title"><?php echo ENDING_SOON;?></div>
<?php
foreach($result_endingsoon as $rs)
{
$data['site_setting'] = $site_setting;
$data['rs'] = $rs;
$this->load->view('common_card',$data);
}
}
?>
<div class="clear"></div>
</div>
</div>
Pouvez vous m'aider à trouver le bug ? merci beaucoup