Subversion Repositories Applications.papyrus

Rev

Rev 2141 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2141 Rev 2143
Line 92... Line 92...
92
 
92
 
93
	$db = mysql_connect(SPHINX_DSN, NULL, NULL, TRUE);
93
	$db = mysql_connect(SPHINX_DSN, NULL, NULL, TRUE);
94
	// AFAICT, pas de réel risque de SQL-injection du côté de sphinx (au pire, $req = FALSE)
94
	// AFAICT, pas de réel risque de SQL-injection du côté de sphinx (au pire, $req = FALSE)
95
	// et il serait dommage de devoir limiter la puissante syntaxe offerte à  l'utilisation
95
	// et il serait dommage de devoir limiter la puissante syntaxe offerte à  l'utilisation
96
	//$requeteTpl = "SELECT group_id, main_id FROM i_projet, i_spip, i_papyrus, i_bazar, i_coste, i_nvjfl WHERE MATCH('%s') LIMIT 50";
96
	//$requeteTpl = "SELECT group_id, main_id FROM i_projet, i_spip, i_papyrus, i_bazar, i_coste, i_nvjfl WHERE MATCH('%s') LIMIT 50";
97
	$requeteTpl = 'SELECT group_id, main_id, id '.
97
	$requeteTpl = 'SELECT group_id, main_id, id, WEIGHT() AS poids '.
98
		'FROM i_projet, i_spip, i_papyrus, i_bazar, i_coste, i_nvjfl '.
98
		'FROM i_projet, i_spip, i_papyrus, i_bazar, i_coste, i_nvjfl '.
99
		"WHERE MATCH('%s') ".
99
		"WHERE MATCH('%s') ".
100
		'LIMIT 50 ';
100
		'LIMIT 50 ';
Line 101... Line 101...
101
	$requete = mysql_query(sprintf($requeteTpl, $q), $db);
101
	$requete = mysql_query(sprintf($requeteTpl, $q), $db);
102
 
102
 
103
	$retour = array();
103
	$retour = array();
