kan_ve_gul
Yeni Üye
1. Gerekli Ortam
- LAMP (Linux + Apache + MySQL + PHP 8)
- Web sunucusunda
mod_rewriteetkin - PHP’de
pdo_mysqleklentisi enabled
2. Veri Toplama
- Etkinlik tablosu oluşturma
SQL:CREATE TABLE user_events ( id BIGINT AUTO_INCREMENT PRIMARY KEY, user_id BIGINT NOT NULL, product_id BIGINT NOT NULL, event_type ENUM('view','add_cart','purchase') NOT NULL, event_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); - HTML/JS ile izleme
Sayfa tetiklerindeHTML:<script> function trackEvent(type, productId) { fetch('/track', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({type, productId}) }); } </script>trackEvent('view', 123)gibi çağrılar yapılır.
3. Öneri Algoritması – Basit Ürün‑Ürün Benzerliği
- Oluşturulması
PHP:$stmt = $pdo->prepare( "SELECT a.product_id, b.product_id, COUNT(*) AS weight FROM user_events a JOIN user_events b ON a.user_id = b.user_id WHERE a.event_type = 'view' AND b.event_type = 'view' AND a.product_id <> b.product_id GROUP BY a.product_id, b.product_id ORDER BY weight DESC" ); - Cache
- Sonuçları Redis veya OPcache ile 5 dk süreyle saklayın.
4. API Entegrasyonu
/api/recommend.phpdosyası oluşturun.
PHP:<?php header('Content-Type: application/json'); $userId = $_GET['user_id']; $stmt = $pdo->prepare( "SELECT product_id FROM recommendation_cache WHERE user_id = ? ORDER BY score DESC LIMIT 10" ); $stmt->execute([$userId]); echo json_encode($stmt->fetchAll(PDO::FETCH_COLUMN));- Önemli: CORS başlıklarını ekleyin.
5. Güncelleme İşlemi
cronile haftada birphp update_recommendations.phpçalıştırın.- Bu script, 3. adımda tanımlanan sorguyu yeniden çalıştırıp
recommendation_cachetablosunu günceller.
6. Yayın Öncesi Kontroller
| Adım | Kontrol | Açıklama |
|---|---|---|
| 1 | Veritabanı bağlantısı | PDO hatası var mı? |
| 2 | JavaScript izleme | Konsolda fetch hatası var mı? |
| 3 | Cache boş mu? | Öğrenme verisi oluşturulmalı |
| 4 | API yanıtı | 200 OK ve JSON döndürmeli |
Bu yapı, e‑ticaret sitenizde gerçek zamanlı ve tutarlı öneriler sunmanıza olanak tanır.
Peki, hangi veri kümenizin öneri doğruluğunu artıracağını düşünüyorsunuz?
Support Pollinations.AI:
Powered by Pollinations.AI free text APIs. Support our mission to keep AI accessible for everyone.