From f31ad84d98dfa3d4a1af959f5efee34fe2457c2f Mon Sep 17 00:00:00 2001 From: Michael Peter Christen Date: Tue, 17 Apr 2012 11:22:19 +0200 Subject: [PATCH] automatic generation of blacklist pattern, see http://forum.yacy-websuche.de/viewtopic.php?f=5&t=2685&p=25305#p25305 --- htroot/Blacklist_p.java | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/htroot/Blacklist_p.java b/htroot/Blacklist_p.java index b466fcc5e..0476e00d3 100644 --- a/htroot/Blacklist_p.java +++ b/htroot/Blacklist_p.java @@ -636,12 +636,30 @@ public class Blacklist_p { newEntry = newEntry.substring(8); } - int pos = newEntry.indexOf('/',0); - if (pos < 0) { - // add default empty path pattern - pos = newEntry.length(); - newEntry = newEntry + "/.*"; + if (newEntry.indexOf("*") < 0) { + // user did not use any wild cards and just submitted a word + + addBlacklistEntry0(listsPath, blacklistToUse, ".*" + newEntry + ".*/.*", supportedBlacklistTypes); + addBlacklistEntry0(listsPath, blacklistToUse, ".*.*/.*" + newEntry + ".*", supportedBlacklistTypes); + + } else { + + int pos = newEntry.indexOf('/',0); + if (pos < 0) { + // add default empty path pattern + pos = newEntry.length(); + newEntry = newEntry + "/.*"; + } + + addBlacklistEntry0(listsPath, blacklistToUse, newEntry, supportedBlacklistTypes); } + } + + private static void addBlacklistEntry0( + final File listsPath, + final String blacklistToUse, + String newEntry, + final String[] supportedBlacklistTypes) { if (!Blacklist.blacklistFileContains(listsPath, blacklistToUse, newEntry)) { // append the line to the file @@ -664,6 +682,7 @@ public class Blacklist_p { } // add to blacklist + int pos = newEntry.indexOf('/',0); for (final String supportedBlacklistType : supportedBlacklistTypes) { if (ListManager.listSetContains(supportedBlacklistType + ".BlackLists", blacklistToUse)) { Switchboard.urlBlacklist.add(supportedBlacklistType, newEntry.substring(0, pos), newEntry.substring(pos + 1));