From 9330ad4838cdab780fae8f0d67203e987a9b1034 Mon Sep 17 00:00:00 2001 From: Michael Peter Christen Date: Fri, 2 Nov 2012 01:22:31 +0100 Subject: [PATCH] - fixed the delete option in host browser - added a delete method which can be used to delete a full subpath in solr. --- htroot/HostBrowser.java | 5 ++- source/net/yacy/search/index/Fulltext.java | 52 +++++++++++++++++++--- 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/htroot/HostBrowser.java b/htroot/HostBrowser.java index c13ba3ae0..15adf415b 100644 --- a/htroot/HostBrowser.java +++ b/htroot/HostBrowser.java @@ -166,8 +166,9 @@ public class HostBrowser { if (p < 8) { prop.put("files_root", 1); } else { + path = path.substring(0, p + 1); prop.put("files_root", 0); - prop.put("files_root_path", path.substring(0, p + 1)); + prop.put("files_root_path", path); } try { // generate file list from path @@ -221,7 +222,7 @@ public class HostBrowser { } catch (MalformedURLException e) {} } } - if (deleteIDs.size() > 0) sb.index.fulltext().removeConcurrently(deleteIDs); + if (deleteIDs.size() > 0) sb.index.fulltext().remove(deleteIDs, true); // now combine both lists into one Map files = new HashMap(); diff --git a/source/net/yacy/search/index/Fulltext.java b/source/net/yacy/search/index/Fulltext.java index cf6ab1a8b..37915de39 100644 --- a/source/net/yacy/search/index/Fulltext.java +++ b/source/net/yacy/search/index/Fulltext.java @@ -27,6 +27,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintWriter; +import java.net.MalformedURLException; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; @@ -34,11 +35,13 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.TreeSet; +import java.util.concurrent.BlockingQueue; import net.yacy.cora.date.GenericFormatter; import net.yacy.cora.document.ASCII; import net.yacy.cora.document.MultiProtocolURI; import net.yacy.cora.federate.solr.YaCySchema; +import net.yacy.cora.federate.solr.connector.AbstractSolrConnector; import net.yacy.cora.federate.solr.connector.EmbeddedSolrConnector; import net.yacy.cora.federate.solr.connector.MirrorSolrConnector; import net.yacy.cora.federate.solr.connector.SolrConnector; @@ -295,11 +298,50 @@ public final class Fulltext implements Iterable { if (MemoryControl.shortStatus()) clearCache(); } - public void removeConcurrently(final List deleteIDs) { - new Thread() { - public void run() {for (byte[] id: deleteIDs) {remove(id);}} - }.start(); - this.solr.commit(); + /** + * remove a full subpath from the index + * @param subpath the left path of the url; at least until the end of the host + * @param concurrently if true, then the method returnes immediately and runs concurrently + */ + public void remove(String subpath, final boolean concurrently) { + int p = subpath.substring(0, subpath.length() - 1).lastIndexOf('/'); + final String path = p > 8 ? subpath.substring(0, p + 1) : subpath; + DigestURI uri; + try {uri = new DigestURI(path);} catch (MalformedURLException e) {return;} + final String host = uri.getHost(); + Thread t = new Thread(){ + public void run() { + final BlockingQueue docs = getSolr().concurrentQuery(YaCySchema.host_s.name() + ":" + host, 0, 100000, 60000); + try { + SolrDocument doc; + boolean removed = false; + while ((doc = docs.take()) != AbstractSolrConnector.POISON_DOCUMENT) { + String u = (String) doc.getFieldValue(YaCySchema.sku.getSolrFieldName()); + if (u.startsWith(path)) { + remove(ASCII.getBytes((String) doc.getFieldValue(YaCySchema.id.name()))); + removed = true; + } + } + if (removed) Fulltext.this.solr.commit(); + } catch (InterruptedException e) {} + } + }; + if (concurrently) t.start(); else t.run(); + } + + /** + * remove a list of id's from the index + * @param deleteIDs a list of urlhashes; each denoting a document + * @param concurrently if true, then the method returnes immediately and runs concurrently + */ + public void remove(final List deleteIDs, final boolean concurrently) { + Thread t = new Thread() { + public void run() { + for (byte[] id: deleteIDs) {remove(id);} + Fulltext.this.solr.commit(); + } + }; + if (concurrently) t.start(); else t.run(); } public boolean remove(final byte[] urlHash) {