RECHERCHE INTELLIGENTE ULTRA TENDANCE VX
// ai-search.js async function intelligentSearch(query, db) { const q = query .toLowerCase() .trim() .split(/\s+/); // Recherche classique dans ta base const results = await db.query(` SELECT id, name, description, category, keywords, views, clicks, created_at FROM items WHERE LOWER(name) LIKE ANY($1) OR LOWER(description) LIKE ANY($1) OR LOWER(category) LIKE ANY($1) OR LOWER(keywords) LIKE ANY($1) `, [ q.map(word => `%${word}%`) ]); const now = Date.now(); return results.rows .map(item => { // Popularité const popularity = Math.log(1 + item.views) * 0.6 + Math.log(1 + item.clicks) * 0.4; // Nouveauté const age = (now - new Date(item.created_at).getTime()) / (1000 * 60 * 60 * 24); const freshness = Math.max( 0, 1 - age / 365 ); // Correspondance des mots const text = ` ${item.name} ${item.description} ${item.category} ${item.keywords} `.toLowerCase(); const matches = q.filter(word => text.includes(word) ).length; const relevance = matches / Math.max(q.length, 1); // Score final const score = relevance * 0.50 + Math.min(popularity / 20, 1) * 0.20 + freshness * 0.10; return { ...item, ai_score: Number(score.toFixed(4)) }; }) .sort((a, b) => b.ai_score - a.ai_score); }
7 625 597 484 987 COMBINAISON POSSIBLES