Changeset 1004
- Timestamp:
- 04/23/08 18:46:29 (7 months ago)
- Files:
-
- traduc/trunk/www/search.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
traduc/trunk/www/search.php
r1003 r1004 2 2 $recherche = $_POST['q']; 3 3 $filtreversion = $_POST['v']; 4 5 ## No backslashes allowed 6 $recherche = preg_replace('/\\\/', '', $recherche); 7 ## Collapse parens into nearby words: 8 $recherche = preg_replace('/\s*\(\s*/', ' (', $recherche); 9 $recherche = preg_replace('/\s*\)\s*/', ') ', $recherche); 10 ## Treat colons as word separators: 11 $recherche = preg_replace('/:/', ' ', $recherche); 12 13 $recherche_value = strlen($recherche)>0 ? $recherche : 'Rechercher'; 14 4 15 $pgconn = @pg_connect("host=localhost dbname=docspgfr user=docspgfr") or die('Connexion impossible'); 5 //$query = "SELECT set_curcfg('utf8_french')"; 6 //$result = pg_query($pgconn, $query); 16 17 $query = "SET client_encoding TO utf8;"; 18 $result = pg_query($pgconn, $query); 7 19 8 20 $version['801'] = '8.1'; … … 17 29 <link rel="shortcut icon" href="/favicon.ico" /> 18 30 <link rel="stylesheet" href="css/style.css" type="text/css" title="Test" /> 19 <!--20 <link rel="search" type="application/opensearchdescription+xml" title="PgFr Docs 8.1.X" href="http://docs.postgresqlfr.org/addon/pgfr-docs81-ff.osd" />21 -->22 31 <script type="text/javascript"> 23 32 <!-- … … 73 82 </form> 74 83 <? 75 $recherche = pg_escape_string($_POST['q']); 84 $like[0]="'sql-%".pg_escape_string(ereg_replace(' ','',$recherche))."%.html'"; 85 $like[1]="'app-%".pg_escape_string(ereg_replace('_','',$recherche))."%.html'"; 86 $like[2]="'app-%".pg_escape_string(ereg_replace('_','-',$recherche))."%.html'"; 76 87 77 88 $query = "SELECT version, url, titre 78 89 FROM pages 79 WHERE (url like 'sql-%".ereg_replace(' ','',$recherche)."%.html' OR url like 'app-%".ereg_replace('_','',$recherche)."%.html' OR url like 'app-%".ereg_replace('_','-',$recherche)."%.html') ";80 if ( $filtreversion > 0)90 WHERE (url like {$like[0]} OR url like {$like[1]} OR url like {$like[2]}) "; 91 if (array_key_exists($filtreversion, $version)) { 81 92 $query .= "AND version=".pg_escape_string($filtreversion)." "; 93 } 82 94 $query .= "ORDER BY version desc, titre "; 83 95 $result = pg_query($pgconn, $query); … … 95 107 96 108 $result = pg_query($pgconn, $query); 97 98 pg_close($pgconn);99 109 ?> 100 110 </ol> … … 108 118 <? 109 119 110 $pgconn = pg_connect("host=localhost dbname=docspgfr user=docspgfr") or die('Connexion impossible'); 111 $query = "SET client_encoding TO utf8;"; 112 $result = pg_query($pgconn, $query); 120 $searchstring = ''; 121 if( preg_match_all('/([-!]?)(\S+)\s*/', $recherche, $m, PREG_SET_ORDER ) ) { 122 foreach( $m as $terms ) { 123 if (strlen($terms[1])) { 124 $searchstring .= ' & !'; 125 } 126 if (strtolower($terms[2]) === 'and') { 127 $searchstring .= ' & '; 128 } 129 else if (strtolower($terms[2]) === 'or' or $terms[2] === '|') { 130 $searchstring .= ' | '; 131 } 132 else if (strtolower($terms[2]) === 'not') { 133 $searchstring .= ' & !'; 134 } 135 else { 136 $searchstring .= " & $terms[2]"; 137 } 138 } 139 } 113 140 114 $term = $_POST['q']; 141 ## Strip out leading junk 142 $searchstring = preg_replace('/^[\s\&\|]+/', '', $searchstring); 115 143 116 ## No backslashes allowed 117 $term = preg_replace('/\\\/', '', $term);144 ## Remove any doubled-up operators 145 $searchstring = preg_replace('/([\!\&\|]) +(?:[\&\|] +)+/', "$1 ", $searchstring); 118 146 119 ## Collapse parens into nearby words: 120 $term = preg_replace('/\s*\(\s*/', ' (', $term); 121 $term = preg_replace('/\s*\)\s*/', ') ', $term); 147 ## Remove any non-spaced operators (e.g. "Zounds!") 148 $searchstring = preg_replace('/([^ ])[\!\&\|]/', "$1", $searchstring); 122 149 123 ## Treat colons as word separators: 124 $term = preg_replace('/:/', ' ', $term);150 ## Remove any trailing whitespace or operators 151 $searchstring = preg_replace('/[\s\!\&\|]+$/', '', $searchstring); 125 152 126 $searchstring = ''; 127 if( preg_match_all('/([-!]?)(\S+)\s*/', $term, $m, PREG_SET_ORDER ) ) { 128 foreach( $m as $terms ) { 129 if (strlen($terms[1])) { 130 $searchstring .= ' & !'; 131 } 132 if (strtolower($terms[2]) === 'and') { 133 $searchstring .= ' & '; 134 } 135 else if (strtolower($terms[2]) === 'or' or $terms[2] === '|') { 136 $searchstring .= ' | '; 137 } 138 else if (strtolower($terms[2]) === 'not') { 139 $searchstring .= ' & !'; 140 } 141 else { 142 $searchstring .= " & $terms[2]"; 143 } 144 } 145 } 146 147 ## Strip out leading junk 148 $searchstring = preg_replace('/^[\s\&\|]+/', '', $searchstring); 149 150 ## Remove any doubled-up operators 151 $searchstring = preg_replace('/([\!\&\|]) +(?:[\&\|] +)+/', "$1 ", $searchstring); 152 153 ## Remove any non-spaced operators (e.g. "Zounds!") 154 $searchstring = preg_replace('/([^ ])[\!\&\|]/', "$1", $searchstring); 155 156 ## Remove any trailing whitespace or operators 157 $searchstring = preg_replace('/[\s\!\&\|]+$/', '', $searchstring); 158 159 ## Remove unnecessary quotes around everything 160 $searchstring = preg_replace('/^[\'"](.*)[\'"]$/', "$1", $searchstring); 161 162 ## Quote the whole thing 163 //$searchstring = $this->db->addQuotes($searchstring); 164 165 //echo "term : $term<br/>\nsearchstring = $searchstring<br/>\n"; 153 ## Remove unnecessary quotes around everything 154 $searchstring = preg_replace('/^[\'"](.*)[\'"]$/', "$1", $searchstring); 166 155 167 156 $query = "SELECT version, url, titre, ts_headline(contenu, q) AS resume, to_char(ts_rank(fti, q)*100, '999.99') AS score 168 157 FROM pages, to_tsquery('".pg_escape_string($searchstring)."') AS q 169 158 WHERE fti @@ q "; 170 if ( $filtreversion > 0)159 if (array_key_exists($filtreversion, $version)) { 171 160 $query .= "AND version=".pg_escape_string($filtreversion)." "; 172 $query .= "ORDER BY ts_rank(fti, q) DESC 161 } 162 $query .= "ORDER BY ts_rank(fti, q) DESC, version DESC 173 163 LIMIT 100"; 174 164 $result = pg_query($pgconn, $query); 175 176 //echo $query;177 165 178 166 while ($ligne = pg_fetch_array($result)) { … … 189 177 </ol> 190 178 </div> 191 <!-- 192 <div id="pg81"> 193 <h1>Un problÚme avec la documentation ?</h1> 194 <div class="listes"> 195 N'hésitez pas à nous en faire part sur notre <a 196 href="http://svn.postgresqlfr.org">site de traduction</a> 197 en remplissant un ticket. 198 </div> 199 </div> 200 --> 179 201 180 <div id="basdepage" > 202 181 <a href="http://www.postgresqlfr.org/">Retour au site</a>

