// built urlCache
final Iterator<WordReference> urlIter = index.entries();
final TreeMap<byte[], URIMetadataRow> knownURLs = new TreeMap<byte[], URIMetadataRow>(Base64Order.enhancedCoder);
final HandleSet unknownURLEntries = new HandleSet(WordReferenceRow.urlEntryRow.primaryKeyLength, WordReferenceRow.urlEntryRow.objectOrder, index.size());
Reference iEntry;
URIMetadataRow lurl;
while (urlIter.hasNext()) {
iEntry = urlIter.next();
lurl = segment.urlMetadata().load(iEntry.urlhash());
if (lurl == null) {
try {
unknownURLEntries.put(iEntry.urlhash());
} catch (final RowSpaceExceededException e) {
Log.logException(e);
}
urlIter.remove();
} else {
knownURLs.put(iEntry.urlhash(), lurl);
}
}
// make an indexContainerCache
final ReferenceContainerCache<WordReference> icc = new ReferenceContainerCache<WordReference>(Segment.wordReferenceFactory, Segment.wordOrder, Word.commonHashLength);
try {
icc.add(index);
} catch (final RowSpaceExceededException e) {
Log.logException(e);
}
// transport to other peer
final boolean gzipBody = sb.getConfigBool("indexControl.gzipBody", false);
final int timeout = (int) sb.getConfigLong("indexControl.timeout", 60000);
final String error = yacyClient.transferIndex(
seed,
icc,
knownURLs,
gzipBody,
timeout);
prop.put("result", (error == null) ? ("Successfully transferred " + knownURLs.size() + " words in " + ((System.currentTimeMillis() - starttime) / 1000) + " seconds, " + unknownURLEntries.size() + " URL not found") : "error: " + error);
index = null;
} catch (final IOException e) {
Log.logException(e);
}
// generate list
if (post.containsKey("keyhashsimilar")) try {
final Iterator<ReferenceContainer<WordReference>> containerIt = segment.termIndex().references(keyhash, true, 256, false).iterator();
ReferenceContainer<WordReference> container;
i = 0;
int rows = 0, cols = 0;
prop.put("keyhashsimilar", "1");
while (containerIt.hasNext() && i < 256) {
container = containerIt.next();
prop.put("keyhashsimilar_rows_"+rows+"_cols_"+cols+"_wordHash", container.getTermHash());
cols++;
if (cols==8) {
prop.put("keyhashsimilar_rows_"+rows+"_cols", cols);
cols = 0;
rows++;
}
i++;
}
prop.put("keyhashsimilar_rows_"+rows+"_cols", cols);
prop.put("keyhashsimilar_rows", rows + 1);
prop.put("result", "");
} catch (final IOException e) {
Log.logException(e);
}
if (post.containsKey("blacklist")) {
final String blacklist = post.get("blacklist", "");
final HandleSet urlHashes = new HandleSet(URIMetadataRow.rowdef.primaryKeyLength, URIMetadataRow.rowdef.objectOrder, urlb.size());
if (post.containsKey("blacklisturls")) {
PrintWriter pw;
try {
final String[] supportedBlacklistTypes = env.getConfig("BlackLists.types", "").split(",");
pw = new PrintWriter(new FileWriter(new File(ListManager.listsPath, blacklist), true));
DigestURI url;
for (final byte[] b: urlb) {
try {
urlHashes.put(b);
} catch (final RowSpaceExceededException e) {
Log.logException(e);
}
final URIMetadataRow e = segment.urlMetadata().load(b);
segment.urlMetadata().remove(b);
if (e != null) {
url = e.metadata().url();
pw.println(url.getHost() + "/" + url.getFile());
for (final String supportedBlacklistType : supportedBlacklistTypes) {
if (ListManager.listSetContains(supportedBlacklistType + ".BlackLists", blacklist)) {
Switchboard.urlBlacklist.add(
supportedBlacklistType,
url.getHost(),
url.getFile());
}
}
SearchEventCache.cleanupEvents(true);
}
}
pw.close();
} catch (final IOException e) {
}
}
if (post.containsKey("blacklistdomains")) {
PrintWriter pw;
try {
final String[] supportedBlacklistTypes = Blacklist.BLACKLIST_TYPES_STRING.split(",");
pw = new PrintWriter(new FileWriter(new File(ListManager.listsPath, blacklist), true));
DigestURI url;
for (final byte[] b: urlb) {
try {
urlHashes.put(b);
} catch (final RowSpaceExceededException e) {
Log.logException(e);
}
final URIMetadataRow e = segment.urlMetadata().load(b);
segment.urlMetadata().remove(b);
if (e != null) {
url = e.metadata().url();
pw.println(url.getHost() + "/.*");
for (final String supportedBlacklistType : supportedBlacklistTypes) {
if (ListManager.listSetContains(supportedBlacklistType + ".BlackLists", blacklist)) {
Switchboard.urlBlacklist.add(
supportedBlacklistType,