From 49f00ce8922c8aa8af44abc0d3252560192530ac Mon Sep 17 00:00:00 2001 From: jygaulier Date: Mon, 15 Oct 2012 20:19:10 +0200 Subject: [PATCH 1/9] avoid sql search in extension when term was not found in thesaurus btw, fix the #937 --- .../adapter/phrasea/queryParser.class.php | 167 ++++++------------ 1 file changed, 54 insertions(+), 113 deletions(-) diff --git a/lib/classes/searchEngine/adapter/phrasea/queryParser.class.php b/lib/classes/searchEngine/adapter/phrasea/queryParser.class.php index 79c5a1c62e..0c10dca535 100644 --- a/lib/classes/searchEngine/adapter/phrasea/queryParser.class.php +++ b/lib/classes/searchEngine/adapter/phrasea/queryParser.class.php @@ -110,7 +110,7 @@ class searchEngine_adapter_phrasea_queryParser public function parsequery($phq) { if ($this->debug) { - for ($i = 0; $i < mb_strlen($phq, 'UTF-8'); $i ++ ) { + for ($i = 0; $i < mb_strlen($phq, 'UTF-8'); $i++) { $c = mb_substr($phq, $i, 1, 'UTF-8'); printf("// %s : '%s' (%d octets)\n", $i, $c, strlen($c)); } @@ -347,7 +347,7 @@ class searchEngine_adapter_phrasea_queryParser public function priority_opk(&$tree, $depth = 0) { - if ( ! $tree) { + if (!$tree) { return; } @@ -367,7 +367,7 @@ class searchEngine_adapter_phrasea_queryParser public function distrib_opk(&$tree, $depth = 0) { - if ( ! $tree) { + if (!$tree) { return; } @@ -394,7 +394,7 @@ class searchEngine_adapter_phrasea_queryParser public function thesaurus2_apply(&$tree, $bid) { - if ( ! $tree) { + if (!$tree) { return; } @@ -453,7 +453,7 @@ class searchEngine_adapter_phrasea_queryParser { if ($depth == 0) $ret = $tree; - if ( ! $useThesaurus) { + if (!$useThesaurus) { return; // full-text only : inchangé } @@ -469,7 +469,7 @@ class searchEngine_adapter_phrasea_queryParser if (isset($tree["RB"]["CONTEXT"])) $copy["CONTEXT"] = $tree["CONTEXT"] = $tree["RB"]["CONTEXT"]; else - if ( ! $keepfuzzy) + if (!$keepfuzzy) $copy["CONTEXT"] = $tree["CONTEXT"] = "*"; $copy["RB"]["SREF"] = &$tree["RB"]; @@ -530,7 +530,7 @@ class searchEngine_adapter_phrasea_queryParser if ($context !== null) $tmp["RB"]["CONTEXT"] = $context; else - if ( ! $keepfuzzy) + if (!$keepfuzzy) $tmp["RB"]["CONTEXT"] = "*"; // corrige les profondeurs des 2 copies du 'simple' d'origine $tmp["LB"]["DEPTH"] += 1; @@ -557,7 +557,7 @@ class searchEngine_adapter_phrasea_queryParser if ($context !== null) $tmp["CONTEXT"] = $context; else - if ( ! $keepfuzzy) + if (!$keepfuzzy) $tmp["CONTEXT"] = "*"; // corrige la profondeur de la copie du 'simple' d'origine $tmp["RB"]["DEPTH"] += 1; @@ -577,7 +577,7 @@ class searchEngine_adapter_phrasea_queryParser if ($depth == 0) $this->proposals["BASES"]["b$bid"] = array("BID" => $bid, "NAME" => $name, "TERMS" => array()); - if ( ! $tree) { + if (!$tree) { return(0); } @@ -602,7 +602,7 @@ class searchEngine_adapter_phrasea_queryParser for ($n = $node->firstChild; $n; $n = $n->nextSibling) { if ($n->nodeName == "sy") { $lng = $n->getAttribute("lng"); - if ( ! array_key_exists($lng, $tsy)) + if (!array_key_exists($lng, $tsy)) $tsy[$lng] = array(); $zsy = array("v" => $n->getAttribute("v"), "w" => $n->getAttribute("w"), "k" => $n->getAttribute("k")); @@ -654,7 +654,7 @@ class searchEngine_adapter_phrasea_queryParser } } $n->removeAttribute("marked"); - for ($i = 0; array_key_exists($syfound . $i, $tsort) && $i < 9999; $i ++ ) + for ($i = 0; array_key_exists($syfound . $i, $tsort) && $i < 9999; $i++) ; $tsort[$syfound . $i] = $n; } @@ -727,7 +727,7 @@ class searchEngine_adapter_phrasea_queryParser $t = $w = implode(" ", $w); if (isset($tree["CONTEXT"])) { - if ( ! $tree["CONTEXT"]) { + if (!$tree["CONTEXT"]) { $x0 = "@w=\"" . $w . "\" and not(@k)"; } else { if ($tree["CONTEXT"] == "*") { @@ -749,7 +749,7 @@ class searchEngine_adapter_phrasea_queryParser $dxp = new DOMXPath($domthe); $nodes = $dxp->query($x); - if ( ! isset($tree["RB"]["SREF"]["TIDS"])) + if (!isset($tree["RB"]["SREF"]["TIDS"])) $tree["RB"]["SREF"]["TIDS"] = array(); if ($nodes->length >= 1) { if ($nodes->length == 1) { @@ -760,8 +760,8 @@ class searchEngine_adapter_phrasea_queryParser // on cherche plusieurs id's, on utilisera la syntaxe 'regexp' (l'extension repérera elle meme la syntaxe car la value finira par '$') $val = ""; foreach ($nodes as $node) { - if ( ! isset($tree["CONTEXT"])) - $ambigus ++; + if (!isset($tree["CONTEXT"])) + $ambigus++; $this->addtoTIDS($tree["RB"], $bid, $node); } } @@ -771,74 +771,15 @@ class searchEngine_adapter_phrasea_queryParser $this->proposals["BASES"]["b$bid"]["TERMS"][$path]["HTML"] = $prophtml; } else { // le mot n'est pas dans le thesaurus + $tree = null; } return($ambigus); } - /* - function dead_setTids(&$tree, &$simple, $bid, &$domthe, $searchsynonyms) - { - // if($this->debug) - print("setTids:\n\$tree=" . var_export($tree, true) . "\n"); - - $ambigus = 0; - if(is_array($w = $simple["VALUE"])) - $t = $w = implode(" ", $w); - - if (isset($tree["CONTEXT"])) { - if (!$tree["CONTEXT"]) { - $x0 = "@w=\"" . $w ."\" and not(@k)"; - } else { - if ($tree["CONTEXT"]=="*") { - $x0 = "@w=\"" . $w ."\""; - } else { - $x0 = "@w=\"" . $w ."\" and @k=\"" . $tree["CONTEXT"] . "\""; - $t .= " (" . $tree["CONTEXT"] . ")"; - } - } - } else { - $x0 = "@w=\"" . $w ."\""; - } - - $x = "/thesaurus//sy[" . $x0 ."]"; - - if($this->debug) - printf("searching thesaurus with xpath='%s'
\n", $x); - - $dxp = new DOMXPath($domthe); - $nodes = $dxp->query($x); - - if(!isset($tree["RB"]["SREF"]["TIDS"])) - $tree["RB"]["SREF"]["TIDS"] = array(); - if ($nodes->length >= 1) { - if ($nodes->length == 1) { - // on cherche un id simple, on utilisera la syntaxe sql 'like' (l'extension repérera elle méme la syntaxe car la value finira par '%') - $this->addtoTIDS($tree["RB"], $bid, $nodes->item(0)); - // $this->thesaurusDOMNodes[] = $nodes->item(0); - } else { - // on cherche plusieurs id's, on utilisera la syntaxe 'regexp' (l'extension repérera elle meme la syntaxe car la value finira par '$') - $val = ""; - foreach ($nodes as $node) { - if(!isset($tree["CONTEXT"])) - $ambigus++; - $this->addtoTIDS($tree["RB"], $bid, $node); - } - } - $path = $tree["RB"]["SREF"]["PATH"]; - $prophtml = ""; - $this->propAsHTML($domthe->documentElement, $prophtml, $path); - $this->proposals["TERMS"][$path]["HTML"] = $prophtml; - } else { - // le mot n'est pas dans le thesaurus - } - - return($ambigus); - } - */ public function containsColonOperator(&$tree) { - if ( ! $tree) { + if (!$tree) { return(false); } if ($tree["CLASS"] == "OPK" && $tree["NODETYPE"] == PHRASEA_OP_COLON && ($tree["RB"]["CLASS"] == "SIMPLE" || $tree["RB"]["CLASS"] == "QSIMPLE")) { @@ -866,7 +807,7 @@ class searchEngine_adapter_phrasea_queryParser if ($this->debug) printf("found node id='%s', v='%s' w='%s', k='%s', p='%s' for node-path=%s \n", $id, $DOMnode->getAttribute("v"), $w, $k, $p, $path); - if ( ! $k) + if (!$k) $k = null; $found = false; @@ -885,11 +826,11 @@ class searchEngine_adapter_phrasea_queryParser // } } } - if ( ! $found) + if (!$found) $extendednode["SREF"]["TIDS"][] = array("bid" => $bid, "pid" => $pid, "id" => $id, "w" => $w, "k" => $k, "lng" => $lng, "p" => $p); // on liste les propositions de thésaurus pour ce node (dans l'arbre simple) - if ( ! isset($this->proposals["BASES"]["b$bid"]["TERMS"][$path])) { + if (!isset($this->proposals["BASES"]["b$bid"]["TERMS"][$path])) { // $this->proposals["TERMS"][$path] = array("TERM"=>implode(" ", $extendednode["VALUE"]), "PROPOSALS"=>array()); $term = implode(" ", $extendednode["VALUE"]); if (isset($extendednode["CONTEXT"]) && $extendednode["CONTEXT"]) { @@ -910,7 +851,7 @@ class searchEngine_adapter_phrasea_queryParser // puis par remonter au père for ($node = $DOMnode->parentNode; $node && $node->nodeType == XML_ELEMENT_NODE && $node->parentNode; $node = $node->parentNode) { $id = $node->getAttribute("id"); - if ( ! $id) + if (!$id) break; // on a dépassé la racine du thésaurus $node->setAttribute("marked", "1"); } @@ -933,7 +874,7 @@ class searchEngine_adapter_phrasea_queryParser $txt .= $tab . "\t\"" . $w . ""; $txt .= $tab . "\t\""; $txt .= $tab . "\n"; - $ambiguites["n"] ++; + $ambiguites["n"]++; } else { if (isset($tree["CONTEXT"])) $w .= "[" . $tree["CONTEXT"] . "]"; @@ -968,7 +909,7 @@ class searchEngine_adapter_phrasea_queryParser public function get_ambigu(&$tree, $mouseCallback = "void", $depth = 0) { - if ( ! $tree) { + if (!$tree) { return(""); } @@ -990,22 +931,22 @@ class searchEngine_adapter_phrasea_queryParser public function set_default(&$tree, &$emptyw, $depth = 0) { - if ( ! $tree) { + if (!$tree) { return(true); } if ($tree["CLASS"] == "OPS" || $tree["CLASS"] == "OPK") { if ($tree["CLASS"] == "OPS") { - if ( ! $this->set_default($tree["LB"], $emptyw, $depth + 1)) { + if (!$this->set_default($tree["LB"], $emptyw, $depth + 1)) { return(false); } - if ( ! $this->set_default($tree["RB"], $emptyw, $depth + 1)) { + if (!$this->set_default($tree["RB"], $emptyw, $depth + 1)) { return(false); } } else { // OPK ! // jy 20041223 : ne pas appliquer d'op. par def. derriere un op arith. // ex : "d < 1/2/2003" : grouper la liste "1","2","2004" en "mot" unique - if ( ! $tree["LB"] || ($tree["LB"]["CLASS"] != "SIMPLE" && $tree["LB"]["CLASS"] != "QSIMPLE") || (is_array($tree["LB"]["VALUE"]) && count($tree["LB"]["VALUE"]) != 1)) { + if (!$tree["LB"] || ($tree["LB"]["CLASS"] != "SIMPLE" && $tree["LB"]["CLASS"] != "QSIMPLE") || (is_array($tree["LB"]["VALUE"]) && count($tree["LB"]["VALUE"]) != 1)) { // un op. arith. doit étre précédé d'un seul nom de champ if ($this->errmsg != "") $this->errmsg .= sprintf("\\n"); @@ -1013,7 +954,7 @@ class searchEngine_adapter_phrasea_queryParser return(false); } - if ( ! $tree["RB"] || ($tree["RB"]["CLASS"] != "SIMPLE" && $tree["RB"]["CLASS"] != "QSIMPLE")) { + if (!$tree["RB"] || ($tree["RB"]["CLASS"] != "SIMPLE" && $tree["RB"]["CLASS"] != "QSIMPLE")) { // un op. arith. doit étre suivi d'une valeur if ($this->errmsg != "") $this->errmsg .= sprintf("\\n"); @@ -1032,21 +973,21 @@ class searchEngine_adapter_phrasea_queryParser /** gestion des branches null * a revoir car ca ppete pas d'erreur mais corrige automatiquement * ** */ - if ( ! isset($tree["RB"])) + if (!isset($tree["RB"])) $tree = $tree["LB"]; else - if ( ! isset($tree["LB"])) + if (!isset($tree["LB"])) $tree = $tree["RB"]; } else { if (($tree["CLASS"] == "SIMPLE" || $tree["CLASS"] == "QSIMPLE")) { if (is_array($tree["VALUE"])) { $treetmp = null; $pnum = 0; - for ($i = 0; $i < count($tree["VALUE"]); $i ++ ) { + for ($i = 0; $i < count($tree["VALUE"]); $i++) { // gestion mot vide if (isset($emptyw[$tree["VALUE"][$i]]) || $tree["VALUE"][$i] == "?" || $tree["VALUE"][$i] == "*") { // on a forcé les '?' ou '*' isolés comme des mots vides - $pnum ++; + $pnum++; } else { if ($treetmp == null) { $treetmp = array("CLASS" => $tree["CLASS"], @@ -1105,7 +1046,7 @@ class searchEngine_adapter_phrasea_queryParser unset($tree["LB"]); unset($tree["RB"]); unset($tree["PNUM"]); - $nmodif ++; + $nmodif++; } else { $nmodif += $this->factor_or2($tree["LB"], $depth + 1); $nmodif += $this->factor_or2($tree["RB"], $depth + 1); @@ -1219,7 +1160,7 @@ class searchEngine_adapter_phrasea_queryParser } $tmp = $onedate; - if ( ! is_array($tmp)) + if (!is_array($tmp)) $tmp = explode(" ", $tmp); switch (sizeof($tmp)) { @@ -1473,7 +1414,7 @@ class searchEngine_adapter_phrasea_queryParser if ($inquote) { // quand on est entre guillements les tokens perdent leur signification $tree = $this->addtotree($tree, $t, $depth, $inquote); - if ( ! $tree) { + if (!$tree) { return(null); } } else { @@ -1492,16 +1433,16 @@ class searchEngine_adapter_phrasea_queryParser if ($inquote) { // quand on est entre guillements les tokens perdent leur signification $tree = $this->addtotree($tree, $t, $depth, $inquote); - if ( ! $tree) { + if (!$tree) { return(null); } } else { // '(' : appel récursif - if ( ! $tree) + if (!$tree) $tree = $this->maketree($depth + 1); else { if (($tree["CLASS"] == "OPS" || $tree["CLASS"] == "OPK") && $tree["RB"] == null) { $tree["RB"] = $this->maketree($depth + 1); - if ( ! $tree["RB"]) + if (!$tree["RB"]) $tree = null; } else { // ici on applique l'opérateur par défaut @@ -1514,7 +1455,7 @@ class searchEngine_adapter_phrasea_queryParser "RB" => $this->maketree($depth + 1)); } } - if ( ! $tree) { + if (!$tree) { return(null); } } @@ -1543,12 +1484,12 @@ class searchEngine_adapter_phrasea_queryParser print("OPENING QUOTE!
"); } // ouverture des guillemets -> récursivité - if ( ! $tree) + if (!$tree) $tree = $this->maketree($depth + 1, true); else { if (($tree["CLASS"] == "OPS" || $tree["CLASS"] == "OPK") && $tree["RB"] == null) { $tree["RB"] = $this->maketree($depth + 1, true); - if ( ! $tree["RB"]) + if (!$tree["RB"]) $tree = null; } else { // ici on applique l'opérateur par défaut @@ -1561,7 +1502,7 @@ class searchEngine_adapter_phrasea_queryParser "RB" => $this->maketree($depth + 1, true)); } } - if ( ! $tree) { + if (!$tree) { return(null); } } @@ -1573,7 +1514,7 @@ class searchEngine_adapter_phrasea_queryParser var_dump($tree); print("-------------------------\n"); } - if ( ! $tree) { + if (!$tree) { return(null); } break; @@ -1598,7 +1539,7 @@ class searchEngine_adapter_phrasea_queryParser print("-------------------------\n"); } - if ( ! $t) { + if (!$t) { return($tree); } @@ -1612,7 +1553,7 @@ class searchEngine_adapter_phrasea_queryParser // un [xxx] suit un terme : il introduit un contexte $tree["CONTEXT"] = $t["VALUE"]; } elseif ($tree["CLASS"] == "OPS" || $tree["CLASS"] == "OPK") { - if ( ! isset($tree["RB"]) || ! $tree["RB"]) { + if (!isset($tree["RB"]) || !$tree["RB"]) { // un [xxx] peut suivre un opérateur, c'est un paramétre normalement numérique $tree["PNUM"] = $t["VALUE"]; } else { @@ -1639,7 +1580,7 @@ class searchEngine_adapter_phrasea_queryParser break; case "TOK_CMP": // < > <= >= <> = : sont des opérateurs de comparaison - if ( ! $tree) { + if (!$tree) { // printf("\nUne question ne peut commencer par '" . $t["VALUE"] . "'
"); if ($this->errmsg != "") $this->errmsg .= "\\n"; @@ -1659,9 +1600,9 @@ class searchEngine_adapter_phrasea_queryParser return(array("CLASS" => "OPK", "VALUE" => $t["VALUE"], "NODETYPE" => $this->opk[$t["VALUE"]]["NODETYPE"], "PNUM" => null, "DEPTH" => $depth, "LB" => $tree, "RB" => null)); break; case "TOK_WORD": - if ($t["CLASS"] == "TOK_WORD" && isset($this->ops[$t["VALUE"]]) && ! $inquote) { + if ($t["CLASS"] == "TOK_WORD" && isset($this->ops[$t["VALUE"]]) && !$inquote) { // ce mot est un opérateur phrasea - if ( ! $tree) { + if (!$tree) { // printf("\n581 : Une question ne peut commencer par un opérateur
"); if ($this->errmsg != "") $this->errmsg .= "\\n"; @@ -1694,7 +1635,7 @@ class searchEngine_adapter_phrasea_queryParser // ce mot n'est pas un opérateur $pnum = null; $nodetype = PHRASEA_KEYLIST; - if ($t["CLASS"] == "TOK_WORD" && isset($this->spw[$t["VALUE"]]) && ! $inquote) { + if ($t["CLASS"] == "TOK_WORD" && isset($this->spw[$t["VALUE"]]) && !$inquote) { // mais c'est un mot 'spécial' de phrasea ('last', 'all') $type = $this->spw[$t["VALUE"]]["CLASS"]; $nodetype = $this->spw[$t["VALUE"]]["NODETYPE"]; @@ -1724,7 +1665,7 @@ class searchEngine_adapter_phrasea_queryParser $registry = registry::get_instance(); $w = $t["VALUE"]; if ($w != "?" && $w != "*") { // on laisse passer les 'isolés' pour les traiter plus tard comme des mots vides - for ($i = 0; $i < strlen($w); $i ++ ) { + for ($i = 0; $i < strlen($w); $i++) { $c = substr($w, $i, 1); if ($c == "?" || $c == "*") { if ($nok < $registry->get('GV_min_letters_truncation')) { @@ -1736,10 +1677,10 @@ class searchEngine_adapter_phrasea_queryParser } // $nok = 0; } else - $nok ++; + $nok++; } } - if ( ! $tree) { + if (!$tree) { return(array("CLASS" => $type, "NODETYPE" => $nodetype, "VALUE" => array($t["VALUE"]), "PNUM" => $pnum, "DEPTH" => $depth)); } switch ($tree["CLASS"]) { @@ -1924,8 +1865,8 @@ class searchEngine_adapter_phrasea_queryParser $l = mb_strlen($this->phq, 'UTF-8'); $t = ""; $c_utf8 = ""; - for ($i = 0; $i < $l; $i ++ ) { - if ( ! $this->unicode->has_indexer_bad_char(($c_utf8 = mb_substr($this->phq, $i, 1, 'UTF-8')))) { + for ($i = 0; $i < $l; $i++) { + if (!$this->unicode->has_indexer_bad_char(($c_utf8 = mb_substr($this->phq, $i, 1, 'UTF-8')))) { // $c = mb_strtolower($c); // $t .= isset($this->noaccent[$c]) ? $this->noaccent[$c] : $c; $t .= $this->unicode->remove_diacritics(mb_strtolower($c_utf8)); From 4d84b379832bde0c93dfe8364257cee9fea2fed7 Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Tue, 16 Oct 2012 13:54:56 +0200 Subject: [PATCH 2/9] Fix #930 Defaut d'affichage d elements inaccessible au download --- templates/web/common/dialog_export.twig | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/web/common/dialog_export.twig b/templates/web/common/dialog_export.twig index e99ed0b97e..f8c58140db 100644 --- a/templates/web/common/dialog_export.twig +++ b/templates/web/common/dialog_export.twig @@ -106,7 +106,7 @@ {% for name, values in download.get_display_download() %} {% if values.available > 0 %} -
+
{% if values.refused|length > 0 %} -