104
	if ($requete) {
104
	if ($requete) {
-
 
105
		$res = array('spip' => array(), 'bazar' => array(), 'projet' => array(), 'papyrus' => array(), 'coste' => array(), 'nvjfl' => array());
105
		$res = array('spip' => array(), 'bazar' => array(), 'projet' => array(), 'papyrus' => array(), 'coste' => array(), 'nvjfl' => array());
106
		$ids_par_poids = array();
-
 
107
		$poidsMax = 0;
106
		$ids_par_poids = array();
108
		while ($rec = mysql_fetch_array($requete, MYSQL_ASSOC)) {
107
		while($rec = mysql_fetch_array($requete, MYSQL_ASSOC)) {
109
			$poidsMax = ($rec['poids'] > $poidsMax) ? $rec['poids'] : $poidsMax;
108
			$res[$rec['group_id']][$rec['id']] = $rec;
110
			$res[$rec['group_id']][$rec['id']] = $rec;
Line 109... Line 111...
109
			$ids_par_poids[] = $rec['main_id'];
111
			$ids_par_poids[] = $rec['main_id'];
110
		}
112
		}
111
 
113
 
112
		$docs = array();
114
		$docs = array();
113
		// spip
115
		// spip
114
		$spip = new MoteurRecherche_SPIP();
116
		$spip = new MoteurRecherche_SPIP();
115
		foreach($spip->get(array_filter(array_keys($res['spip']), 'intval'), $q) as $v) {
117
		foreach ($spip->get(array_filter(array_keys($res['spip']), 'intval'), $q) as $v) {
116
			unset($res['spip'][$v['id']]['group_id'],
-
 
117
				  $res['spip'][$v['id']]['main_id'],
118
			unset($res['spip'][$v['id']]['group_id'],
118
				  $res['spip'][$v['id']]['id']);
119
				$res['spip'][$v['id']]['main_id'],
Line 119... Line 120...
119
			// left: weight
120
				$res['spip'][$v['id']]['id']);
120
			$docs['spip-' . $v['id']] = array_merge($v,	$res['spip'][$v['id']]);
121
			$docs['spip-' . $v['id']] = array_merge($v,	$res['spip'][$v['id']]);
121
		}
122
		}
122
 
123
 
123
		// bazar
124
		// bazar
124
		$bazar = new MoteurRecherche_BAZAR();
125
		$bazar = new MoteurRecherche_BAZAR();
125
		foreach($bazar->get(array_filter(array_keys($res['bazar']), 'intval'), $q) as $v) {
-
 
126
			unset($res['bazar'][$v['id']]['group_id'],
126
		foreach ($bazar->get(array_filter(array_keys($res['bazar']), 'intval'), $q) as $v) {
127
				  $res['bazar'][$v['id']]['main_id'],
127
			unset($res['bazar'][$v['id']]['group_id'],
Line 128... Line 128...
128
				  $res['bazar'][$v['id']]['id']);
128
				$res['bazar'][$v['id']]['main_id'],
129
			// left: weight
129
				$res['bazar'][$v['id']]['id']);
130
			$docs['bazar-' . $v['id']] = array_merge($v, $res['bazar'][$v['id']]);
130
			$docs['bazar-' . $v['id']] = array_merge($v, $res['bazar'][$v['id']]);
131
		}
131
		}
132
 
132
 
133
		// projet
133
		// projet
134
		$projet = new MoteurRecherche_PROJET();
-
 
135
		foreach($projet->get(array_filter(array_keys($res['projet']), 'intval'), $q) as $v) {
134
		$projet = new MoteurRecherche_PROJET();
136
			unset($res['projet'][$v['id']]['group_id'],
135
		foreach ($projet->get(array_filter(array_keys($res['projet']), 'intval'), $q) as $v) {
Line 137... Line 136...
137
				  $res['projet'][$v['id']]['main_id'],
136
			unset($res['projet'][$v['id']]['group_id'],
138
				  $res['projet'][$v['id']]['id']);
137
				$res['projet'][$v['id']]['main_id'],
139
			// left: weight
138
				$res['projet'][$v['id']]['id']);
140
			$docs['projet-' . $v['id']] = array_merge($v, $res['projet'][$v['id']]);
139
			$docs['projet-' . $v['id']] = array_merge($v, $res['projet'][$v['id']]);
141
		}
140
		}
142
 
141
 
143
		// papyrus
-
 
144
		$papyrus = new MoteurRecherche_PAPYRUS();
142
		// papyrus
145
		foreach($papyrus->get(array_filter(array_keys($res['papyrus']), 'intval'), $q) as $v) {
143
		$papyrus = new MoteurRecherche_PAPYRUS();
Line 146... Line 144...
146
			unset($res['papyrus'][$v['id']]['group_id'],
144
		foreach ($papyrus->get(array_filter(array_keys($res['papyrus']), 'intval'), $q) as $v) {
147
				  $res['papyrus'][$v['id']]['main_id'],
145
			unset($res['papyrus'][$v['id']]['group_id'],
148
				  $res['papyrus'][$v['id']]['id']);
146
				$res['papyrus'][$v['id']]['main_id'],
149
			// left: weight
147
				$res['papyrus'][$v['id']]['id']);
150
			$docs['papyrus-' . $v['id']] = array_merge($v, $res['papyrus'][$v['id']]);
148
			$docs['papyrus-' . $v['id']] = array_merge($v, $res['papyrus'][$v['id']]);
151
		}
149
		}
152
 
-
 
153
		// coste
150
 
154
		$coste = new MoteurRecherche_COSTE();
151
		// coste
Line 155... Line 152...
155
		foreach($coste->get(array_filter(array_keys($res['coste']), 'intval'), $q) as $v) {
152
		$coste = new MoteurRecherche_COSTE();
156
			unset($res['coste'][$v['id']]['group_id'],
153
		foreach ($coste->get(array_filter(array_keys($res['coste']), 'intval'), $q) as $v) {
157
				  $res['coste'][$v['id']]['main_id'],
154
			unset($res['coste'][$v['id']]['group_id'],
158
				  $res['coste'][$v['id']]['id']);
155
				$res['coste'][$v['id']]['main_id'],
159
			// left: weight
156
				$res['coste'][$v['id']]['id']);
160
			$docs['coste-' . $v['id']] = array_merge($v, $res['coste'][$v['id']]);
157
			$docs['coste-' . $v['id']] = array_merge($v, $res['coste'][$v['id']]);
161
		}
-
 
162
 
158
		}
163
		// nvjfl
159
 
-
 
160
		// nvjfl
Line 164... Line 161...
164
		$nvjfl = new MoteurRecherche_NVJFL();
161
		$nvjfl = new MoteurRecherche_NVJFL();
165
		foreach($nvjfl->get(array_filter(array_keys($res['nvjfl']), 'intval'), $q) as $v) {
162
		foreach ($nvjfl->get(array_filter(array_keys($res['nvjfl']), 'intval'), $q) as $v) {
166
			unset($res['nvjfl'][$v['id']]['group_id'],
-
 
167
				  $res['nvjfl'][$v['id']]['main_id'],
-
 
Line 168... Line 163...
168
				  $res['nvjfl'][$v['id']]['id']);
163
			unset($res['nvjfl'][$v['id']]['group_id'],
169
			// left: weight
164
				$res['nvjfl'][$v['id']]['main_id'],
170
			$docs['nvjfl-' . $v['id']] = array_merge($v, $res['nvjfl'][$v['id']]);
165
				$res['nvjfl'][$v['id']]['id']);
171
		}
166
			$docs['nvjfl-' . $v['id']] = array_merge($v, $res['nvjfl'][$v['id']]);
172
 
167
		}
Line 173... Line 168...
173
		// sort
168
		//die('<pre>'.print_r($docs, true).'</pre>');
174
		$sorted = _sortArrayByArray($docs, $ids_par_poids);
169
 
175
		$max = current($sorted);
170
		// sort
176
		$max = $max['weight'];
171
		$sorted = _sortArrayByArray($docs, $ids_par_poids);
Line 364... Line 359...
364
 
359
 
365
function _actuNewerFirst($a,$b) {
360
function _actuNewerFirst($a,$b) {
366
	return isset($a['date_creation']) && isset($b['date_creation']) ? strcmp($b['date_creation'], $a['date_creation']) : 0;
361
	return isset($a['date_creation']) && isset($b['date_creation']) ? strcmp($b['date_creation'], $a['date_creation']) : 0;
Line 367... Line 362...
367
}
362
}
368
 
363
 
369
// adaption aux templates existants: [score] => [weight]
364
// Transforme un score en pourcentage
370
function _weight2score(&$item, $key, $max) {
365
function _weight2score(&$item, $key, $max) {
371
	$item['score'] = intval($item['weight'] / $max * 100);
366
	$item['score'] = intval($item['poids'] / $max * 100);
372
	$item['date_creation'] = isset($item['date_creation']) ? strftime("%d %B %Y", strtotime($item['date_creation'])) : '';
367
	$item['date_creation'] = isset($item['date_creation']) ? strftime("%d %B %Y", strtotime($item['date_creation'])) : '';
Line 373... Line 368...
373
	unset($item['weight']);
368
	unset($item['poids']);