Skip to content

Commit

Permalink
corrections opérateurs + ajout recherche de phrase
Browse files Browse the repository at this point in the history
  • Loading branch information
anayrat authored and gleu committed Jul 18, 2017
1 parent 4567a1b commit ec9597b
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions www-docs.postgresql.fr/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function addEngine(name,ext,cat,type)
<form method="post" action="search.php">
<div>
<h2><label for="q">Rechercher</label></h2>
<input id="q" name="q" type="text" size="16" maxlength="255" onfocus="if( this.value=='Rechercher' ) this.value='';" value="<?= strlen($_REQUEST['q'])>0 ? $_REQUEST['q'] : 'Rechercher' ?>" accesskey="s" />
<input id="q" name="q" type="text" size="16" maxlength="255" title='Vous pouvez utiliser les opérateurs suivants : "and", "&","not","!","or","|","<->" ("suivi de" pour recherche de phrase)' onfocus="if( this.value=='rechercher' ) this.value='';" value="<?= strlen($_request['q'])>0 ? $_request['q'] : 'rechercher' ?>" accesskey="s" />
<select id="v" name="v">
<?php
$query = "SELECT version, count(*) as nb FROM pages GROUP BY version ORDER BY version DESC";
Expand Down Expand Up @@ -162,23 +162,34 @@ function addEngine(name,ext,cat,type)

$searchstring = '';

$no_and = false;

if( preg_match_all('/([-!]?)(\S+)\s*/', $recherche, $m, PREG_SET_ORDER ) ) {
foreach( $m as $terms ) {
if (strlen($terms[1])) {
$searchstring .= ' & !';
}
if (strtolower($terms[2]) === 'and' && strlen($terms[3]) > 0) {
if (strtolower($terms[2]) === 'and') {
$searchstring .= ' & ';
}
else if ((strtolower($terms[2]) === 'or' or $terms[2] === '|') &&
strlen($terms[3]) > 0) {
else if (strtolower($terms[2]) === 'or' or $terms[2] === '|') {
$searchstring .= ' | ';
}
else if (strtolower($terms[2]) === 'not' && strlen($terms[3]) > 0) {
else if (strtolower($terms[2]) === 'not') {
$searchstring .= ' & !';
}
else if (strtolower($terms[2]) === '<->') {
$searchstring .= ' <->';
$no_and = true;
}
else {
$searchstring .= " & $terms[2]";
if ($no_and) {
$searchstring .= " $terms[2]";
$no_and = false;
}
else {
$searchstring .= " & $terms[2]";
}
}
}
}
Expand Down

0 comments on commit ec9597b

Please sign in to comment.