fix: strictly penalize pure mahkumiyet onamasi decisions on beraat search and extract beraat passages

This commit is contained in:
mstfyldz
2026-08-14 12:15:46 +03:00
parent 8ae98a9500
commit 644d5f4052
+38 -14
View File
@@ -67,35 +67,59 @@ SADECE anahtar kelimeleri aralarına boşluk koyarak yaz. Noktalama işareti, a
if (Array.isArray(rawItems) && rawItems.length > 0) { if (Array.isArray(rawItems) && rawItems.length > 0) {
const searchTerms = phrase.toLowerCase().split(/\s+/).filter(Boolean); const searchTerms = phrase.toLowerCase().split(/\s+/).filter(Boolean);
const outcomeTerms = ['beraat', 'mahkumiyet', 'bozma', 'onanma', 'tazminat', 'tahliye', 'kabul', 'red', 'ispat', 'zamanaşımı']; const isBeraatSearch = searchTerms.some(t => t.includes('beraat'));
const targetOutcomes = searchTerms.filter((t: string) => outcomeTerms.some(o => t.includes(o))); const isBozmaSearch = searchTerms.some(t => t.includes('bozma') || t.includes('bozulması'));
const scoredItems = rawItems.map((item: any) => { const scoredItems = rawItems.map((item: any) => {
const text = (item.ozet || item.kararMetni || item.summary || item.content || item.title || item.konu || item.birimAdi || '').toLowerCase(); const fullText = (
item.ozet || item.kararMetni || item.summary || item.content || item.title || item.konu || item.birimAdi || ''
);
const lowerText = fullText.toLowerCase();
let baseScore = 70; let baseScore = 70;
// 1. Arama terimlerinin metindeki kapsama oranı // 1. Arama terimlerinin metindeki kapsama oranı
const matchCount = searchTerms.filter((term: string) => text.includes(term)).length; const matchCount = searchTerms.filter((term: string) => lowerText.includes(term)).length;
const matchRatio = searchTerms.length > 0 ? matchCount / searchTerms.length : 1; const matchRatio = searchTerms.length > 0 ? matchCount / searchTerms.length : 1;
baseScore += Math.round(matchRatio * 15); baseScore += Math.round(matchRatio * 15);
// 2. Kullanıcının aradığı net netice/karar türü terimleri var mı? (Örn. beraat) // 2. Beraat araması için özel akıbet analizi ve filtreleme
if (targetOutcomes.length > 0) { if (isBeraatSearch) {
const hasTargetOutcome = targetOutcomes.some((outcome: string) => text.includes(outcome)); const hasExplicitBeraat = lowerText.includes('beraat') || lowerText.includes('beraatına') || lowerText.includes('beraatine') || lowerText.includes('beraat kararı');
if (hasTargetOutcome) { const isBeraatOnamasi = lowerText.includes('beraatına ilişkin') || lowerText.includes('beraatine ilişkin') || lowerText.includes('beraat hükmünün');
baseScore += 18; const isPureMahkumiyetOnama = (lowerText.includes('mahkumiyetine') || lowerText.includes('mahkûmiyetine')) && (lowerText.includes('onanmasına') || lowerText.includes('itirazın reddine'));
} else {
baseScore -= 25; // Eğer beraat arayıp kararda beraat geçmiyorsa (örn sadece onanması varsa) sırayı düşür if (hasExplicitBeraat || isBeraatOnamasi) {
baseScore += 30; // Gerçek beraat içeren kararlar en üste
}
if (isPureMahkumiyetOnama && !hasExplicitBeraat) {
baseScore -= 45; // Mahkumiyet onaması olup beraat içermeyenleri dibe düşür
} }
} }
// Skor 45 - 98 arasında sınırlandırılır // 3. Bozma araması için özel analiz
const finalScore = Math.max(45, Math.min(98, baseScore)); if (isBozmaSearch) {
if (lowerText.includes('bozulmasına') || lowerText.includes('bozma')) {
baseScore += 25;
} else if (lowerText.includes('onanmasına')) {
baseScore -= 30;
}
}
// 4. Pasaj (Özet) Cımbızlama: Aranan netice cümlesini tam ortalayarak özet yap
const keyTarget = isBeraatSearch ? 'beraat' : (isBozmaSearch ? 'bozulmasına' : searchTerms[0]);
if (keyTarget && lowerText.includes(keyTarget)) {
const idx = lowerText.indexOf(keyTarget);
const start = Math.max(0, idx - 90);
const end = Math.min(fullText.length, idx + 150);
item.ozet = '...' + fullText.slice(start, end).trim() + '...';
}
const finalScore = Math.max(30, Math.min(98, baseScore));
return { ...item, relevanceScore: finalScore, score: finalScore }; return { ...item, relevanceScore: finalScore, score: finalScore };
}); });
// En yüksek alakaya göre yeniden sırala // En yüksek beraat/netice eşleşmesine göre yeniden sırala
scoredItems.sort((a: any, b: any) => b.relevanceScore - a.relevanceScore); scoredItems.sort((a: any, b: any) => b.relevanceScore - a.relevanceScore);
if (data.results) data.results = scoredItems; if (data.results) data.results = scoredItems;