Subversion Repositories Applications.papyrus

Rev

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

Rev 2117 Rev 2123
Line 178... Line 178...
178
		}
178
		}
179
		return $content;		
179
		return $content;		
180
	}
180
	}
181
}
181
}
Line -... Line 182...
-
 
182
 
-
 
183
class MoteurRecherche_NVJFL {
-
 
184
	public function get($ids, $q = NULL) {
-
 
185
		if(!$ids) return array();
-
 
186
		// DB access is dumb, let's use this one and pray
-
 
187
		$db = $GLOBALS['_MOTEUR_RECHERCHE_']['bd']['papyrus'];
-
 
188
		$req = $db->query(sprintf(<<<EOF
-
 
189
SELECT b.num_nom AS id, CONCAT(nom_sci, ' (nn: ', b.num_nom, ', nt: ', num_taxonomique, ')') AS titre, GROUP_CONCAT(n.nom_vernaculaire) AS description
-
 
190
FROM tb_eflore.bdtfx_v1_02 b
-
 
191
LEFT JOIN tb_eflore.nvjfl_v2007 n ON n.num_taxon = b.num_taxonomique
-
 
192
WHERE b.num_nom IN (%s)
-
 
193
GROUP BY n.num_taxon
-
 
194
EOF
-
 
195
								  ,
-
 
196
								  implode(',', $ids)));
-
 
197
 
-
 
198
		(DB::isError($req)) ? die($req->getMessage()) : '';
-
 
199
		$content = array();
-
 
200
		while($rec = $req->fetchRow(DB_FETCHMODE_ASSOC)) {
-
 
201
			$rec['url_simple'] = $rec['url'] = sprintf("http://%s/bdtfx-nn-%d", _MRS_SPHINX_BASEHOST, $rec['id']);
-
 
202
			$rec['description'] = substr($rec['description'], 0, 400 + 2 * MORE_RESULTAT_TAILLE_DESCRIPTION);
-
 
203
			$content[$rec['id']] = $rec;
-
 
204
		}
-
 
205
		var_dump($content);
-
 
206
		return $content;		
-
 
207
	}
-
 
208
}
Line 182... Line 209...
182
 
209
 
183
 
210
 
184
// http://stackoverflow.com/questions/348410/sort-an-array-based-on-another-array
211
// http://stackoverflow.com/questions/348410/sort-an-array-based-on-another-array
185
function _sortArrayByArray($array, $orderArray) {
212
function _sortArrayByArray($array, $orderArray) {
Line 202... Line 229...
202
 
229
 
203
function sphinx_search($q = NULL, $page = 1) {
230
function sphinx_search($q = NULL, $page = 1) {
Line 204... Line 231...
204
	if(!$q) return array();
231
	if(!$q) return array();
205
 
232
 
Line 206... Line 233...
206
	$db = mysql_connect(SPHINX_DSN, NULL, NULL, TRUE);
233
	$db = mysql_connect(SPHINX_DSN, NULL, NULL, TRUE);
207
	$req = mysql_query(sprintf("SELECT group_id, main_id FROM i_projet, i_spip, i_papyrus, i_bazar, i_coste WHERE MATCH('%s') LIMIT 50", $q), $db);
234
	$req = mysql_query(sprintf("SELECT group_id, main_id FROM i_projet, i_spip, i_papyrus, i_bazar, i_coste, i_nvjfl WHERE MATCH('%s') LIMIT 50", $q), $db);
208
 
235
 
209
	$res = array('spip' => array(), 'bazar' => array(), 'projet' => array(), 'papyrus' => array(), 'coste' => array());
236
	$res = array('spip' => array(), 'bazar' => array(), 'projet' => array(), 'papyrus' => array(), 'coste' => array());
Line 262... Line 289...
262
			  $res['coste'][$v['id']]['id']);
289
			  $res['coste'][$v['id']]['id']);
263
		// left: weight
290
		// left: weight
264
		$docs['coste-' . $v['id']] = array_merge($v, $res['coste'][$v['id']]);
291
		$docs['coste-' . $v['id']] = array_merge($v, $res['coste'][$v['id']]);
265
	}
292
	}
Line -... Line 293...
-
 
293
 
-
 
294
	// nvjfl
-
 
295
	$nvjfl = new MoteurRecherche_NVJFL();
-
 
296
	foreach($nvjfl->get(array_filter(array_keys($res['nvjfl']), 'intval'), $q) as $v) {
-
 
297
		unset($res['nvjfl'][$v['id']]['group_id'],
-
 
298
			  $res['nvjfl'][$v['id']]['main_id'],
-
 
299
			  $res['nvjfl'][$v['id']]['id']);
-
 
300
		// left: weight
-
 
301
		$docs['nvjfl-' . $v['id']] = array_merge($v, $res['nvjfl'][$v['id']]);
-
 
302
	}
266
 
303
 
Line 267... Line 304...
267
	$sorted = _sortArrayByArray($docs, $ids_par_poids);
304
	$sorted = _sortArrayByArray($docs, $ids_par_poids);
268
 
305
 
269
	// sort
306
	// sort
270
	/*
307
	/*
Line 271... Line 308...
271
	// uncomment this:
308
	// uncomment this:
272
	print_r(array_keys($sorted); die;
309
	print_r(array_keys($sorted); die;
273
 
310
 
274
	// then:
311
	// then:
Line 275... Line 312...
275
	ddiff
312
	ddiff
276
	<(mysql -h0 -P 9306 <<<"SELECT main_id FROM i_projet, i_spip, i_papyrus, i_bazar, i_coste WHERE MATCH('test') LIMIT 50;"|awk '{print $3}'|sed 1d) \
313
	<(mysql -h0 -P 9306 <<<"SELECT main_id FROM i_projet, i_spip, i_papyrus, i_bazar, i_coste, i_nvjfl WHERE MATCH('test') LIMIT 50;"|awk '{print $3}'|sed 1d) \
277
	<(POST http://localhost/site:reseau<<<"more_motif=test&"|awk -F'=>' '{print $2}'|sed -e 's/ //g' -e '/^$/d')
314
	<(POST http://localhost/site:reseau<<<"more_motif=test&"|awk -F'=>' '{print $2}'|sed -e 's/ //g' -e '/^$/d')