From 139810d50416e03f4275e5618fb771c3d89ccce6 Mon Sep 17 00:00:00 2001 From: karlchenofhell Date: Wed, 17 Jan 2007 23:45:53 +0000 Subject: [PATCH] - truncate attributes of new newsRecords if too long git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3239 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/yacy/yacyNewsRecord.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/source/de/anomic/yacy/yacyNewsRecord.java b/source/de/anomic/yacy/yacyNewsRecord.java index 23c8e2f79..9e177d902 100644 --- a/source/de/anomic/yacy/yacyNewsRecord.java +++ b/source/de/anomic/yacy/yacyNewsRecord.java @@ -88,6 +88,7 @@ public class yacyNewsRecord { this.distributed = (attributes.containsKey("dis")) ? Integer.parseInt((String) attributes.get("dis")) : 0; this.originator = (attributes.containsKey("ori")) ? (String) attributes.get("ori") : ""; removeStandards(); + } public yacyNewsRecord(String category, Map attributes) { @@ -99,6 +100,7 @@ public class yacyNewsRecord { this.distributed = 0; this.originator = yacyCore.seedDB.mySeed.hash; removeStandards(); + truncAttrLengthToMax(); } protected yacyNewsRecord(String id, String category, Date received, int distributed, Map attributes) { @@ -109,6 +111,7 @@ public class yacyNewsRecord { this.distributed = distributed; this.originator = id.substring(yacyCore.universalDateShortPattern.length()); removeStandards(); + truncAttrLengthToMax(); } private void removeStandards() { @@ -118,7 +121,14 @@ public class yacyNewsRecord { attributes.remove("rec"); attributes.remove("dis"); } - + + private void truncAttrLengthToMax() { + String s = this.attributes.toString(); + if (s.length() <= attributesMaxLength) return; + this.attributes = serverCodings.string2map( + s.substring(0, s.lastIndexOf(',', attributesMaxLength)), ","); + } + public String toString() { // this creates the string that shall be distributed // attention: this has no additional encoding