Search Engine : Rassemblement des fonctions dans un fichier

This commit is contained in:
Michael RICOIS 2016-10-10 10:54:55 +02:00
parent 94d22673fe
commit 99e7a183aa
2 changed files with 200 additions and 215 deletions

View File

@ -1,204 +0,0 @@
<?php
// --------------------------------------------------------------------------- //
// Fonctions sur les criteres
// --------------------------------------------------------------------------- //
if (defined('DEBUG') == false) {
define( 'DEBUG', 0);
}
if (defined('LOCAL') == false) {
define( 'LOCAL', 0);
}
// --------------------------------------------------------------------------- //
// Nouvelle sequence
// --------------------------------------------------------------------------- //
function nouvelleSequence(&$criteres)
{
$sequence = array(
array( 'crit' => 'IT ', 'next' => '12' ),
array( 'crit' => 'I ', 'next' => '00' ),
array( 'crit' => 'I SEP ', 'next' => '12' ),
array( 'crit' => ' T ', 'next' => '00' ),
array( 'crit' => ' TSEP ', 'next' => '13 61 61o61p' ),
array( 'crit' => ' D VNR', 'next' => '24 45o24o24p' ),
array( 'crit' => ' D NR', 'next' => '21o21p' ),
array( 'crit' => ' DL NR', 'next' => '21 21o21p' ),
array( 'crit' => ' DLVNR', 'next' => '36 45 24 45o24o24p' ),
array( 'crit' => ' P VNR', 'next' => '74 78o74o74p' ),
array( 'crit' => ' PD VNR', 'next' => '74 78o74o74p' ),
array( 'crit' => ' PDL NR', 'next' => '78 83o74 74o74p' ),
array( 'crit' => ' PDLV R', 'next' => '78 81 82 77 71' ),
array( 'crit' => ' PDLVN ', 'next' => '82 75 28 71' ),
array( 'crit' => ' PDLVNR', 'next' => '78 74 82 78o74o82o82p' ),
array( 'crit' => ' S ', 'next' => '30o30p' ),
array( 'crit' => ' S R', 'next' => '72o71 71o71p' ),
array( 'crit' => ' S N ', 'next' => '31' ),
array( 'crit' => ' S NR', 'next' => '77 43 71' ),
array( 'crit' => ' S V ', 'next' => '35o35p30' ),
array( 'crit' => ' S VN ', 'next' => '75 77o75o77p75p' ),
array( 'crit' => ' S V R', 'next' => '75 83' ),
array( 'crit' => ' S VNR', 'next' => '43 44 75 83 61 71' ),
array( 'crit' => ' S D ', 'next' => '40p40o61p61' ),
array( 'crit' => ' S D R', 'next' => '45o77 77o77p' ),
array( 'crit' => ' S D N ', 'next' => '71' ),
array( 'crit' => ' S D NR', 'next' => '77 43 71 31' ),
array( 'crit' => ' S D V ', 'next' => '77o40 40o' ),
array( 'crit' => ' S D V R', 'next' => '75 72 71' ),
array( 'crit' => ' S D VN ', 'next' => '43 41 77 71' ),
array( 'crit' => ' S D VNR', 'next' => '44 43 49 73 75 72 71' ),
array( 'crit' => ' S DL ', 'next' => '78 78p61p61p' ),
array( 'crit' => ' S DL R', 'next' => '82 78 77 71' ),
array( 'crit' => ' S DL N ', 'next' => '41 71' ),
array( 'crit' => ' S DL NR', 'next' => '78 82 81 78p77 43 71 31' ),
array( 'crit' => ' S DLV ', 'next' => '78 78p71' ),
array( 'crit' => ' S DLV R', 'next' => '78 83 82 75 72 40 71' ),
array( 'crit' => ' S DLVN ', 'next' => '78 82 78p43 71' ),
array( 'crit' => ' S DLVNR', 'next' => '78 49 77 43 78p75 41 72 71 22' ),
array( 'crit' => ' S P ', 'next' => '60o60p31 31o31p' ),
array( 'crit' => ' S P R', 'next' => '45 77 41' ),
array( 'crit' => ' S P N ', 'next' => '71 71o45 45p' ),
array( 'crit' => ' S P NR', 'next' => '77 72 33 32' ),
array( 'crit' => ' S P V ', 'next' => '63o45 45o45p' ),
array( 'crit' => ' S P VN ', 'next' => '45 43 61 64' ),
array( 'crit' => ' S P V R', 'next' => '75 83 45 35' ),
array( 'crit' => ' S P VNR', 'next' => '77 45 44 43 73 75 72 71 41 42 40' ),
array( 'crit' => ' S PD ', 'next' => '45 71p71o' ),
array( 'crit' => ' S PD R', 'next' => '77 45 71' ),
array( 'crit' => ' S PD N ', 'next' => '71 71o45 45o' ),
array( 'crit' => ' S PD NR', 'next' => '77 76 45 41 43 40' ),
array( 'crit' => ' S PD V ', 'next' => '45 45o71 42 42p' ),
array( 'crit' => ' S PD V R', 'next' => '77 83 43 71 41' ),
array( 'crit' => ' S PD VN ', 'next' => '83 75 71 44 83o75o71o44o43 41 40 40o40p' ),
array( 'crit' => ' S PD VNR', 'next' => '77 74 45 44 43 75 71 61 63 60 40' ),
array( 'crit' => ' S PDL ', 'next' => '71 71o71p45 45o' ),
array( 'crit' => ' S PDL R', 'next' => '78 82 75 45 44' ),
array( 'crit' => ' S PDL N ', 'next' => '73 48 41' ),
array( 'crit' => ' S PDL NR', 'next' => '78 82 81 49 77 65 44 43 75 60 31' ),
array( 'crit' => ' S PDLV ', 'next' => '78 45 45o71 42 42p40' ),
array( 'crit' => ' S PDLV R', 'next' => '78 83 82 75 45 49 46 42 71 40' ),
array( 'crit' => ' S PDLVN ', 'next' => '78 83 77 45 71 42 41 40' ),
array( 'crit' => ' S PDLVNR', 'next' => '78 83 27 74 45 44 43 42 40' ),
array( 'crit' => ' SE ', 'next' => '31o31p' ),
array( 'crit' => ' SE R', 'next' => '72o71 71o71p' ),
array( 'crit' => ' SE N ', 'next' => '31' ),
array( 'crit' => ' SE NR', 'next' => '77 43 71' ),
array( 'crit' => ' SE V ', 'next' => '35o35p30' ),
array( 'crit' => ' SE V R', 'next' => '75 83' ),
array( 'crit' => ' SE VN ', 'next' => '75 77' ),
array( 'crit' => ' SE VNR', 'next' => '43 44 75 83 61 71' ),
array( 'crit' => ' SE D ', 'next' => '40o30' ),
array( 'crit' => ' SE D R', 'next' => '45o77' ),
array( 'crit' => ' SE D N ', 'next' => '71' ),
array( 'crit' => ' SE D NR', 'next' => '77 43 71 31' ),
array( 'crit' => ' SE D V ', 'next' => '77o40' ),
array( 'crit' => ' SE D V R', 'next' => '75 72 71' ),
array( 'crit' => ' SE D VN ', 'next' => '43 41 77' ),
array( 'crit' => ' SE D VNR', 'next' => '44 43 49 73 75 72 71' ),
array( 'crit' => ' SE DL ', 'next' => '40' ),
array( 'crit' => ' SE DL R', 'next' => '82 78 77' ),
array( 'crit' => ' SE DL N ', 'next' => '45 43 82o45o43o43p' ),
array( 'crit' => ' SE DL NR', 'next' => '78 82 81 46 77 43 71 31' ),
array( 'crit' => ' SE DLV ', 'next' => '78 78o71 71o71p' ),
array( 'crit' => ' SE DLV R', 'next' => '78 83 82 75 72 40' ),
array( 'crit' => ' SE DLVN ', 'next' => '78 82 46 43 71' ),
array( 'crit' => ' SE DLVNR', 'next' => '78 49 77 43 46 75 41 72 71 22' ),
array( 'crit' => ' SEP ', 'next' => '61p31 31p30' ),
array( 'crit' => ' SEP R', 'next' => '45 77 41' ),
array( 'crit' => ' SEP N ', 'next' => '71 71o45 45p' ),
array( 'crit' => ' SEP NR', 'next' => '77 72 33 32' ),
array( 'crit' => ' SEP V ', 'next' => '63o45' ),
array( 'crit' => ' SEP V R', 'next' => '75 83 45 35' ),
array( 'crit' => ' SEP VN ', 'next' => '45 43 61 64' ),
array( 'crit' => ' SEP VNR', 'next' => '77 45 44 43 73 75 72 71 41 42 40' ),
array( 'crit' => ' SEPD ', 'next' => '45 71p' ),
array( 'crit' => ' SEPD R', 'next' => '77 45' ),
array( 'crit' => ' SEPD N ', 'next' => '71 71o45 40' ),
array( 'crit' => ' SEPD NR', 'next' => '77 76 45 41 43 40' ),
array( 'crit' => ' SEPD V ', 'next' => '45 71p71o40' ),
array( 'crit' => ' SEPD V R', 'next' => '77 83 43 71 41 40' ),
array( 'crit' => ' SEPD VN ', 'next' => '83 75 71 44 83o75o71o44o43 41 40 40o40p' ),
array( 'crit' => ' SEPD VNR', 'next' => '77 74 45 44 43 75 71 61 63 60 40' ),
array( 'crit' => ' SEPDL ', 'next' => '45 71p40' ),
array( 'crit' => ' SEPDL R', 'next' => '78 82 75 45 44 40' ),
array( 'crit' => ' SEPDL N ', 'next' => '73 48 41 40' ),
array( 'crit' => ' SEPDL NR', 'next' => '78 82 81 49 77 65 44 43 75 60 31' ),
array( 'crit' => ' SEPDLV ', 'next' => '78 45 45o71 42 42p' ),
array( 'crit' => ' SEPDLV R', 'next' => '78 83 82 75 45 49 46 42 71 40' ),
array( 'crit' => ' SEPDLVN ', 'next' => '78 83 77 45 71 42 41 40' ),
array( 'crit' => ' SEPDLVNR', 'next' => '78 83 27 74 45 44 43 42 40' ),
);
foreach ($sequence as $ligne) {
if (strstr($ligne['crit'], $criteres) != false) {
return str_split($ligne['next'], 3);
}
}
return array();
}
// --------------------------------------------------------------------------- //
// Nouvelle combinaison
// --------------------------------------------------------------------------- //
function nouvelleCombinaison(&$sequence, &$sequencePos, $pass, &$index, &$mode)
{
for (;;) {
if (isset($sequence[$sequencePos]) === false) {
return '';
}
$combinaison = trim($sequence[$sequencePos]);
++$sequencePos;
if (strlen($combinaison) == 2) {
return $combinaison;
}
// Passage en phonetique ou en orthographique
if (strlen($combinaison) == 3) {
if ($pass == 2 || $pass == 3) {
continue;
}
$car = strtolower(substr($combinaison, 2, 1));
//Search Engine Version 2, we remove the orthographique
if (SPHINX_ENT_VERSION == 2 && $car == 'o') {
return strtolower(substr($combinaison, 0, 2));
}
switch($car) {
case 'p':
$index = 'ent_phx';
$mode = SPH_MATCH_EXTENDED2;
break;
case 'o':
$index = 'ent_mns';
$mode = SPH_MATCH_ISPELL;
break;
default:
debugln("attention: mode inconnu: '$car'");
}
} else if ($pass == 1) {
$index = 'ent_mns';
//Search Engine Version 2, we remove the orthographique
if (SPHINX_ENT_VERSION == 2) {
$index = 'ent';
}
}
return $combinaison;
}
}
// --------------------------------------------------------------------------- //
// Nouveaux criteres
// --------------------------------------------------------------------------- //
function nouveauxCriteres($comb2crit, $combinaison)
{
if ( array_key_exists($combinaison, $comb2crit) ) {
$ligne = $comb2crit[$combinaison];
return $ligne;
}
return '';
}
?>

