";
// requête de recherche sur les titres
print pmb_bidi("
$count ".$msg['docnum_found']." '".htmlentities(stripslashes($user_query),ENT_QUOTES,$charset)."'");
//calcul restriction
if ($opac_search_other_function) {
require_once($include_path."/".$opac_search_other_function);
print pmb_bidi(" ".search_other_function_human_query($_SESSION["last_query"]));
}
print "";
print activation_surlignage();
print "
";
$restrict_opac_view='';
if($_SESSION["opac_view"]){
$restrict_opac_view=" notice_id in (select opac_view_num_notice from opac_view_notices_".$_SESSION["opac_view"].") ";
}
$restrict_typdoc = '';
if ($typdoc) {
$restrict_typdoc = "typdoc='".addslashes($typdoc)."'";
}
$aq=new analyse_query(stripslashes($user_query),0,0,1,0,$opac_stemming_active);
$members=$aq->get_query_members("explnum","explnum_index_wew","explnum_index_sew","explnum_id",'',0,0,true);
if($user_query=='*') {
$new_clause = '1';
$pert = "100 as pert";
} else {
$new_clause = $members["where"];
}
if (!isset($pert)) {
$pert=$members["select"]." as pert";
}
//droits d'acces emprunteur/notice
$acces_j='';
if ($gestion_acces_active==1 && $gestion_acces_empr_notice==1) {
require_once("$class_path/acces.class.php");
$ac= new acces();
$dom_2= $ac->setDomain(2);
$acces_j= $dom_2->getJoin($_SESSION['id_empr_session'],16,'notice_id');
}
if ($acces_j) {
$q_restrict = "select notice_id from notices ".$acces_j." where ".(($restrict_typdoc)?$restrict_typdoc:'1 ');
$q_restrict.= (($restrict_opac_view)?'and '.$restrict_opac_view:'');
//Pour rester compatible avec l'ancienne version
$statut_j='';
} else {
$q_restrict = "select notice_id from notices where ".(($restrict_typdoc)?$restrict_typdoc:'1 ');
$q_restrict.= (($restrict_opac_view)?'and '.$restrict_opac_view:'');
$q_restrict.= "and statut in (select id_notice_statut from notice_statut where (((notice_visible_opac=1 and notice_visible_opac_abon=0) and (explnum_visible_opac=1 and explnum_visible_opac_abon=0))".($_SESSION["user_code"]?" or ((notice_visible_opac_abon=1 and notice_visible_opac=1) and (explnum_visible_opac=1 and explnum_visible_opac_abon=1)) or ((notice_visible_opac_abon=0 and notice_visible_opac=1) and (explnum_visible_opac=1 and explnum_visible_opac_abon=1))":"")."))";
//Pour rester compatible avec l'ancienne version
$statut_j=',notice_statut';
}
if ($opac_search_other_function) {
$add_notice = search_other_function_clause();
if ($add_notice) {
$q_restrict.= ' and notice_id in ('.$add_notice.')';
//Pour rester compatible avec l'ancienne version
$old_clause.= ' and notice_id in ('.$add_notice.')';
$old_clause_bull.= ' and notice_id in ('.$add_notice.')';
$old_clause_bull_num_notice.= ' and notice_id in ('.$add_notice.')';
}
}
//creation table tempo search_result_notices_ contenant les ids des notices visibles pour le lecteur courant.
$tx = session_id();
$table_tempo_notices = "search_result_notices_".$tx;
mysql_query("drop table if exists $table_tempo_notices", $dbh);
$q_table_tempo_notices = "create temporary table ".$table_tempo_notices." engine=memory ".$q_restrict;
$res_table_tempo_notices = mysql_query($q_table_tempo_notices,$dbh);
//ajout index
$q_index_tempo_notices = "alter table ".$table_tempo_notices." add index i_id(notice_id)";
mysql_query($q_index_tempo,$dbh);
//creation table tempo search_result_explnum_ contenant les ids des documents numériques et les ids de notices pour monographies/articles.
$table_tempo_explnum = "search_result_explnum_".$tx;
mysql_query("drop table if exists $table_tempo_explnum", $dbh);
$q_table_tempo_explnum = "create temporary table $table_tempo_explnum engine=memory select explnum_id, explnum_notice as notice_id, explnum_mimetype, 1.00 as pert from explnum join $table_tempo_notices on explnum_notice=notice_id where explnum_notice!=0";
$res_table_tempo_explnum = mysql_query($q_table_tempo_explnum,$dbh);
//ajout index
$q_index_tempo_explnum = "alter table ".$table_tempo_explnum." add primary key i_id(explnum_id)";
mysql_query($q_index_tempo_explnum,$dbh);
//ajout dans la table tempo search_result_explnum_ des ids des documents numériques et des ids de notices pour les notices de periodique des bulletins.
$q_in_tempo_explnum = "insert ignore into $table_tempo_explnum select explnum_id, bulletin_notice as notice_id, explnum_mimetype, 1.00 as pert from explnum join bulletins on explnum_bulletin=bulletin_id where num_notice=0 and bulletin_notice in (select notice_id from $table_tempo_notices);";
$res_in_tempo_explnum = mysql_query($q_in_tempo_explnum,$dbh);
//ajout dans la table tempo search_result_explnum_ des ids des documents numériques et des ids de notices pour les notices de bulletins.
$q_in_tempo_explnum = "insert ignore into $table_tempo_explnum select explnum_id, num_notice as notice_id, explnum_mimetype, 1.00 as pert from explnum join bulletins on explnum_bulletin=bulletin_id where num_notice in (select notice_id from $table_tempo_notices);";
$res_in_tempo_explnum = mysql_query($q_in_tempo_explnum,$dbh);
$search_terms = $aq->get_positive_terms($aq->tree);
//On enlève le dernier terme car il s'agit de la recherche booléenne complète
unset($search_terms[count($search_terms)-1]);
if(!isset($tri)) {
$tri="order by pert desc, index_serie, tnvol, index_sew";
}
$nb_result_docnum = 0;
if($new_clause) {
$s_explnum = 0;
$nb_explnum = 0;
//suppression des recherches obsoletes en cache
$q_cache_del= "delete from search_cache where delete_on_date < NOW()";
mysql_query($q_cache_del,$dbh);
//recuperation signature recherche
$str_to_hash = "type_search=explnum";
$str_to_hash.= $new_clause;
$sign = md5($str_to_hash);
//la recherche brute est elle en cache ?
$q_cache_read = "select value from search_cache where object_id='".addslashes($sign)."'";
$r_cache_read = mysql_query($q_cache_read, $dbh);
//si oui, recuperation
if (mysql_num_rows($r_cache_read)) {
$o = mysql_fetch_object($r_cache_read);
$t_explnum = unserialize($o->value);
if(count($t_explnum)) {
$s_explnum = implode(',',array_keys($t_explnum));
}
//si non, re-calcul et mise en cache
} else {
// Recherche des documents numeriques correspondants a la recherche.
$q_explnum = "select distinct(explnum_id), $pert from explnum where $new_clause";
$r_explnum = mysql_query($q_explnum, $dbh);
$nb_explnum = mysql_num_rows($r_explnum);
$t_explnum = array();
$s_explnum = '';
if ($nb_explnum) {
while ($o=mysql_fetch_object($r_explnum)) {
$t_explnum[$o->explnum_id]=$o->pert;
}
}
if(count($t_explnum)) {
$s_explnum = implode(',',array_keys($t_explnum));
}
//mise en cache des resultats de la recherche
$str_to_cache = serialize($t_explnum);
$q_cache_insert = "insert into search_cache set object_id ='".addslashes($sign)."', value ='".addslashes($str_to_cache)."', delete_on_date = now() + interval ".$opac_search_cache_duration." second";
mysql_query($q_cache_insert,$dbh);
}
if (count($t_explnum)) {
//restriction des resultats
$q_result_docnum = "delete from $table_tempo_explnum where explnum_id not in (".$s_explnum.") " ;
$r_result_docnum = mysql_query($q_result_docnum,$dbh);
//Ajout pertinence dans $table_tempo_explnum
$t_pert = array();
foreach($t_explnum as $t_id=>$t_pert) {
$q_pert = "update $table_tempo_explnum set pert=$t_pert where explnum_id=$t_id";
$r_pert = mysql_query($q_pert,$dbh);
}
}
}
$requete = "select explnum_id, uni.notice_id,explnum_mimetype, pert from $table_tempo_explnum as uni join notices n on uni.notice_id=n.notice_id" ;
$nbexplnum = 0;
if($opac_photo_filtre_mimetype){
$requete_nbexplnum = "select count(*) from $table_tempo_explnum as uni where explnum_mimetype in ($opac_photo_filtre_mimetype)";
$res_nbexplnum = mysql_query($requete_nbexplnum);
if(mysql_num_rows($res_nbexplnum)) {
$nbexplnum = mysql_result($res_nbexplnum,0,0);
}
}
//gestion du tri
if (isset($_GET["sort"])) {
$_SESSION["last_sortnotices"]=$_GET["sort"];
}
if ($count>$opac_nb_max_tri) {
$_SESSION["last_sortnotices"]="";
}
if ($_SESSION["last_sortnotices"]!="") {
$sort=new sort('notices','session');
$requete=$sort->appliquer_tri($_SESSION["last_sortnotices"],$requete,"notice_id",$debut,$opac_search_results_per_page);
} else {
$requete .= " ".$tri;
$requete .= " ".$limiter;
}
//fin gestion du tri
$found = mysql_query($requete, $dbh);
print " \n
";
if ($opac_notices_depliable) print $begin_result_liste;
//gestion du tri
if ($count<=$opac_nb_max_tri) {
$pos=strpos($_SERVER['REQUEST_URI'],"?");
$pos1=strpos($_SERVER['REQUEST_URI'],"get");
if ($pos1==0) $pos1=strlen($_SERVER['REQUEST_URI']);
else $pos1=$pos1-3;
$para=urlencode(substr($_SERVER['REQUEST_URI'],$pos+1,$pos1-$pos+1));
$para1=substr($_SERVER['REQUEST_URI'],$pos+1,$pos1-$pos+1);
$affich_tris_result_liste=str_replace("!!page_en_cours!!",$para,$affich_tris_result_liste);
$affich_tris_result_liste=str_replace("!!page_en_cours1!!",$para1,$affich_tris_result_liste);
print $affich_tris_result_liste;
if ($_SESSION["last_sortnotices"]!="") {
print " ".$msg['tri_par']." ".$sort->descriptionTriParId($_SESSION["last_sortnotices"])." ";
}
} else print " ";
//fin gestion du tri
print $add_cart_link;
if($opac_visionneuse_allow && $nbexplnum){
print " ".$link_to_visionneuse;
print $sendToVisionneuseByPost;
}
//affinage
//enregistrement de l'endroit actuel dans la session
if ($_SESSION["last_query"]) { $n=$_SESSION["last_query"]; } else { $n=$_SESSION["nb_queries"]; }
$_SESSION["notice_view".$n]["search_mod"]="docnum";
$_SESSION["notice_view".$n]["search_page"]=$page;
//affichage
print "
".$msg["affiner_recherche"]."";
//fin affinage
//Etendre
if ($opac_allow_external_search) print "
".$msg["connecteurs_external_search_sources"]."";
//fin etendre
if ($opac_show_suggest) {
$bt_sugg = "
".$msg[empr_bt_make_sugg]."";
print $bt_sugg;
}
require_once("$class_path/explnum_affichage.class.php");
// Ancienne version
$list_explnum = array();
while(($mesNotices = mysql_fetch_array($found))){
$list_explnum[] = $mesNotices["explnum_id"];
}
$terms = unserialize(stripslashes($search_terms));
$explnum = new explnum_affichage($list_explnum,DOCNUM_NOTI,$terms);
$explnum->show_explnum();
print "
\n
";
?>