Exemplo n.º 1
0
 function make_first_search()
 {
     global $msg, $charset, $lang, $dbh;
     global $title_query, $all_query, $author_query, $ex_query, $typdoc_query, $statut_query, $etat, $docnum_query;
     global $categ_query, $thesaurus_auto_postage_search, $auto_postage_query;
     global $nb_per_page_a_search;
     global $class_path;
     global $pmb_default_operator;
     global $acces_j;
     global $thesaurus_concepts_active, $concept_query;
     global $dbh;
     if ($nb_per_page_a_search) {
         $this->nb_per_page = $nb_per_page_a_search;
     } else {
         $this->nb_per_page = 3;
     }
     $author_per_page = 10;
     $restrict = '';
     $queries = array();
     if ($typdoc_query) {
         $restrict = "and typdoc='" . $typdoc_query . "' ";
     }
     if ($statut_query) {
         $restrict .= "and statut='" . $statut_query . "' ";
     }
     //traitons les cas particuliers...
     if ($author_query && !$all_query && !$title_query && !$categ_query && !$concept_query) {
         // Recherche sur l'auteur uniquement :
         $aq = new analyse_query(stripslashes($author_query), 0, 0, 1, 1);
         if (!$aq->error) {
             if ($typdoc_query || $statut_query || $acces_j) {
                 $restrict = "and responsability_author=author_id and responsability_notice=notice_id " . $restrict . " ";
                 $members = $aq->get_query_members("authors", "concat(author_name,', ',author_rejete)", "index_author", "author_id");
                 $requete_count = "select count(distinct author_id) from authors, responsability, notices ";
                 $requete_count .= $acces_j;
                 $requete_count .= "where " . $members["where"] . " ";
                 $requete_count .= $restrict;
                 $requete = "select author_id," . $members["select"] . " as pert from authors, responsability, notices ";
                 $requete .= $acces_j;
                 $requete .= "where " . $members["where"] . " ";
                 $requete .= $restrict . " group by author_id order by pert desc,author_name, author_rejete,author_numero , author_subdivision limit " . $this->page * $author_per_page . "," . $author_per_page;
             } else {
                 $requete_count = $aq->get_query_count("authors", "concat(author_name,', ',author_rejete)", "index_author", "author_id");
                 $t_query = $aq->get_query_members("authors", "concat(author_name,', ',author_rejete)", "index_author", "author_id");
                 $requete = "select author_id," . $t_query["select"] . " as pert from authors where " . $t_query["where"] . " group by author_id order by pert desc,author_name, author_rejete, author_numero , author_subdivision limit " . $this->page * $author_per_page . "," . $author_per_page;
             }
             $this->nbresults = @pmb_mysql_result(@pmb_mysql_query($requete_count), 0, 0);
             $this->t_query = @pmb_mysql_query($requete, $dbh);
             $this->nbepage = ceil($this->nbresults / $author_per_page);
             return AUT_LIST;
         }
     } else {
         //sinon, on liste des notices, c'est assez simple...
         $no_results = false;
         //tous les champs
         if ($all_query) {
             $searcher = new searcher_records_all_fields(stripslashes($all_query));
             $queries[] = $searcher->get_full_query() . " ";
         }
         //pour la suite, avant de déclencher les recherches, on vérifie si la recherche est différente de celle tous les champs (on s'économise quelques requetes qui ne serviront à rien)
         //les concepts
         if ($thesaurus_concepts_active && $concept_query && $concept_query != $all_query) {
             $concept_searcher = new searcher_records_concepts(stripslashes($concept_query));
             if ($concept_searcher->get_nb_results()) {
                 $queries[] = $concept_searcher->get_full_query() . " ";
             } else {
                 $no_results = true;
             }
         }
         //le titre
         if ($title_query && $title_query != $all_query) {
             $title_searcher = new searcher_records_title(stripslashes($title_query));
             if ($title_searcher->get_nb_results()) {
                 //hack, un petit espace à la fin de la requete nous évite une régression avec le tri...
                 $queries[] = $title_searcher->get_full_query() . " ";
             } else {
                 $no_results = true;
             }
             $this->text_query = $title_sql_query;
         }
         //auteur
         if ($author_query && $author_query != $all_query) {
             $author_searcher = new searcher_records_authors(stripslashes($author_query));
             if ($author_searcher->get_nb_results()) {
                 $queries[] = $author_searcher->get_full_query() . " ";
             } else {
                 $no_results = true;
             }
         }
         //catégorie
         if ($categ_query && $categ_query != $all_query) {
             if ($thesaurus_auto_postage_search && $auto_postage_query) {
                 $aq_auth = new analyse_query(stripslashes($categ_query), 0, 0, 0, 0);
                 if (!$aq_auth->error) {
                     $members_auth = $aq_auth->get_query_members("categories", "path_word_categ", "index_path_word_categ", "num_noeud");
                     $requete_count = "select count(distinct notice_id) from notices ";
                     $requete_count .= $acces_j;
                     $requete_count .= ", categories, noeuds, notices_categories ";
                     $requete_count .= "where (" . $members_auth["where"] . ")  ";
                     $requete_count .= "and id_noeud= categories.num_noeud and notices_categories.num_noeud=categories.num_noeud and notcateg_notice = notice_id ";
                     $requete_count .= $restrict;
                     $requete = "select notice_id, " . $members_auth["select"] . " as pert from notices ";
                     $requete .= $acces_j;
                     $requete .= ", categories, noeuds, notices_categories ";
                     $requete .= "where (" . $members_auth["where"] . ") ";
                     $requete .= "and id_noeud= categories.num_noeud and notices_categories.num_noeud=categories.num_noeud and notcateg_notice = notice_id ";
                     $requete .= $restrict . " group by notice_id ";
                     $requete .= "order by pert desc ";
                     $nbresults = @pmb_mysql_result(@pmb_mysql_query($requete_count), 0, 0);
                     if ($nbresults) {
                         $queries[] = $requete;
                     } else {
                         $no_results = true;
                     }
                 }
             } else {
                 $categ_searcher = new searcher_records_categories(stripslashes($categ_query));
                 if ($categ_searcher->get_nb_results()) {
                     $queries[] = $categ_searcher->get_full_query() . " ";
                 } else {
                     $no_results = true;
                 }
             }
         }
         //on fait un et donc si un élément ne renvoi rien ,on s'embete pas avec les jointures...
         if ($no_results) {
             $this->nbresults = 0;
             $this->text_query = "select notice_id from notices where notice_id = 0 ";
             //l'espace à la fin est important
         } else {
             //TODO le tri sur la pertinance desc, titre devrait être automatique...
             $from = "";
             $select_pert = "";
             for ($i = 0; $i < count($queries); $i++) {
                 if ($i == 0) {
                     $from = "(" . $queries[$i] . ") as t" . $i;
                     $select_pert = "t" . $i . ".pert";
                 } else {
                     $from .= " inner join (" . $queries[$i] . ") as t" . $i . " on t" . $i . ".notice_id = t" . ($i - 1) . ".notice_id";
                     $select_pert .= " + t" . $i . ".pert";
                 }
             }
             $this->text_query = "select t0.notice_id, (" . $select_pert . ") as pert from " . $from . " join notices on t0.notice_id = notices.notice_id group by t0.notice_id  order by pert desc, notices.index_sew ";
             $result = pmb_mysql_query($this->text_query, $dbh);
             $this->nbresults = pmb_mysql_num_rows($result);
         }
         $this->nbepage = ceil($this->nbresults / $this->nb_per_page);
         return NOTICE_LIST;
     }
 }