View File

@ -6,8 +6,6 @@ if (defined('DEBUG') == false) {
define( 'DEBUG', 0);
}
require_once realpath(dirname(__FILE__)).'/criteresFonc.php';
$gDatabaseJO = databaseJO();
// --------------------------------------------------------------------------- //
@ -36,17 +34,15 @@ function println($ln = '')
// debugln
// --------------------------------------------------------------------------- //
if (DEBUG) {
function debugln($ln = '')
{
function debugln($ln = '') {
print $ln.'<br/>';
}
} else if (LOCAL) {
function debugln($ln = '')
{
}
} else {
function debugln($ln = '')
{
}
else if (LOCAL) {
function debugln($ln = '') {}
}
else {
function debugln($ln = '') {
/*
$fp = fopen(LOG_PATH.'/recherchesDebug.log', 'a');
fwrite($fp, $ln."\n");
@ -55,6 +51,199 @@ if (DEBUG) {
}
}
// --------------------------------------------------------------------------- //
// Nouvelle sequence
// --------------------------------------------------------------------------- //
function nouvelleSequence(&$criteres)
{
$sequence = array(
array( 'crit' => 'IT ', 'next' => '12' ),
array( 'crit' => 'I ', 'next' => '00' ),
array( 'crit' => 'I SEP ', 'next' => '12' ),
array( 'crit' => ' T ', 'next' => '00' ),
array( 'crit' => ' TSEP ', 'next' => '13 61 61o61p' ),
array( 'crit' => ' D VNR', 'next' => '24 45o24o24p' ),
array( 'crit' => ' D NR', 'next' => '21o21p' ),
array( 'crit' => ' DL NR', 'next' => '21 21o21p' ),
array( 'crit' => ' DLVNR', 'next' => '36 45 24 45o24o24p' ),
array( 'crit' => ' P VNR', 'next' => '74 78o74o74p' ),
array( 'crit' => ' PD VNR', 'next' => '74 78o74o74p' ),
array( 'crit' => ' PDL NR', 'next' => '78 83o74 74o74p' ),
array( 'crit' => ' PDLV R', 'next' => '78 81 82 77 71' ),
array( 'crit' => ' PDLVN ', 'next' => '82 75 28 71' ),
array( 'crit' => ' PDLVNR', 'next' => '78 74 82 78o74o82o82p' ),
array( 'crit' => ' S ', 'next' => '30o30p' ),
array( 'crit' => ' S R', 'next' => '72o71 71o71p' ),
array( 'crit' => ' S N ', 'next' => '31' ),
array( 'crit' => ' S NR', 'next' => '77 43 71' ),
array( 'crit' => ' S V ', 'next' => '35o35p30' ),
array( 'crit' => ' S VN ', 'next' => '75 77o75o77p75p' ),
array( 'crit' => ' S V R', 'next' => '75 83' ),
array( 'crit' => ' S VNR', 'next' => '43 44 75 83 61 71' ),
array( 'crit' => ' S D ', 'next' => '40p40o61p61' ),
array( 'crit' => ' S D R', 'next' => '45o77 77o77p' ),
array( 'crit' => ' S D N ', 'next' => '71' ),
array( 'crit' => ' S D NR', 'next' => '77 43 71 31' ),
array( 'crit' => ' S D V ', 'next' => '77o40 40o' ),
array( 'crit' => ' S D V R', 'next' => '75 72 71' ),
array( 'crit' => ' S D VN ', 'next' => '43 41 77 71' ),
array( 'crit' => ' S D VNR', 'next' => '44 43 49 73 75 72 71' ),
array( 'crit' => ' S DL ', 'next' => '78 78p61p61p' ),
array( 'crit' => ' S DL R', 'next' => '82 78 77 71' ),
array( 'crit' => ' S DL N ', 'next' => '41 71' ),
array( 'crit' => ' S DL NR', 'next' => '78 82 81 78p77 43 71 31' ),
array( 'crit' => ' S DLV ', 'next' => '78 78p71' ),
array( 'crit' => ' S DLV R', 'next' => '78 83 82 75 72 40 71' ),
array( 'crit' => ' S DLVN ', 'next' => '78 82 78p43 71' ),
array( 'crit' => ' S DLVNR', 'next' => '78 49 77 43 78p75 41 72 71 22' ),
array( 'crit' => ' S P ', 'next' => '60o60p31 31o31p' ),
array( 'crit' => ' S P R', 'next' => '45 77 41' ),
array( 'crit' => ' S P N ', 'next' => '71 71o45 45p' ),
array( 'crit' => ' S P NR', 'next' => '77 72 33 32' ),
array( 'crit' => ' S P V ', 'next' => '63o45 45o45p' ),
array( 'crit' => ' S P VN ', 'next' => '45 43 61 64' ),
array( 'crit' => ' S P V R', 'next' => '75 83 45 35' ),
array( 'crit' => ' S P VNR', 'next' => '77 45 44 43 73 75 72 71 41 42 40' ),
array( 'crit' => ' S PD ', 'next' => '45 71p71o' ),
array( 'crit' => ' S PD R', 'next' => '77 45 71' ),
array( 'crit' => ' S PD N ', 'next' => '71 71o45 45o' ),
array( 'crit' => ' S PD NR', 'next' => '77 76 45 41 43 40' ),
array( 'crit' => ' S PD V ', 'next' => '45 45o71 42 42p' ),
array( 'crit' => ' S PD V R', 'next' => '77 83 43 71 41' ),
array( 'crit' => ' S PD VN ', 'next' => '83 75 71 44 83o75o71o44o43 41 40 40o40p' ),
array( 'crit' => ' S PD VNR', 'next' => '77 74 45 44 43 75 71 61 63 60 40' ),
array( 'crit' => ' S PDL ', 'next' => '71 71o71p45 45o' ),
array( 'crit' => ' S PDL R', 'next' => '78 82 75 45 44' ),
array( 'crit' => ' S PDL N ', 'next' => '73 48 41' ),
array( 'crit' => ' S PDL NR', 'next' => '78 82 81 49 77 65 44 43 75 60 31' ),
array( 'crit' => ' S PDLV ', 'next' => '78 45 45o71 42 42p40' ),
array( 'crit' => ' S PDLV R', 'next' => '78 83 82 75 45 49 46 42 71 40' ),
array( 'crit' => ' S PDLVN ', 'next' => '78 83 77 45 71 42 41 40' ),
array( 'crit' => ' S PDLVNR', 'next' => '78 83 27 74 45 44 43 42 40' ),
array( 'crit' => ' SE ', 'next' => '31o31p' ),
array( 'crit' => ' SE R', 'next' => '72o71 71o71p' ),
array( 'crit' => ' SE N ', 'next' => '31' ),
array( 'crit' => ' SE NR', 'next' => '77 43 71' ),
array( 'crit' => ' SE V ', 'next' => '35o35p30' ),
array( 'crit' => ' SE V R', 'next' => '75 83' ),
array( 'crit' => ' SE VN ', 'next' => '75 77' ),
array( 'crit' => ' SE VNR', 'next' => '43 44 75 83 61 71' ),
array( 'crit' => ' SE D ', 'next' => '40o30' ),
array( 'crit' => ' SE D R', 'next' => '45o77' ),
array( 'crit' => ' SE D N ', 'next' => '71' ),
array( 'crit' => ' SE D NR', 'next' => '77 43 71 31' ),
array( 'crit' => ' SE D V ', 'next' => '77o40' ),
array( 'crit' => ' SE D V R', 'next' => '75 72 71' ),
array( 'crit' => ' SE D VN ', 'next' => '43 41 77' ),
array( 'crit' => ' SE D VNR', 'next' => '44 43 49 73 75 72 71' ),
array( 'crit' => ' SE DL ', 'next' => '40' ),
array( 'crit' => ' SE DL R', 'next' => '82 78 77' ),
array( 'crit' => ' SE DL N ', 'next' => '45 43 82o45o43o43p' ),
array( 'crit' => ' SE DL NR', 'next' => '78 82 81 46 77 43 71 31' ),
array( 'crit' => ' SE DLV ', 'next' => '78 78o71 71o71p' ),
array( 'crit' => ' SE DLV R', 'next' => '78 83 82 75 72 40' ),
array( 'crit' => ' SE DLVN ', 'next' => '78 82 46 43 71' ),
array( 'crit' => ' SE DLVNR', 'next' => '78 49 77 43 46 75 41 72 71 22' ),
array( 'crit' => ' SEP ', 'next' => '61p31 31p30' ),
array( 'crit' => ' SEP R', 'next' => '45 77 41' ),
array( 'crit' => ' SEP N ', 'next' => '71 71o45 45p' ),
array( 'crit' => ' SEP NR', 'next' => '77 72 33 32' ),
array( 'crit' => ' SEP V ', 'next' => '63o45' ),
array( 'crit' => ' SEP V R', 'next' => '75 83 45 35' ),
array( 'crit' => ' SEP VN ', 'next' => '45 43 61 64' ),
array( 'crit' => ' SEP VNR', 'next' => '77 45 44 43 73 75 72 71 41 42 40' ),
array( 'crit' => ' SEPD ', 'next' => '45 71p' ),
array( 'crit' => ' SEPD R', 'next' => '77 45' ),
array( 'crit' => ' SEPD N ', 'next' => '71 71o45 40' ),
array( 'crit' => ' SEPD NR', 'next' => '77 76 45 41 43 40' ),
array( 'crit' => ' SEPD V ', 'next' => '45 71p71o40' ),
array( 'crit' => ' SEPD V R', 'next' => '77 83 43 71 41 40' ),
array( 'crit' => ' SEPD VN ', 'next' => '83 75 71 44 83o75o71o44o43 41 40 40o40p' ),
array( 'crit' => ' SEPD VNR', 'next' => '77 74 45 44 43 75 71 61 63 60 40' ),
array( 'crit' => ' SEPDL ', 'next' => '45 71p40' ),
array( 'crit' => ' SEPDL R', 'next' => '78 82 75 45 44 40' ),
array( 'crit' => ' SEPDL N ', 'next' => '73 48 41 40' ),
array( 'crit' => ' SEPDL NR', 'next' => '78 82 81 49 77 65 44 43 75 60 31' ),
array( 'crit' => ' SEPDLV ', 'next' => '78 45 45o71 42 42p' ),
array( 'crit' => ' SEPDLV R', 'next' => '78 83 82 75 45 49 46 42 71 40' ),
array( 'crit' => ' SEPDLVN ', 'next' => '78 83 77 45 71 42 41 40' ),
array( 'crit' => ' SEPDLVNR', 'next' => '78 83 27 74 45 44 43 42 40' ),
);
foreach ($sequence as $ligne) {
if (strstr($ligne['crit'], $criteres) != false) {
return str_split($ligne['next'], 3);
}
}
return array();
}
// --------------------------------------------------------------------------- //
// Nouvelle combinaison
// --------------------------------------------------------------------------- //
function nouvelleCombinaison(&$sequence, &$sequencePos, $pass, &$index, &$mode)
{
for (;;) {
if (isset($sequence[$sequencePos]) === false) {
return '';
}
$combinaison = trim($sequence[$sequencePos]);
++$sequencePos;
if (strlen($combinaison) == 2) {
return $combinaison;
}
// Passage en phonetique ou en orthographique
if (strlen($combinaison) == 3) {
if ($pass == 2 || $pass == 3) {
continue;
}
$car = strtolower(substr($combinaison, 2, 1));
//Search Engine Version 2, we remove the orthographique
if (SPHINX_ENT_VERSION == 2 && $car == 'o') {
return strtolower(substr($combinaison, 0, 2));
}
switch($car) {
case 'p':
$index = 'ent_phx';
$mode = SPH_MATCH_EXTENDED2;
break;
case 'o':
$index = 'ent_mns';
$mode = SPH_MATCH_ISPELL;
break;
default:
debugln("attention: mode inconnu: '$car'");
}
} else if ($pass == 1) {
$index = 'ent_mns';
//Search Engine Version 2, we remove the orthographique
if (SPHINX_ENT_VERSION == 2) {
$index = 'ent';
}
}
return $combinaison;
}
}
// --------------------------------------------------------------------------- //
// Nouveaux criteres
// --------------------------------------------------------------------------- //
function nouveauxCriteres($comb2crit, $combinaison)
{
if ( array_key_exists($combinaison, $comb2crit) ) {
$ligne = $comb2crit[$combinaison];
return $ligne;
}
return '';
}
// --------------------------------------------------------------------------- //
// Filtre les caracteres speciaux
// --------------------------------------------------------------------------- //