Exemplo n.º 2
0
 function make_first_search()
 {
     global $msg, $charset, $lang, $dbh;
     global $title_query, $all_query, $author_query, $ex_query, $typdoc_query, $statut_query, $etat, $docnum_query;
     global $categ_query, $thesaurus_auto_postage_search, $auto_postage_query;
     global $nb_per_page_a_search;
     global $class_path;
     global $pmb_default_operator;
     global $acces_j;
     global $thesaurus_concepts_active, $concept_query;
     global $dbh;
     if ($nb_per_page_a_search) {
         $this->nb_per_page = $nb_per_page_a_search;
     } else {
         $this->nb_per_page = 3;
     }
     $author_per_page = 10;
     $restrict = '';
     if ($typdoc_query) {
         $restrict = "and typdoc='" . $typdoc_query . "' ";
     }
     if ($statut_query) {
         $restrict .= "and statut='" . $statut_query . "' ";
     }
     //traitons les cas particuliers...
     if ($author_query && !$all_query && !$title_query && !$categ_query && !$concept_query) {
         // Recherche sur l'auteur uniquement :
         $aq = new analyse_query(stripslashes($author_query), 0, 0, 1, 1);
         if (!$aq->error) {
             if ($typdoc_query || $statut_query || $acces_j) {
                 $restrict = "and responsability_author=author_id and responsability_notice=notice_id " . $restrict . " ";
                 $members = $aq->get_query_members("authors", "concat(author_name,', ',author_rejete)", "index_author", "author_id");
                 $requete_count = "select count(distinct author_id) from authors, responsability, notices ";
                 $requete_count .= $acces_j;
                 $requete_count .= "where " . $members["where"] . " ";
                 $requete_count .= $restrict;
                 $requete = "select author_id," . $members["select"] . " as pert from authors, responsability, notices ";
                 $requete .= $acces_j;
                 $requete .= "where " . $members["where"] . " ";
                 $requete .= $restrict . " group by author_id order by pert desc,author_name, author_rejete,author_numero , author_subdivision limit " . $this->page * $author_per_page . "," . $author_per_page;
             } else {
                 $requete_count = $aq->get_query_count("authors", "concat(author_name,', ',author_rejete)", "index_author", "author_id");
                 $t_query = $aq->get_query_members("authors", "concat(author_name,', ',author_rejete)", "index_author", "author_id");
                 $requete = "select author_id," . $t_query["select"] . " as pert from authors where " . $t_query["where"] . " group by author_id order by pert desc,author_name, author_rejete, author_numero , author_subdivision limit " . $this->page * $author_per_page . "," . $author_per_page;
             }
             $this->nbresults = @pmb_mysql_result(@pmb_mysql_query($requete_count), 0, 0);
             $this->t_query = @pmb_mysql_query($requete, $dbh);
             $this->nbepage = ceil($this->nbresults / $author_per_page);
             return AUT_LIST;
         }
     } else {
         //sinon, on liste des notices, c'est assez simple...
         $no_results = false;
         //tous les champs
         if ($all_query) {
             //TODO Searcher all_fields, pas le temps de le faire là...
             // Recherche sur tous les champs (index global) uniquement :
             $aq = new analyse_query(stripslashes($all_query), 0, 0, 1, 1);
             $aq2 = new analyse_query(stripslashes($all_query));
             if (!$aq->error) {
                 $aq1 = new analyse_query(stripslashes($all_query), 0, 0, 1, 1);
                 $members1 = $aq1->get_query_members("notices", "index_wew", "index_sew", "notice_id", $restrict);
                 global $pmb_title_ponderation;
                 $pert1 = "+" . $members1["select"] . "*" . $pmb_title_ponderation;
                 $members = $aq->get_query_members("notices_global_index", "infos_global", "index_infos_global", "num_notice");
                 $members2 = $aq2->get_query_members("notices_global_index", "infos_global", "index_infos_global", "num_notice");
                 if ($members2["where"] != "()" && $pmb_default_operator) {
                     $where_term = "(" . $members["where"] . " or " . $members2["where"] . ")";
                 } else {
                     $where_term = $members["where"];
                 }
                 if ($docnum_query && $all_query != '*') {
                     //Si on a activé la recherche dans les docs num
                     //On traite les notices
                     $members_num_noti = $aq2->get_query_members("explnum", "explnum_index_wew", "explnum_index_sew", "explnum_notice", "", 0, 0, true);
                     $members_num_bull = $aq2->get_query_members("explnum", "explnum_index_wew", "explnum_index_sew", "explnum_bulletin", "", 0, 0, true);
                     $join = "(\n\t\t\t\t\t\tselect tc.notice_id, sum(tc.pert) as pert, tc.typdoc from (\n\t\t\t\t\t\t(\n\t\t\t\t\t\tselect notice_id, " . $members["select"] . "+" . $members1["select"] . " as pert,typdoc\n\t\t\t\t\t\tfrom notices join notices_global_index on num_notice=notice_id {$acces_j}\n\t\t\t\t\t\twhere " . $members["where"] . " {$restrict}\n\t\t\t\t\t\t)\n\t\t\t\t\t\tunion\n\t\t\t\t\t\t(\n\t\t\t\t\t\tselect notice_id, " . $members_num_noti["select"] . " as pert,typdoc\n\t\t\t\t\t\tfrom notices join explnum on explnum_notice=notice_id {$acces_j}\n\t\t\t\t\t\twhere  " . $members_num_noti["where"] . " {$restrict}\n\t\t\t\t\t\t)\n\t\t\t\t\t\tunion\n\t\t\t\t\t\t(\n\t\t\t\t\t\tselect if(num_notice,num_notice,bulletin_notice) as notice_id, " . $members_num_bull["select"] . " as pert,typdoc\n\t\t\t\t\t\tfrom explnum join bulletins on explnum_bulletin=bulletin_id ,notices {$acces_j}\n\t\t\t\t\t\twhere bulletin_notice=notice_id and " . $members_num_bull["where"] . " {$restrict}\n\t\t\t\t\t\t)\n\t\t\t\t\t\t)as tc group by notice_id\n\t\t\t\t\t\t)";
                     $requete_count = "select count(distinct notice_id) from ({$join}) as union_table";
                     $requete = "select uni.notice_id, sum(pert) as pert  from ({$join}) as uni join notices n on n.notice_id=uni.notice_id group by uni.notice_id order by pert desc, index_serie, tnvol, index_sew ";
                 } else {
                     $restrict .= " and num_notice = notice_id ";
                     $requete_count = "select count(1) from notices ";
                     $requete_count .= $acces_j;
                     $requete_count .= ", notices_global_index ";
                     $requete_count .= "where " . $where_term . " ";
                     $requete_count .= $restrict;
                     $requete = "select notice_id," . $members["select"] . "{$pert1} as pert from notices ";
                     $requete .= $acces_j;
                     $requete .= ", notices_global_index ";
                     $requete .= "where {$where_term} ";
                     $requete .= $restrict . " order by pert desc, index_serie, tnvol, index_sew ";
                 }
                 $queries[] = $requete;
             }
         }
         //pour la suite, avant de déclencher les recherches, on vérifie si la recherche est différente de celle tous les champs (on s'économise quelques requetes qui ne serviront à rien)
         //les concepts
         if ($thesaurus_concepts_active && $concept_query && $concept_query != $all_query) {
             $concept_searcher = new searcher_records_concepts(stripslashes($concept_query));
             if ($concept_searcher->get_nb_results()) {
                 $queries[] = $concept_searcher->get_full_query() . " ";
             } else {
                 $no_results = true;
             }
         }
         //le titre
         if ($title_query && $title_query != $all_query) {
             $title_searcher = new searcher_records_title(stripslashes($title_query));
             if ($title_searcher->get_nb_results()) {
                 //hack, un petit espace à la fin de la requete nous évite une régression avec le tri...
                 $queries[] = $title_searcher->get_full_query() . " ";
             } else {
                 $no_results = true;
             }
             $this->text_query = $title_sql_query;
         }
         //auteur
         if ($author_query && $author_query != $all_query) {
             $author_searcher = new searcher_records_authors(stripslashes($author_query));
             if ($author_searcher->get_nb_results()) {
                 $queries[] = $author_searcher->get_full_query() . " ";
             } else {
                 $no_results = true;
             }
         }
         //catégorie
         if ($categ_query && $categ_query != $all_query) {
             if ($thesaurus_auto_postage_search && $auto_postage_query) {
                 $aq_auth = new analyse_query(stripslashes($categ_query), 0, 0, 0, 0);
                 if (!$aq_auth->error) {
                     $members_auth = $aq_auth->get_query_members("categories", "path_word_categ", "index_path_word_categ", "num_noeud");
                     $requete_count = "select count(distinct notice_id) from notices ";
                     $requete_count .= $acces_j;
                     $requete_count .= ", categories, noeuds, notices_categories ";
                     $requete_count .= "where (" . $members_auth["where"] . ")  ";
                     $requete_count .= "and id_noeud= categories.num_noeud and notices_categories.num_noeud=categories.num_noeud and notcateg_notice = notice_id ";
                     $requete_count .= $restrict;
                     $requete = "select notice_id, " . $members_auth["select"] . " as pert from notices ";
                     $requete .= $acces_j;
                     $requete .= ", categories, noeuds, notices_categories ";
                     $requete .= "where (" . $members_auth["where"] . ") ";
                     $requete .= "and id_noeud= categories.num_noeud and notices_categories.num_noeud=categories.num_noeud and notcateg_notice = notice_id ";
                     $requete .= $restrict . " group by notice_id ";
                     $requete .= "order by pert desc ";
                     $nbresults = @pmb_mysql_result(@pmb_mysql_query($requete_count), 0, 0);
                     if ($nbresults) {
                         $queries[] = $requete;
                     } else {
                         $no_results = true;
                     }
                 }
             } else {
                 $categ_searcher = new searcher_records_categories(stripslashes($categ_query));
                 if ($categ_searcher->get_nb_results()) {
                     $queries[] = $categ_searcher->get_full_query() . " ";
                 } else {
                     $no_results = true;
                 }
             }
         }
         //on fait un et donc si un élément ne renvoi rien ,on s'embete pas avec les jointures...
         if ($no_results) {
             $this->nbresults = 0;
             $this->text_query = "select notice_id from notices where notice_id = 0";
         } else {
             //TODO le tri sur la pertinance desc, titre devrait être automatique...
             $from = "";
             $select_pert = "";
             for ($i = 0; $i < count($queries); $i++) {
                 if ($i == 0) {
                     $from = "(" . $queries[$i] . ") as t" . $i;
                     $select_pert = "t" . $i . ".pert";
                 } else {
                     $from .= " inner join (" . $queries[$i] . ") as t" . $i . " on t" . $i . ".notice_id = t" . ($i - 1) . ".notice_id";
                     $select_pert .= " + t" . $i . ".pert";
                 }
             }
             $this->text_query = "select t0.notice_id, (" . $select_pert . ") as pert from " . $from . " join notices on t0.notice_id = notices.notice_id group by t0.notice_id  order by pert desc, notices.index_sew ";
             $result = pmb_mysql_query($this->text_query, $dbh);
             $this->nbresults = pmb_mysql_num_rows($result);
         }
         $this->nbepage = ceil($this->nbresults / $this->nb_per_page);
         return NOTICE_LIST;
     }
 }