Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
more refactoring
orbiter83792d9233a7
diff --git a/htroot/IndexControlRWIs_p.java b/htroot/IndexControlRWIs_p.javaindex d665199d8..1bb1e4d9b 100644--- a/htroot/IndexControlRWIs_p.java+++ b/htroot/IndexControlRWIs_p.java@@ -48,6 +48,7 @@ import de.anomic.plasma.plasmaSearchAPI;import de.anomic.plasma.plasmaSearchEvent;import de.anomic.plasma.plasmaSearchRankingProcess;import de.anomic.plasma.plasmaSwitchboard;+import de.anomic.plasma.plasmaWordIndex;import de.anomic.server.serverObjects;import de.anomic.server.serverSwitch;import de.anomic.yacy.yacyClient;@@ -124,7 +125,7 @@ public class IndexControlRWIs_p {if (delurl || delurlref) {// generate an urlx arrayReferenceContainer index = null;- index = sb.webIndex.index().getReferences(keyhash, null);+ index = sb.webIndex.index().get(keyhash, null);final Iterator<ReferenceRow> en = index.entries();int i = 0;urlx = new String[index.size()];@@ -141,7 +142,7 @@ public class IndexControlRWIs_p {sb.urlRemove(urlx[i]);}}- sb.webIndex.index().deleteAllReferences(keyhash);+ sb.webIndex.index().delete(keyhash);post.remove("keyhashdeleteall");post.put("urllist", "generated");} catch (IOException e) {@@ -160,7 +161,7 @@ public class IndexControlRWIs_p {}final Set<String> urlHashes = new HashSet<String>();for (int i = 0; i < urlx.length; i++) urlHashes.add(urlx[i]);- sb.webIndex.index().removeReferences(keyhash, urlHashes);+ sb.webIndex.index().remove(keyhash, urlHashes);// this shall lead to a presentation of the list; so handle that the remaining program// thinks that it was called for a list presentationpost.remove("keyhashdelete");@@ -204,7 +205,7 @@ public class IndexControlRWIs_p {// prepare indexReferenceContainer index;final long starttime = System.currentTimeMillis();- index = sb.webIndex.index().getReferences(keyhash, null);+ index = sb.webIndex.index().get(keyhash, null);// built urlCachefinal Iterator<ReferenceRow> urlIter = index.entries();final HashMap<String, MetadataRowContainer> knownURLs = new HashMap<String, MetadataRowContainer>();@@ -223,8 +224,8 @@ public class IndexControlRWIs_p {}// make an indexContainerCache- ReferenceContainerCache icc = new ReferenceContainerCache(index.rowdef);- icc.addReferences(index);+ ReferenceContainerCache icc = new ReferenceContainerCache(index.rowdef, plasmaWordIndex.wordOrder);+ icc.add(index);// transport to other peerfinal String gzipBody = sb.getConfig("indexControl.gzipBody","false");@@ -242,8 +243,8 @@ public class IndexControlRWIs_p {}// generate list- if (post.containsKey("keyhashsimilar")) {- final Iterator<ReferenceContainer> containerIt = sb.webIndex.index().indexContainerSet(keyhash, false, true, 256).iterator();+ if (post.containsKey("keyhashsimilar")) try {+ final Iterator<ReferenceContainer> containerIt = sb.webIndex.index().references(keyhash, true, 256, false).iterator();ReferenceContainer container;int i = 0;int rows = 0, cols = 0;@@ -262,6 +263,8 @@ public class IndexControlRWIs_p {prop.put("keyhashsimilar_rows_"+rows+"_cols", cols);prop.put("keyhashsimilar_rows", rows + 1);prop.put("result", "");+ } catch (IOException e) {+ e.printStackTrace();}if (post.containsKey("blacklist")) {@@ -322,7 +325,7 @@ public class IndexControlRWIs_p {}}try {- sb.webIndex.index().removeReferences(keyhash, urlHashes);+ sb.webIndex.index().remove(keyhash, urlHashes);} catch (IOException e) {e.printStackTrace();}diff --git a/htroot/PerformanceGraph.java b/htroot/PerformanceGraph.javaindex ff1556e0a..9b72660ff 100644--- a/htroot/PerformanceGraph.java+++ b/htroot/PerformanceGraph.java@@ -41,7 +41,7 @@ public class PerformanceGraph {final int width = post.getInt("width", 660);final int height = post.getInt("height", 240);- return plasmaProfiling.performanceGraph(width, height, sb.webIndex.metadata().size() + " URLS / " + sb.webIndex.index().backendSize() + " WORDS IN COLLECTIONS / " + sb.webIndex.index().cacheSize() + " WORDS IN CACHE");+ return plasmaProfiling.performanceGraph(width, height, sb.webIndex.metadata().size() + " URLS / " + sb.webIndex.index().getBackendSize() + " WORDS IN COLLECTIONS / " + sb.webIndex.index().getBufferSize() + " WORDS IN CACHE");}}\ No newline at end of filediff --git a/htroot/PerformanceQueues_p.java b/htroot/PerformanceQueues_p.javaindex 6897c3b90..5332a7aa1 100644--- a/htroot/PerformanceQueues_p.java+++ b/htroot/PerformanceQueues_p.java@@ -229,7 +229,7 @@ public class PerformanceQueues_p {if ((post != null) && (post.containsKey("cacheSizeSubmit"))) {final int wordCacheMaxCount = post.getInt("wordCacheMaxCount", 20000);switchboard.setConfig(plasmaSwitchboardConstants.WORDCACHE_MAX_COUNT, Integer.toString(wordCacheMaxCount));- switchboard.webIndex.index().setMaxWordCount(wordCacheMaxCount);+ switchboard.webIndex.index().setBufferMaxWordCount(wordCacheMaxCount);final int wordCacheInitCount = post.getInt(plasmaSwitchboardConstants.WORDCACHE_INIT_COUNT, 30000);switchboard.setConfig(plasmaSwitchboardConstants.WORDCACHE_INIT_COUNT, Integer.toString(wordCacheInitCount));@@ -288,11 +288,11 @@ public class PerformanceQueues_p {// table cache settingsprop.putNum("urlCacheSize", switchboard.webIndex.metadata().writeCacheSize());- prop.putNum("wordCacheSize", switchboard.webIndex.index().indexCacheSize());- prop.putNum("wordCacheSizeKBytes", switchboard.webIndex.index().indexCacheSizeBytes()/1024);- prop.putNum("maxURLinCache", switchboard.webIndex.index().maxURLinCache());- prop.putNum("maxAgeOfCache", switchboard.webIndex.index().maxAgeOfCache() / 1000 / 60); // minutes- prop.putNum("minAgeOfCache", switchboard.webIndex.index().minAgeOfCache() / 1000 / 60); // minutes+ prop.putNum("wordCacheSize", switchboard.webIndex.index().getBufferSize());+ prop.putNum("wordCacheSizeKBytes", switchboard.webIndex.index().getBufferSizeBytes()/1024);+ prop.putNum("maxURLinCache", switchboard.webIndex.index().getBufferMaxReferences());+ prop.putNum("maxAgeOfCache", switchboard.webIndex.index().getBufferMaxAge() / 1000 / 60); // minutes+ prop.putNum("minAgeOfCache", switchboard.webIndex.index().getBufferMinAge() / 1000 / 60); // minutesprop.putNum("maxWaitingWordFlush", switchboard.getConfigLong("maxWaitingWordFlush", 180));prop.put("wordCacheMaxCount", switchboard.getConfigLong(plasmaSwitchboardConstants.WORDCACHE_MAX_COUNT, 20000));prop.put("wordCacheInitCount", switchboard.getConfigLong(plasmaSwitchboardConstants.WORDCACHE_INIT_COUNT, 30000));diff --git a/htroot/api/status_p.java b/htroot/api/status_p.javaindex 437fd9188..c55fdd406 100644--- a/htroot/api/status_p.java+++ b/htroot/api/status_p.java@@ -21,11 +21,11 @@ public class status_p {prop.setLocalized(false);prop.put("rejected", "0");sb.updateMySeed();- final int cacheSize = sb.webIndex.index().indexCacheSize();+ final int cacheSize = sb.webIndex.index().getBufferSize();final long cacheMaxSize = sb.getConfigLong(plasmaSwitchboardConstants.WORDCACHE_MAX_COUNT, 10000);prop.putNum("ppm", sb.currentPPM());prop.putNum("qpm", sb.webIndex.peers().mySeed().getQPM());- prop.putNum("wordCacheSize", sb.webIndex.index().indexCacheSize());+ prop.putNum("wordCacheSize", sb.webIndex.index().getBufferSize());prop.putNum("wordCacheSize", cacheSize);prop.putNum("wordCacheMaxSize", cacheMaxSize);prop.put("wordCacheCount", cacheSize);diff --git a/htroot/api/timeline.java b/htroot/api/timeline.javaindex f73b499c5..6dc39bd05 100644--- a/htroot/api/timeline.java+++ b/htroot/api/timeline.java@@ -78,7 +78,7 @@ public final class timeline {yacyCore.log.logInfo("INIT TIMELINE SEARCH: " + plasmaSearchQuery.anonymizedQueryHashes(query[0]) + " - " + count + " links");// get the index container with the result vector- HashMap<String, ReferenceContainer>[] localSearchContainerMaps = sb.webIndex.index().localSearchContainers(query[0], query[1], null);+ HashMap<String, ReferenceContainer>[] localSearchContainerMaps = sb.webIndex.localSearchContainers(query[0], query[1], null);final ReferenceContainer index =ReferenceContainer.joinExcludeContainers(localSearchContainerMaps[0].values(),diff --git a/htroot/yacy/query.java b/htroot/yacy/query.javaindex f1be181b1..6755fd8ad 100644--- a/htroot/yacy/query.java+++ b/htroot/yacy/query.java@@ -84,7 +84,7 @@ public final class query {if (obj.equals("rwiurlcount")) try {// the total number of different urls in the rwi is returned// <env> shall contain a word hash, the number of assigned lurls to this hash is returned- prop.put("response", sb.webIndex.index().getReferences(env, null).size());+ prop.put("response", sb.webIndex.index().get(env, null).size());return prop;} catch (IOException e) {e.printStackTrace();diff --git a/htroot/yacy/search.java b/htroot/yacy/search.javaindex 4853ff31f..5102112f3 100644--- a/htroot/yacy/search.java+++ b/htroot/yacy/search.java@@ -185,7 +185,7 @@ public final class search {yacyCore.log.logInfo("INIT HASH SEARCH (abstracts only): " + plasmaSearchQuery.anonymizedQueryHashes(theQuery.queryHashes) + " - " + theQuery.displayResults() + " links");final long timer = System.currentTimeMillis();- final Map<String, ReferenceContainer>[] containers = sb.webIndex.index().localSearchContainers(theQuery.queryHashes, theQuery.excludeHashes, plasmaSearchQuery.hashes2Set(urls));+ final Map<String, ReferenceContainer>[] containers = sb.webIndex.localSearchContainers(theQuery.queryHashes, theQuery.excludeHashes, plasmaSearchQuery.hashes2Set(urls));serverProfiling.update("SEARCH", new plasmaProfiling.searchEvent(theQuery.id(true), plasmaSearchEvent.COLLECTION, containers[0].size(), System.currentTimeMillis() - timer), false);if (containers != null) {diff --git a/htroot/yacy/transferRWI.java b/htroot/yacy/transferRWI.javaindex bee64d17d..60b1c209b 100644--- a/htroot/yacy/transferRWI.java+++ b/htroot/yacy/transferRWI.java@@ -101,9 +101,9 @@ public final class transferRWI {sb.getLog().logInfo("Rejecting RWIs from peer " + otherPeerName + ". Not granted.");result = "not_granted";pause = 0;- } else if (sb.webIndex.index().indexCacheSize() > cachelimit) {+ } else if (sb.webIndex.index().getBufferSize() > cachelimit) {// we are too busy to receive indexes- sb.getLog().logInfo("Rejecting RWIs from peer " + otherPeerName + ". We are too busy (buffersize=" + sb.webIndex.index().indexCacheSize() + ").");+ sb.getLog().logInfo("Rejecting RWIs from peer " + otherPeerName + ". We are too busy (buffersize=" + sb.webIndex.index().getBufferSize() + ").");granted = false; // don't accept more words if there are too many words to flushresult = "busy";pause = 60000;@@ -159,7 +159,7 @@ public final class transferRWI {// learn entrytry {- sb.webIndex.index().addReference(wordHash, iEntry);+ sb.webIndex.index().add(wordHash, iEntry);} catch (IOException e) {e.printStackTrace();}@@ -198,7 +198,7 @@ public final class transferRWI {}result = "ok";- pause = (int) (sb.webIndex.index().indexCacheSize() * 20000 / sb.getConfigLong(plasmaSwitchboardConstants.WORDCACHE_MAX_COUNT, 100000)); // estimation of necessary pause time+ pause = (int) (sb.webIndex.index().getBufferSize() * 20000 / sb.getConfigLong(plasmaSwitchboardConstants.WORDCACHE_MAX_COUNT, 100000)); // estimation of necessary pause time}prop.put("unknownURL", unknownURLs.toString());diff --git a/htroot/yacysearch.java b/htroot/yacysearch.javaindex 2f8aedd5e..a1e4b9413 100644--- a/htroot/yacysearch.java+++ b/htroot/yacysearch.java@@ -316,7 +316,7 @@ public class yacysearch {// delete the index entry locallyfinal String delHash = post.get("deleteref", ""); // urlhash- sb.webIndex.index().removeEntryMultiple(Word.words2hashes(query[0]), delHash);+ sb.webIndex.index().remove(Word.words2hashes(query[0]), delHash);// make new news message with negative votingfinal HashMap<String, String> map = new HashMap<String, String>();diff --git a/source/de/anomic/kelondro/table/EcoTable.java b/source/de/anomic/kelondro/table/EcoTable.javaindex 53169f478..cec6b03e9 100644--- a/source/de/anomic/kelondro/table/EcoTable.java+++ b/source/de/anomic/kelondro/table/EcoTable.java@@ -74,13 +74,13 @@ public class EcoTable implements ObjectIndex {public static final long maxarraylength = 134217727L; // that may be the maxmimum size of array length in some JVMsprivate static final long minmemremaining = 20 * 1024 * 1024; // if less than this memory is remaininig, the memory copy of a table is abandoned- RowSet table;- IntegerHandleIndex index;- BufferedEcoFS file;- Row rowdef;- int fail;- File tablefile;- Row taildef;+ private RowSet table;+ private IntegerHandleIndex index;+ private BufferedEcoFS file;+ private Row rowdef;+ private int fail;+ private File tablefile;+ private Row taildef;private final int buffersize;public EcoTable(final File tablefile, final Row rowdef, final int useTailCache, final int buffersize, final int initialSpace) {diff --git a/source/de/anomic/kelondro/text/AbstractBufferedIndex.java b/source/de/anomic/kelondro/text/AbstractBufferedIndex.javanew file mode 100644index 000000000..3d3ea9ed9--- /dev/null+++ b/source/de/anomic/kelondro/text/AbstractBufferedIndex.java@@ -0,0 +1,61 @@+// AbstractBufferedIndex.java+// -----------------------------+// (C) 2009 by Michael Peter Christen; [email protected], Frankfurt a. M., Germany+// first published 16.3.2009 on http://yacy.net+//+// This is a part of YaCy, a peer-to-peer based web search engine+//+// $LastChangedDate: 2006-04-02 22:40:07 +0200 (So, 02 Apr 2006) $+// $LastChangedRevision: 1986 $+// $LastChangedBy: orbiter $+//+// LICENSE+//+// This program is free software; you can redistribute it and/or modify+// it under the terms of the GNU General Public License as published by+// the Free Software Foundation; either version 2 of the License, or+// (at your option) any later version.+//+// This program is distributed in the hope that it will be useful,+// but WITHOUT ANY WARRANTY; without even the implied warranty of+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+// GNU General Public License for more details.+//+// You should have received a copy of the GNU General Public License+// along with this program; if not, write to the Free Software+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA++package de.anomic.kelondro.text;++import java.io.IOException;+import java.util.Iterator;+import java.util.TreeSet;++import de.anomic.kelondro.order.Order;++public abstract class AbstractBufferedIndex extends AbstractIndex implements BufferedIndex {++ public synchronized TreeSet<ReferenceContainer> references(final String startHash, final boolean rot, int count, boolean ram) throws IOException {+ // creates a set of indexContainers+ // this does not use the cache+ final Order<ReferenceContainer> containerOrder = new ReferenceContainerOrder(this.ordering().clone());+ containerOrder.rotate(ReferenceContainer.emptyContainer(startHash, 0));+ final TreeSet<ReferenceContainer> containers = new TreeSet<ReferenceContainer>(containerOrder);+ final Iterator<ReferenceContainer> i = references(startHash, rot, ram);+ if (ram) count = Math.min(size(), count);+ ReferenceContainer container;+ // this loop does not terminate using the i.hasNex() predicate when rot == true+ // because then the underlying iterator is a rotating iterator without termination+ // in this case a termination must be ensured with a counter+ // It must also be ensured that the counter is in/decreased every loop+ while ((count > 0) && (i.hasNext())) {+ container = i.next();+ if ((container != null) && (container.size() > 0)) {+ containers.add(container);+ }+ count--; // decrease counter even if the container was null or empty to ensure termination+ }+ return containers; // this may return less containers as demanded+ }++}diff --git a/source/de/anomic/kelondro/text/AbstractIndex.java b/source/de/anomic/kelondro/text/AbstractIndex.javaindex 908ed7555..bc04c5349 100644--- a/source/de/anomic/kelondro/text/AbstractIndex.java+++ b/source/de/anomic/kelondro/text/AbstractIndex.java@@ -30,28 +30,52 @@ package de.anomic.kelondro.text;import java.io.IOException;import java.util.Iterator;import java.util.Set;+import java.util.TreeSet;++import de.anomic.kelondro.order.Order;public abstract class AbstractIndex implements Index {- public int removeEntryMultiple(final Set<String> wordHashes, final String urlHash) throws IOException {+ public int remove(final Set<String> wordHashes, final String urlHash) throws IOException {// remove the same url hashes for multiple words// this is mainly used when correcting a index after a searchfinal Iterator<String> i = wordHashes.iterator();int c = 0;while (i.hasNext()) {- if (removeReference(i.next(), urlHash)) c++;+ if (remove(i.next(), urlHash)) c++;}return c;}- public void removeEntriesMultiple(final Set<String> wordHashes, final Set<String> urlHashes) throws IOException {+ public void remove(final Set<String> wordHashes, final Set<String> urlHashes) throws IOException {// remove the same url hashes for multiple words// this is mainly used when correcting a index after a searchfinal Iterator<String> i = wordHashes.iterator();while (i.hasNext()) {- removeReferences(i.next(), urlHashes);+ remove(i.next(), urlHashes);}}-+ public synchronized TreeSet<ReferenceContainer> references(final String startHash, final boolean rot, int count) throws IOException {+ // creates a set of indexContainers+ // this does not use the cache+ final Order<ReferenceContainer> containerOrder = new ReferenceContainerOrder(this.ordering().clone());+ containerOrder.rotate(ReferenceContainer.emptyContainer(startHash, 0));+ final TreeSet<ReferenceContainer> containers = new TreeSet<ReferenceContainer>(containerOrder);+ final Iterator<ReferenceContainer> i = references(startHash, rot);+ //if (ram) count = Math.min(size(), count);+ ReferenceContainer container;+ // this loop does not terminate using the i.hasNex() predicate when rot == true+ // because then the underlying iterator is a rotating iterator without termination+ // in this case a termination must be ensured with a counter+ // It must also be ensured that the counter is in/decreased every loop+ while ((count > 0) && (i.hasNext())) {+ container = i.next();+ if ((container != null) && (container.size() > 0)) {+ containers.add(container);+ }+ count--; // decrease counter even if the container was null or empty to ensure termination+ }+ return containers; // this may return less containers as demanded+ }}diff --git a/source/de/anomic/kelondro/text/BufferedIndex.java b/source/de/anomic/kelondro/text/BufferedIndex.javanew file mode 100644index 000000000..71fd754f4--- /dev/null+++ b/source/de/anomic/kelondro/text/BufferedIndex.java@@ -0,0 +1,124 @@+// BufferedIndex.java+// -----------------------------+// (C) 2009 by Michael Peter Christen; [email protected], Frankfurt a. M., Germany+// first published 15.3.2009 on http://yacy.net+//+// This is a part of YaCy, a peer-to-peer based web search engine+//+// $LastChangedDate: 2006-04-02 22:40:07 +0200 (So, 02 Apr 2006) $+// $LastChangedRevision: 1986 $+// $LastChangedBy: orbiter $+//+// LICENSE+//+// This program is free software; you can redistribute it and/or modify+// it under the terms of the GNU General Public License as published by+// the Free Software Foundation; either version 2 of the License, or+// (at your option) any later version.+//+// This program is distributed in the hope that it will be useful,+// but WITHOUT ANY WARRANTY; without even the implied warranty of+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+// GNU General Public License for more details.+//+// You should have received a copy of the GNU General Public License+// along with this program; if not, write to the Free Software+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA++package de.anomic.kelondro.text;++import java.io.IOException;+import java.util.TreeSet;++import de.anomic.kelondro.order.CloneableIterator;++/*+ * an IndexPackage is an integration of different index types, i.e.+ * - ReferenceContainerArray+ * - ReferenceContainerCache+ * - IndexCache (which is a wrapper of a ReferenceContainerCache)+ * - IndexCollection+ * This interface was created from the methods that are used in CachedIndexCollection+ * (which integrates IndexCache and IndexCollection)+ * and is applied to the new index integration class IndexCell+ * (which integrates ReferenceContainerArray and ReferenceContainerCache)+ * to make it possible to switch between the old and new index data structure+ */+public interface BufferedIndex extends Index {++ /*+ * methods for monitoring of the buffer+ */++ /**+ * set the size of the buffer, which can be defined with a given maximum number+ * of words that shall be stored. Because an arbitrary number of references can+ * be stored at each word entry, this does not limit the memory that the buffer+ * takes. It is possible to monitor the memory occupation of the buffer with the+ * getBufferSizeBytes() method, and then adopt the buffer size with a new word number+ * limit.+ */+ public void setBufferMaxWordCount(final int maxWords);++ /**+ * return the maximum number of references, that one buffer entry has stored+ * @return+ */+ public int getBufferMaxReferences();++ /**+ * return the date of the oldest buffer entry+ * @return a time as milliseconds from epoch+ */+ public long getBufferMinAge();++ /**+ * return the date of the most recent buffer entry+ * @return a time as milliseconds from epoch+ */+ public long getBufferMaxAge();++ /**+ * calculate the memory that is taken by the buffer.+ * This does not simply return a variable content. it is necessary+ * to iterate over all entries to get the whole size.+ * please use this method with great care+ * @return number of bytes that the buffer has allocated+ */+ public long getBufferSizeBytes();++ /**+ * clean the buffer for a given time. The buffer may need operations+ * for flushing, cleaning etc. The buffer operates this cleanup by itself,+ * but may perform better if in spare time this method is called+ * @param time the number of milliseconds that the operation may take+ */+ public void cleanupBuffer(int time);++ /**+ * get the size of the buffer backend+ * @return number of word references+ */+ public int getBackendSize();++ /**+ * get the size of the buffer content+ * @return number of word references+ */+ public int getBufferSize();++ public CloneableIterator<ReferenceContainer> references(+ String startHash,+ boolean rot,+ boolean buffer+ ) throws IOException;+++ public TreeSet<ReferenceContainer> references(+ String startHash,+ boolean rot,+ int count,+ boolean buffer+ ) throws IOException;++}diff --git a/source/de/anomic/kelondro/text/BufferedIndexCollection.java b/source/de/anomic/kelondro/text/BufferedIndexCollection.javanew file mode 100644index 000000000..16289151c--- /dev/null+++ b/source/de/anomic/kelondro/text/BufferedIndexCollection.java@@ -0,0 +1,343 @@+// BufferedIndexCollection.java+// (C) 2005, 2006 by Michael Peter Christen; [email protected], Frankfurt a. M., Germany+// first published 2005 on http://www.anomic.de+//+// This is a part of YaCy, a peer-to-peer based web search engine+//+// $LastChangedDate: 2009-03-13 11:34:51 +0100 (Fr, 13 Mrz 2009) $+// $LastChangedRevision: 5709 $+// $LastChangedBy: orbiter $+//+// LICENSE+//+// This program is free software; you can redistribute it and/or modify+// it under the terms of the GNU General Public License as published by+// the Free Software Foundation; either version 2 of the License, or+// (at your option) any later version.+//+// This program is distributed in the hope that it will be useful,+// but WITHOUT ANY WARRANTY; without even the implied warranty of+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+// GNU General Public License for more details.+//+// You should have received a copy of the GNU General Public License+// along with this program; if not, write to the Free Software+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA++package de.anomic.kelondro.text;++import java.io.File;+import java.io.IOException;+import java.util.ArrayList;+import java.util.Set;++import de.anomic.kelondro.index.Row;+import de.anomic.kelondro.index.RowCollection;+import de.anomic.kelondro.order.Base64Order;+import de.anomic.kelondro.order.ByteOrder;+import de.anomic.kelondro.order.CloneableIterator;+import de.anomic.kelondro.order.MergeIterator;+import de.anomic.kelondro.order.Order;+import de.anomic.kelondro.order.RotateIterator;+import de.anomic.kelondro.text.Index;+import de.anomic.kelondro.text.IndexBuffer;+import de.anomic.kelondro.text.IndexCollection;+import de.anomic.kelondro.text.ReferenceContainer;+import de.anomic.kelondro.text.ReferenceContainerOrder;+import de.anomic.kelondro.text.ReferenceRow;+import de.anomic.kelondro.util.MemoryControl;+import de.anomic.kelondro.util.Log;+import de.anomic.server.serverProfiling;++public final class BufferedIndexCollection extends AbstractBufferedIndex implements Index, BufferedIndex {++ // environment constants+ public static final long wCacheMaxAge = 1000 * 60 * 30; // milliseconds; 30 minutes+ public static final int wCacheMaxChunk = 800; // maximum number of references for each urlhash+ public static final int lowcachedivisor = 900;+ public static final int maxCollectionPartition = 7; // should be 7++ private final IndexBuffer indexCache;+ private final IndexCollection collections; // new database structure to replace AssortmentCluster and FileCluster++ public BufferedIndexCollection (+ File indexPrimaryTextLocation,+ final ByteOrder wordOrdering,+ final Row payloadrow,+ final int entityCacheMaxSize,+ final boolean useCommons,+ final int redundancy,+ Log log) throws IOException {++ final File textindexcache = new File(indexPrimaryTextLocation, "RICACHE");+ if (!(textindexcache.exists())) textindexcache.mkdirs();+ if (new File(textindexcache, "index.dhtin.blob").exists()) {+ // migration of the both caches into one+ this.indexCache = new IndexBuffer(textindexcache, wordOrdering, payloadrow, entityCacheMaxSize, wCacheMaxChunk, wCacheMaxAge, "index.dhtout.blob", log);+ IndexBuffer dhtInCache = new IndexBuffer(textindexcache, wordOrdering, payloadrow, entityCacheMaxSize, wCacheMaxChunk, wCacheMaxAge, "index.dhtin.blob", log);+ for (ReferenceContainer c: dhtInCache) {+ this.indexCache.add(c);+ }+ new File(textindexcache, "index.dhtin.blob").delete();+ } else {+ // read in new BLOB+ this.indexCache = new IndexBuffer(textindexcache, wordOrdering, payloadrow, entityCacheMaxSize, wCacheMaxChunk, wCacheMaxAge, "index.dhtout.blob", log);+ }++ // create collections storage path+ final File textindexcollections = new File(indexPrimaryTextLocation, "RICOLLECTION");+ if (!(textindexcollections.exists())) textindexcollections.mkdirs();+ this.collections = new IndexCollection(+ textindexcollections,+ "collection",+ 12,+ Base64Order.enhancedCoder,+ maxCollectionPartition,+ ReferenceRow.urlEntryRow,+ useCommons);+ }++ /* methods for interface Index */++ public void add(final ReferenceContainer entries) {+ assert (entries.row().objectsize == ReferenceRow.urlEntryRow.objectsize);++ // add the entry+ indexCache.add(entries);+ cacheFlushControl();+ }++ public void add(final String wordHash, final ReferenceRow entry) throws IOException {+ // add the entry+ indexCache.add(wordHash, entry);+ cacheFlushControl();+ }++ public boolean has(final String wordHash) {+ if (indexCache.has(wordHash)) return true;+ if (collections.has(wordHash)) return true;+ return false;+ }++ public int count(String key) {+ return indexCache.count(key) + collections.count(key);+ }++ public ReferenceContainer get(final String wordHash, final Set<String> urlselection) {+ if (wordHash == null) {+ // wrong input+ return null;+ }++ // get from cache+ ReferenceContainer container;+ container = indexCache.get(wordHash, urlselection);++ // get from collection index+ if (container == null) {+ container = collections.get(wordHash, urlselection);+ } else {+ container.addAllUnique(collections.get(wordHash, urlselection));+ }++ if (container == null) return null;++ // check doubles+ final int beforeDouble = container.size();+ container.sort();+ final ArrayList<RowCollection> d = container.removeDoubles();+ RowCollection set;+ for (int i = 0; i < d.size(); i++) {+ // for each element in the double-set, take that one that is the most recent one+ set = d.get(i);+ ReferenceRow e, elm = null;+ long lm = 0;+ for (int j = 0; j < set.size(); j++) {+ e = new ReferenceRow(set.get(j, true));+ if ((elm == null) || (e.lastModified() > lm)) {+ elm = e;+ lm = e.lastModified();+ }+ }+ if(elm != null) {+ container.addUnique(elm.toKelondroEntry());+ }+ }+ if (container.size() < beforeDouble) System.out.println("*** DEBUG DOUBLECHECK - removed " + (beforeDouble - container.size()) + " index entries from word container " + container.getWordHash());++ return container;+ }++ public ReferenceContainer delete(final String wordHash) {+ final ReferenceContainer c = new ReferenceContainer(+ wordHash,+ ReferenceRow.urlEntryRow,+ indexCache.count(wordHash));+ c.addAllUnique(indexCache.delete(wordHash));+ c.addAllUnique(collections.delete(wordHash));+ return c;+ }++ public boolean remove(final String wordHash, final String urlHash) {+ boolean removed = false;+ removed = removed | (indexCache.remove(wordHash, urlHash));+ removed = removed | (collections.remove(wordHash, urlHash));+ return removed;+ }++ public int remove(final String wordHash, final Set<String> urlHashes) {+ int removed = 0;+ removed += indexCache.remove(wordHash, urlHashes);+ removed += collections.remove(wordHash, urlHashes);+ return removed;+ }++ public synchronized CloneableIterator<ReferenceContainer> references(final String startHash, final boolean rot, final boolean ram) throws IOException {+ final CloneableIterator<ReferenceContainer> i = wordContainers(startHash, ram);+ if (rot) {+ return new RotateIterator<ReferenceContainer>(i, new String(Base64Order.zero(startHash.length())), indexCache.size() + ((ram) ? 0 : collections.size()));+ }+ return i;+ }++ private synchronized CloneableIterator<ReferenceContainer> wordContainers(final String startWordHash, final boolean ram) throws IOException {+ final Order<ReferenceContainer> containerOrder = new ReferenceContainerOrder(indexCache.ordering().clone());+ containerOrder.rotate(ReferenceContainer.emptyContainer(startWordHash, 0));+ if (ram) {+ return indexCache.references(startWordHash, false);+ }+ return collections.references(startWordHash, false);+ /*+ return new MergeIterator<ReferenceContainer>(+ indexCache.referenceIterator(startWordHash, false, true),+ collections.referenceIterator(startWordHash, false, false),+ containerOrder,+ ReferenceContainer.containerMergeMethod,+ true);+ */+ }++ public void clear() {+ indexCache.clear();+ try {+ collections.clear();+ } catch (IOException e) {+ e.printStackTrace();+ }+ }++ public void close() {+ indexCache.close();+ collections.close();+ }++ public int size() {+ return java.lang.Math.max(collections.size(), indexCache.size());+ }++ public int minMem() {+ return 1024*1024 /* indexing overhead */ + indexCache.minMem() + collections.minMem();+ }+++ /*+ * methods for cache management+ */++ public int getBufferMaxReferences() {+ return indexCache.getBufferMaxReferences();+ }++ public long getBufferMinAge() {+ return indexCache.getBufferMinAge();+ }++ public long getBufferMaxAge() {+ return indexCache.getBufferMaxAge();+ }++ public long getBufferSizeBytes() {+ return indexCache.getBufferSizeBytes();+ }++ public void setBufferMaxWordCount(final int maxWords) {+ indexCache.setMaxWordCount(maxWords);+ }++ private void cacheFlushControl() {+ // check for forced flush+ int cs = getBufferSize();+ if (cs > 0) {+ // flush elements that are too big. This flushing depends on the fact that the flush rule+ // selects the biggest elements first for flushing. If it does not for any reason, the following+ // loop would not terminate.+ serverProfiling.update("wordcache", Long.valueOf(cs), true);+ // To ensure termination an additional counter is used+ int l = 0;+ while (this.indexCache.size() > 0 && (l++ < 100) && (this.indexCache.getBufferMaxReferences() > wCacheMaxChunk)) {+ flushCacheOne(this.indexCache);+ }+ // next flush more entries if the size exceeds the maximum size of the cache+ while (this.indexCache.size() > 0 &&+ ((this.indexCache.size() > this.indexCache.getMaxWordCount()) ||+ (MemoryControl.available() < collections.minMem()))) {+ flushCacheOne(this.indexCache);+ }+ if (getBufferSize() != cs) serverProfiling.update("wordcache", Long.valueOf(getBufferSize()), true);+ }+ }++ public void cleanupBuffer(int time) {+ flushCacheUntil(System.currentTimeMillis() + time);+ }++ private synchronized void flushCacheUntil(long timeout) {+ while (System.currentTimeMillis() < timeout && indexCache.size() > 0) {+ flushCacheOne(indexCache);+ }+ }++ private synchronized void flushCacheOne(final IndexBuffer ram) {+ if (ram.size() > 0) collections.add(flushContainer(ram));+ }++ private ReferenceContainer flushContainer(final IndexBuffer ram) {+ String wordHash;+ ReferenceContainer c;+ wordHash = ram.maxScoreWordHash();+ c = ram.get(wordHash, null);+ if ((c != null) && (c.size() > wCacheMaxChunk)) {+ return ram.delete(wordHash);+ } else {+ return ram.delete(ram.bestFlushWordHash());+ }+ }++ public int getBackendSize() {+ return collections.size();+ }++ public int getBufferSize() {+ return indexCache.size();+ }++ public ByteOrder ordering() {+ return collections.ordering();+ }++ public CloneableIterator<ReferenceContainer> references(String startWordHash, boolean rot) {+ final Order<ReferenceContainer> containerOrder = new ReferenceContainerOrder(this.indexCache.ordering().clone());+ return new MergeIterator<ReferenceContainer>(+ this.indexCache.references(startWordHash, rot),+ new MergeIterator<ReferenceContainer>(+ this.indexCache.references(startWordHash, false),+ this.collections.references(startWordHash, false),+ containerOrder,+ ReferenceContainer.containerMergeMethod,+ true),+ containerOrder,+ ReferenceContainer.containerMergeMethod,+ true);+ }++}diff --git a/source/de/anomic/kelondro/text/CachedIndexCollection.java b/source/de/anomic/kelondro/text/CachedIndexCollection.javadeleted file mode 100644index 4d529dbb0..000000000--- a/source/de/anomic/kelondro/text/CachedIndexCollection.java+++ /dev/null@@ -1,414 +0,0 @@-// plasmaWordIndex.java-// (C) 2005, 2006 by Michael Peter Christen; [email protected], Frankfurt a. M., Germany-// first published 2005 on http://www.anomic.de-//-// This is a part of YaCy, a peer-to-peer based web search engine-//-// $LastChangedDate: 2009-03-13 11:34:51 +0100 (Fr, 13 Mrz 2009) $-// $LastChangedRevision: 5709 $-// $LastChangedBy: orbiter $-//-// LICENSE-//-// This program is free software; you can redistribute it and/or modify-// it under the terms of the GNU General Public License as published by-// the Free Software Foundation; either version 2 of the License, or-// (at your option) any later version.-//-// This program is distributed in the hope that it will be useful,-// but WITHOUT ANY WARRANTY; without even the implied warranty of-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-// GNU General Public License for more details.-//-// You should have received a copy of the GNU General Public License-// along with this program; if not, write to the Free Software-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA--package de.anomic.kelondro.text;--import java.io.File;-import java.io.IOException;-import java.util.ArrayList;-import java.util.HashMap;-import java.util.Iterator;-import java.util.Set;-import java.util.TreeSet;--import de.anomic.kelondro.index.RowCollection;-import de.anomic.kelondro.order.Base64Order;-import de.anomic.kelondro.order.ByteOrder;-import de.anomic.kelondro.order.CloneableIterator;-import de.anomic.kelondro.order.Order;-import de.anomic.kelondro.order.RotateIterator;-import de.anomic.kelondro.text.Index;-import de.anomic.kelondro.text.IndexCache;-import de.anomic.kelondro.text.IndexCollection;-import de.anomic.kelondro.text.ReferenceContainer;-import de.anomic.kelondro.text.ReferenceContainerOrder;-import de.anomic.kelondro.text.ReferenceRow;-import de.anomic.kelondro.util.MemoryControl;-import de.anomic.kelondro.util.Log;-import de.anomic.server.serverProfiling;--public final class CachedIndexCollection extends AbstractIndex implements Index, IndexPackage {-- // environment constants- public static final long wCacheMaxAge = 1000 * 60 * 30; // milliseconds; 30 minutes- public static final int wCacheMaxChunk = 800; // maximum number of references for each urlhash- public static final int lowcachedivisor = 900;- public static final int maxCollectionPartition = 7; // should be 7- private static final ByteOrder indexOrder = Base64Order.enhancedCoder;---- private final IndexCache indexCache;- private final IndexCollection collections; // new database structure to replace AssortmentCluster and FileCluster-- public CachedIndexCollection (- File indexPrimaryTextLocation,- final int entityCacheMaxSize,- final boolean useCommons,- final int redundancy,- Log log) throws IOException {-- final File textindexcache = new File(indexPrimaryTextLocation, "RICACHE");- if (!(textindexcache.exists())) textindexcache.mkdirs();- if (new File(textindexcache, "index.dhtin.blob").exists()) {- // migration of the both caches into one- this.indexCache = new IndexCache(textindexcache, ReferenceRow.urlEntryRow, entityCacheMaxSize, wCacheMaxChunk, wCacheMaxAge, "index.dhtout.blob", log);- IndexCache dhtInCache = new IndexCache(textindexcache, ReferenceRow.urlEntryRow, entityCacheMaxSize, wCacheMaxChunk, wCacheMaxAge, "index.dhtin.blob", log);- for (ReferenceContainer c: dhtInCache) {- this.indexCache.addReferences(c);- }- new File(textindexcache, "index.dhtin.blob").delete();- } else {- // read in new BLOB- this.indexCache = new IndexCache(textindexcache, ReferenceRow.urlEntryRow, entityCacheMaxSize, wCacheMaxChunk, wCacheMaxAge, "index.dhtout.blob", log);- }-- // create collections storage path- final File textindexcollections = new File(indexPrimaryTextLocation, "RICOLLECTION");- if (!(textindexcollections.exists())) textindexcollections.mkdirs();- this.collections = new IndexCollection(- textindexcollections,- "collection",- 12,- Base64Order.enhancedCoder,- maxCollectionPartition,- ReferenceRow.urlEntryRow,- useCommons);- }-- /* methods for interface Index */-- public void addReferences(final ReferenceContainer entries) {- assert (entries.row().objectsize == ReferenceRow.urlEntryRow.objectsize);-- // add the entry- indexCache.addReferences(entries);- cacheFlushControl();- }-- public void addReference(final String wordHash, final ReferenceRow entry) throws IOException {- // add the entry- indexCache.addReference(wordHash, entry);- cacheFlushControl();- }-- public boolean hasReferences(final String wordHash) {- if (indexCache.hasReferences(wordHash)) return true;- if (collections.hasReferences(wordHash)) return true;- return false;- }-- public int countReferences(String key) {- return indexCache.countReferences(key) + collections.countReferences(key);- }-- public ReferenceContainer getReferences(final String wordHash, final Set<String> urlselection) {- if (wordHash == null) {- // wrong input- return null;- }-- // get from cache- ReferenceContainer container;- container = indexCache.getReferences(wordHash, urlselection);-- // get from collection index- if (container == null) {- container = collections.getReferences(wordHash, urlselection);- } else {- container.addAllUnique(collections.getReferences(wordHash, urlselection));- }-- if (container == null) return null;-- // check doubles- final int beforeDouble = container.size();- container.sort();- final ArrayList<RowCollection> d = container.removeDoubles();- RowCollection set;- for (int i = 0; i < d.size(); i++) {- // for each element in the double-set, take that one that is the most recent one- set = d.get(i);- ReferenceRow e, elm = null;- long lm = 0;- for (int j = 0; j < set.size(); j++) {- e = new ReferenceRow(set.get(j, true));- if ((elm == null) || (e.lastModified() > lm)) {- elm = e;- lm = e.lastModified();- }- }- if(elm != null) {- container.addUnique(elm.toKelondroEntry());- }- }- if (container.size() < beforeDouble) System.out.println("*** DEBUG DOUBLECHECK - removed " + (beforeDouble - container.size()) + " index entries from word container " + container.getWordHash());-- return container;- }-- public ReferenceContainer deleteAllReferences(final String wordHash) {- final ReferenceContainer c = new ReferenceContainer(- wordHash,- ReferenceRow.urlEntryRow,- indexCache.countReferences(wordHash));- c.addAllUnique(indexCache.deleteAllReferences(wordHash));- c.addAllUnique(collections.deleteAllReferences(wordHash));- return c;- }-- public boolean removeReference(final String wordHash, final String urlHash) {- boolean removed = false;- removed = removed | (indexCache.removeReference(wordHash, urlHash));- removed = removed | (collections.removeReference(wordHash, urlHash));- return removed;- }-- public int removeReferences(final String wordHash, final Set<String> urlHashes) {- int removed = 0;- removed += indexCache.removeReferences(wordHash, urlHashes);- removed += collections.removeReferences(wordHash, urlHashes);- return removed;- }-- public synchronized CloneableIterator<ReferenceContainer> referenceIterator(final String startHash, final boolean rot, final boolean ram) {- final CloneableIterator<ReferenceContainer> i = wordContainers(startHash, ram);- if (rot) {- return new RotateIterator<ReferenceContainer>(i, new String(Base64Order.zero(startHash.length())), indexCache.size() + ((ram) ? 0 : collections.size()));- }- return i;- }-- private synchronized CloneableIterator<ReferenceContainer> wordContainers(final String startWordHash, final boolean ram) {- final Order<ReferenceContainer> containerOrder = new ReferenceContainerOrder(indexOrder.clone());- containerOrder.rotate(ReferenceContainer.emptyContainer(startWordHash, 0));- if (ram) {- return indexCache.referenceIterator(startWordHash, false, true);- }- return collections.referenceIterator(startWordHash, false, false);- /*- return new MergeIterator<ReferenceContainer>(- indexCache.referenceIterator(startWordHash, false, true),- collections.referenceIterator(startWordHash, false, false),- containerOrder,- ReferenceContainer.containerMergeMethod,- true);- */- }-- public void clear() {- indexCache.clear();- try {- collections.clear();- } catch (IOException e) {- e.printStackTrace();- }- }-- public void close() {- indexCache.close();- collections.close();- }-- public int size() {- return java.lang.Math.max(collections.size(), indexCache.size());- }-- public int minMem() {- return 1024*1024 /* indexing overhead */ + indexCache.minMem() + collections.minMem();- }--- /*- * methods for cache management- */-- public int maxURLinCache() {- return indexCache.maxURLinCache();- }-- public long minAgeOfCache() {- return indexCache.minAgeOfCache();- }-- public long maxAgeOfCache() {- return indexCache.maxAgeOfCache();- }-- public int indexCacheSize() {- return indexCache.size();- }-- public long indexCacheSizeBytes() {- // calculate the real size in bytes of the index cache- long cacheBytes = 0;- final long entryBytes = ReferenceRow.urlEntryRow.objectsize;- final IndexCache cache = (indexCache);- synchronized (cache) {- final Iterator<ReferenceContainer> it = cache.referenceIterator(null, false, true);- while (it.hasNext()) cacheBytes += it.next().size() * entryBytes;- }- return cacheBytes;- }-- public void setMaxWordCount(final int maxWords) {- indexCache.setMaxWordCount(maxWords);- }-- public void cacheFlushControl() {- // check for forced flush- int cs = cacheSize();- if (cs > 0) {- // flush elements that are too big. This flushing depends on the fact that the flush rule- // selects the biggest elements first for flushing. If it does not for any reason, the following- // loop would not terminate.- serverProfiling.update("wordcache", Long.valueOf(cs), true);- // To ensure termination an additional counter is used- int l = 0;- while (this.indexCache.size() > 0 && (l++ < 100) && (this.indexCache.maxURLinCache() > wCacheMaxChunk)) {- flushCacheOne(this.indexCache);- }- // next flush more entries if the size exceeds the maximum size of the cache- while (this.indexCache.size() > 0 &&- ((this.indexCache.size() > this.indexCache.getMaxWordCount()) ||- (MemoryControl.available() < collections.minMem()))) {- flushCacheOne(this.indexCache);- }- if (cacheSize() != cs) serverProfiling.update("wordcache", Long.valueOf(cacheSize()), true);- }- }-- public void flushCacheFor(int time) {- flushCacheUntil(System.currentTimeMillis() + time);- }-- private synchronized void flushCacheUntil(long timeout) {- while (System.currentTimeMillis() < timeout && indexCache.size() > 0) {- flushCacheOne(indexCache);- }- }-- private synchronized void flushCacheOne(final IndexCache ram) {- if (ram.size() > 0) collections.addReferences(flushContainer(ram));- }-- private ReferenceContainer flushContainer(final IndexCache ram) {- String wordHash;- ReferenceContainer c;- wordHash = ram.maxScoreWordHash();- c = ram.getReferences(wordHash, null);- if ((c != null) && (c.size() > wCacheMaxChunk)) {- return ram.deleteAllReferences(wordHash);- } else {- return ram.deleteAllReferences(ram.bestFlushWordHash());- }- }-- public int backendSize() {- return collections.size();- }-- public int cacheSize() {- return indexCache.size();- }---- /*- * methods to search the index- */-- @SuppressWarnings("unchecked")- public HashMap<String, ReferenceContainer>[] localSearchContainers(- final TreeSet<String> queryHashes,- final TreeSet<String> excludeHashes,- final Set<String> urlselection) {- // search for the set of hashes and return a map of of wordhash:indexContainer containing the seach result-- // retrieve entities that belong to the hashes- HashMap<String, ReferenceContainer> inclusionContainers = (queryHashes.size() == 0) ? new HashMap<String, ReferenceContainer>(0) : getContainers(- queryHashes,- urlselection);- if ((inclusionContainers.size() != 0) && (inclusionContainers.size() < queryHashes.size())) inclusionContainers = new HashMap<String, ReferenceContainer>(0); // prevent that only a subset is returned- final HashMap<String, ReferenceContainer> exclusionContainers = (inclusionContainers.size() == 0) ? new HashMap<String, ReferenceContainer>(0) : getContainers(- excludeHashes,- urlselection);- return new HashMap[]{inclusionContainers, exclusionContainers};- }-- /**- * collect containers for given word hashes. This collection stops if a single container does not contain any references.- * In that case only a empty result is returned.- * @param wordHashes- * @param urlselection- * @return map of wordhash:indexContainer- */- private HashMap<String, ReferenceContainer> getContainers(final Set<String> wordHashes, final Set<String> urlselection) {- // retrieve entities that belong to the hashes- final HashMap<String, ReferenceContainer> containers = new HashMap<String, ReferenceContainer>(wordHashes.size());- String singleHash;- ReferenceContainer singleContainer;- final Iterator<String> i = wordHashes.iterator();- while (i.hasNext()) {-- // get next word hash:- singleHash = i.next();-- // retrieve index- singleContainer = getReferences(singleHash, urlselection);-- // check result- if ((singleContainer == null || singleContainer.size() == 0)) return new HashMap<String, ReferenceContainer>(0);-- containers.put(singleHash, singleContainer);- }- return containers;- }-- public synchronized TreeSet<ReferenceContainer> indexContainerSet(final String startHash, final boolean ram, final boolean rot, int count) {- // creates a set of indexContainers- // this does not use the cache- final Order<ReferenceContainer> containerOrder = new ReferenceContainerOrder(indexOrder.clone());- containerOrder.rotate(ReferenceContainer.emptyContainer(startHash, 0));- final TreeSet<ReferenceContainer> containers = new TreeSet<ReferenceContainer>(containerOrder);- final Iterator<ReferenceContainer> i = referenceIterator(startHash, rot, ram);- if (ram) count = Math.min(indexCache.size(), count);- ReferenceContainer container;- // this loop does not terminate using the i.hasNex() predicate when rot == true- // because then the underlying iterator is a rotating iterator without termination- // in this case a termination must be ensured with a counter- // It must also be ensured that the counter is in/decreased every loop- while ((count > 0) && (i.hasNext())) {- container = i.next();- if ((container != null) && (container.size() > 0)) {- containers.add(container);- }- count--; // decrease counter even if the container was null or empty to ensure termination- }- return containers; // this may return less containers as demanded- }--}diff --git a/source/de/anomic/kelondro/text/Index.java b/source/de/anomic/kelondro/text/Index.javaindex cd02c1089..fca42eb25 100644--- a/source/de/anomic/kelondro/text/Index.java+++ b/source/de/anomic/kelondro/text/Index.java@@ -30,7 +30,9 @@ package de.anomic.kelondro.text;import java.io.IOException;import java.util.Set;+import java.util.TreeSet;+import de.anomic.kelondro.order.ByteOrder;import de.anomic.kelondro.order.CloneableIterator;public interface Index {@@ -43,7 +45,7 @@ public interface Index {* @param newEntries the References to be merged with existing references* @throws IOException*/- public void addReferences(ReferenceContainer newEntries) throws IOException;+ public void add(ReferenceContainer newEntries) throws IOException;/*** add a single reference to the reverse index@@ -54,14 +56,14 @@ public interface Index {* @param entry* @throws IOException*/- public void addReference(final String wordHash, final ReferenceRow entry) throws IOException;+ public void add(final String wordHash, final ReferenceRow entry) throws IOException;/*** check if there are references stored to the given word hash* @param wordHash* @return true if references exist, false if not*/- public boolean hasReferences(String wordHash); // should only be used if in case that true is returned the getContainer is NOT called+ public boolean has(String wordHash); // should only be used if in case that true is returned the getContainer is NOT called/*** count the number of references for the given word@@ -70,7 +72,7 @@ public interface Index {* @param wordHash* @return the number of references to the given word*/- public int countReferences(final String wordHash);+ public int count(final String wordHash);/*** get the references to a given word.@@ -81,7 +83,7 @@ public interface Index {* @return the references* @throws IOException*/- public ReferenceContainer getReferences(String wordHash, Set<String> referenceselection) throws IOException;+ public ReferenceContainer get(String wordHash, Set<String> referenceselection) throws IOException;/*** delete all references for a word@@ -89,7 +91,7 @@ public interface Index {* @return the deleted references* @throws IOException*/- public ReferenceContainer deleteAllReferences(String wordHash) throws IOException;+ public ReferenceContainer delete(String wordHash) throws IOException;/*** remove a specific reference entry@@ -98,7 +100,7 @@ public interface Index {* @return* @throws IOException*/- public boolean removeReference(String wordHash, String referenceHash) throws IOException;+ public boolean remove(String wordHash, String referenceHash) throws IOException;/*** remove a set of reference entries for a given word@@ -107,11 +109,11 @@ public interface Index {* @return* @throws IOException*/- public int removeReferences(String wordHash, Set<String> referenceHashes) throws IOException;+ public int remove(String wordHash, Set<String> referenceHashes) throws IOException;- public int removeEntryMultiple(final Set<String> wordHashes, final String urlHash) throws IOException;+ public int remove(final Set<String> wordHashes, final String urlHash) throws IOException;- public void removeEntriesMultiple(final Set<String> wordHashes, final Set<String> urlHashes) throws IOException;+ public void remove(final Set<String> wordHashes, final Set<String> urlHashes) throws IOException;/*** iterate all references from the beginning of a specific word hash@@ -121,7 +123,17 @@ public interface Index {* @return* @throws IOException*/- public CloneableIterator<ReferenceContainer> referenceIterator(String startWordHash, boolean rot, boolean ram) throws IOException; // method to replace wordHashes+ public CloneableIterator<ReferenceContainer> references(+ String startHash,+ boolean rot+ ) throws IOException;+++ public TreeSet<ReferenceContainer> references(+ String startHash,+ boolean rot,+ int count+ ) throws IOException;/*** delete all references entries@@ -146,4 +158,9 @@ public interface Index {*/public int minMem();+ /**+ * return the order that is used for the storage of the word hashes+ * @return+ */+ public ByteOrder ordering();}diff --git a/source/de/anomic/kelondro/text/IndexCache.java b/source/de/anomic/kelondro/text/IndexBuffer.javasimilarity index 79%rename from source/de/anomic/kelondro/text/IndexCache.javarename to source/de/anomic/kelondro/text/IndexBuffer.javaindex 6a5ccd2d1..199854a1b 100644--- a/source/de/anomic/kelondro/text/IndexCache.java+++ b/source/de/anomic/kelondro/text/IndexBuffer.java@@ -33,6 +33,7 @@ import java.util.Iterator;import java.util.Set;import de.anomic.kelondro.index.Row;+import de.anomic.kelondro.order.ByteOrder;import de.anomic.kelondro.order.CloneableIterator;import de.anomic.kelondro.util.MemoryControl;import de.anomic.kelondro.util.ScoreCluster;@@ -42,7 +43,7 @@ import de.anomic.kelondro.util.Log;* A IndexCache is a ReferenceContainerCache with an attached cache flush logic**/-public final class IndexCache extends AbstractIndex implements Index, IndexReader, Iterable<ReferenceContainer> {+public final class IndexBuffer extends AbstractIndex implements Index, IndexReader, Iterable<ReferenceContainer> {// class variablesprivate final ScoreCluster<String> hashScore;@@ -56,8 +57,9 @@ public final class IndexCache extends AbstractIndex implements Index, IndexReadeprivate ReferenceContainerCache heap;@SuppressWarnings("unchecked")- public IndexCache(+ public IndexBuffer(final File databaseRoot,+ final ByteOrder wordOrdering,final Row payloadrow,final int entityCacheMaxSize,final int wCacheReferenceCountLimitInit,@@ -75,7 +77,7 @@ public final class IndexCache extends AbstractIndex implements Index, IndexReadethis.cacheReferenceAgeLimit = wCacheReferenceAgeLimitInit;this.log = log;this.dumpFile = new File(databaseRoot, newHeapName);- this.heap = new ReferenceContainerCache(payloadrow);+ this.heap = new ReferenceContainerCache(payloadrow, wordOrdering);// read in dump of last sessionboolean initFailed = false;@@ -91,7 +93,7 @@ public final class IndexCache extends AbstractIndex implements Index, IndexReadeheap.initWriteMode();} else if (dumpFile.exists()) {// initialize scores for cache organization- for (final ReferenceContainer ic : (Iterable<ReferenceContainer>) heap.referenceIterator(null, false, true)) {+ for (final ReferenceContainer ic : (Iterable<ReferenceContainer>) heap.references(null, false)) {this.hashDate.setScore(ic.getWordHash(), intTime(ic.lastWrote()));this.hashScore.setScore(ic.getWordHash(), ic.size());}@@ -118,17 +120,17 @@ public final class IndexCache extends AbstractIndex implements Index, IndexReade}// cache settings- public int maxURLinCache() {+ public int getBufferMaxReferences() {if (hashScore.size() == 0) return 0;return hashScore.getMaxScore();}- public long minAgeOfCache() {+ public long getBufferMinAge() {if (hashDate.size() == 0) return 0;return System.currentTimeMillis() - longEmit(hashDate.getMaxScore());}- public long maxAgeOfCache() {+ public long getBufferMaxAge() {if (hashDate.size() == 0) return 0;return System.currentTimeMillis() - longEmit(hashDate.getMinScore());}@@ -146,12 +148,11 @@ public final class IndexCache extends AbstractIndex implements Index, IndexReadereturn heap.size();}- public synchronized CloneableIterator<ReferenceContainer> referenceIterator(final String startWordHash, final boolean rot, final boolean ram) {+ public synchronized CloneableIterator<ReferenceContainer> references(final String startWordHash, final boolean rot) {// we return an iterator object that creates top-level-clones of the indexContainers// in the cache, so that manipulations of the iterated objects do not change// objects in the cache.- assert ram == true;- return heap.referenceIterator(startWordHash, rot, ram);+ return heap.references(startWordHash, rot);}public synchronized String maxScoreWordHash() {@@ -195,7 +196,7 @@ public final class IndexCache extends AbstractIndex implements Index, IndexReadehash = hashDate.getMinObject(); // flush oldest entries}if (hash == null) {- final ReferenceContainer ic = heap.referenceIterator(null, false, true).next();+ final ReferenceContainer ic = heap.references(null, false).next();if (ic != null) hash = ic.getWordHash();}return hash;@@ -213,7 +214,7 @@ public final class IndexCache extends AbstractIndex implements Index, IndexReadefor (int i = 0; i < count; i++) {hash = bestFlushWordHash();if (hash == null) return containerList;- container = heap.deleteAllReferences(hash);+ container = heap.delete(hash);assert (container != null);if (container == null) return containerList;hashScore.deleteScore(hash);@@ -231,19 +232,19 @@ public final class IndexCache extends AbstractIndex implements Index, IndexReadereturn (((long) intTime) * (long) 1000) + initTime;}- public boolean hasReferences(final String wordHash) {- return heap.hasReferences(wordHash);+ public boolean has(final String wordHash) {+ return heap.has(wordHash);}- public int countReferences(String key) {- return this.heap.countReferences(key);+ public int count(String key) {+ return this.heap.count(key);}- public synchronized ReferenceContainer getReferences(final String wordHash, final Set<String> urlselection) {+ public synchronized ReferenceContainer get(final String wordHash, final Set<String> urlselection) {if (wordHash == null) return null;// retrieve container- ReferenceContainer container = heap.getReferences(wordHash, null);+ ReferenceContainer container = heap.get(wordHash, null);// We must not use the container from cache to store everything we find,// as that container remains linked to in the cache and might be changed later@@ -257,19 +258,19 @@ public final class IndexCache extends AbstractIndex implements Index, IndexReadereturn container;}- public synchronized ReferenceContainer deleteAllReferences(final String wordHash) {+ public synchronized ReferenceContainer delete(final String wordHash) {// returns the index that had been deletedif (wordHash == null || heap == null) return null;- final ReferenceContainer container = heap.deleteAllReferences(wordHash);+ final ReferenceContainer container = heap.delete(wordHash);hashScore.deleteScore(wordHash);hashDate.deleteScore(wordHash);return container;}- public synchronized boolean removeReference(final String wordHash, final String urlHash) {- final boolean removed = heap.removeReference(wordHash, urlHash);+ public synchronized boolean remove(final String wordHash, final String urlHash) {+ final boolean removed = heap.remove(wordHash, urlHash);if (removed) {- if (heap.hasReferences(wordHash)) {+ if (heap.has(wordHash)) {hashScore.decScore(wordHash);hashDate.setScore(wordHash, intTime(System.currentTimeMillis()));} else {@@ -281,12 +282,12 @@ public final class IndexCache extends AbstractIndex implements Index, IndexReadereturn false;}- public synchronized int removeReferences(final String wordHash, final Set<String> urlHashes) {+ public synchronized int remove(final String wordHash, final Set<String> urlHashes) {if (urlHashes.size() == 0) return 0;- final int c = heap.removeReferences(wordHash, urlHashes);+ final int c = heap.remove(wordHash, urlHashes);if (c > 0) {// removal successful- if (heap.hasReferences(wordHash)) {+ if (heap.has(wordHash)) {hashScore.addScore(wordHash, -c);hashDate.setScore(wordHash, intTime(System.currentTimeMillis()));} else {@@ -298,20 +299,20 @@ public final class IndexCache extends AbstractIndex implements Index, IndexReadereturn 0;}- public synchronized void addReferences(final ReferenceContainer container) {+ public synchronized void add(final ReferenceContainer container) {if (container == null || container.size() == 0 || heap == null) return;// put new words into cache- heap.addReferences(container);- hashScore.setScore(container.getWordHash(), heap.countReferences(container.getWordHash()));+ heap.add(container);+ hashScore.setScore(container.getWordHash(), heap.count(container.getWordHash()));hashDate.setScore(container.getWordHash(), intTime(System.currentTimeMillis()));}- public void addReference(final String wordHash, final ReferenceRow entry) throws IOException {+ public void add(final String wordHash, final ReferenceRow entry) throws IOException {if (entry == null || heap == null) return;// put new words into cache- heap.addReference(wordHash, entry);+ heap.add(wordHash, entry);hashScore.incScore(wordHash);hashDate.setScore(wordHash, intTime(System.currentTimeMillis()));}@@ -330,6 +331,20 @@ public final class IndexCache extends AbstractIndex implements Index, IndexReade}public Iterator<ReferenceContainer> iterator() {- return referenceIterator(null, false, true);+ return references(null, false);}++ public ByteOrder ordering() {+ return heap.ordering();+ }++ public synchronized long getBufferSizeBytes() {+ // calculate the real size in bytes of the index cache+ long cacheBytes = 0;+ final long entryBytes = ReferenceRow.urlEntryRow.objectsize;+ final Iterator<ReferenceContainer> it = references(null, false);+ while (it.hasNext()) cacheBytes += it.next().size() * entryBytes;+ return cacheBytes;+ }+}diff --git a/source/de/anomic/kelondro/text/IndexCell.java b/source/de/anomic/kelondro/text/IndexCell.javaindex fd766507a..ed88a5e3a 100644--- a/source/de/anomic/kelondro/text/IndexCell.java+++ b/source/de/anomic/kelondro/text/IndexCell.java@@ -32,6 +32,7 @@ import java.util.HashSet;import java.util.Set;import de.anomic.kelondro.index.Row;+import de.anomic.kelondro.order.ByteOrder;import de.anomic.kelondro.order.CloneableIterator;import de.anomic.kelondro.order.MergeIterator;import de.anomic.kelondro.order.Order;@@ -56,11 +57,12 @@ public final class IndexCell extends AbstractIndex implements Index {public IndexCell(final File cellPath,+ final ByteOrder wordOrder,final Row payloadrow,final int maxRamEntries) throws IOException {- this.array = new ReferenceContainerArray(cellPath, payloadrow);- this.ram = new ReferenceContainerCache(payloadrow);+ this.array = new ReferenceContainerArray(cellPath, wordOrder, payloadrow);+ this.ram = new ReferenceContainerCache(payloadrow, wordOrder);this.maxRamEntries = maxRamEntries;}@@ -69,23 +71,27 @@ public final class IndexCell extends AbstractIndex implements Index {File dumpFile = this.array.newContainerBLOBFile();this.ram.dump(dumpFile);// get a fresh ram cache- this.ram = new ReferenceContainerCache(this.array.rowdef());+ this.ram = new ReferenceContainerCache(this.array.rowdef(), this.array.ordering());// add the dumped indexContainerBLOB to the arraythis.array.mountBLOBContainer(dumpFile);}+ public ByteOrder ordering() {+ return this.array.ordering();+ }+/*** add entries to the cell: this adds the new entries always to the RAM part, never to BLOBs* @throws IOException* @throws IOException*/- public synchronized void addReferences(ReferenceContainer newEntries) throws IOException {- this.ram.addReferences(newEntries);+ public synchronized void add(ReferenceContainer newEntries) throws IOException {+ this.ram.add(newEntries);if (this.ram.size() > this.maxRamEntries) cacheDump();}- public synchronized void addReference(String hash, ReferenceRow entry) throws IOException {- this.ram.addReference(hash, entry);+ public synchronized void add(String hash, ReferenceRow entry) throws IOException {+ this.ram.add(hash, entry);if (this.ram.size() > this.maxRamEntries) cacheDump();}@@ -120,8 +126,8 @@ public final class IndexCell extends AbstractIndex implements Index {* the deleted containers are merged and returned as result of the method* @throws IOException*/- public ReferenceContainer deleteAllReferences(String wordHash) throws IOException {- ReferenceContainer c0 = this.ram.deleteAllReferences(wordHash);+ public ReferenceContainer delete(String wordHash) throws IOException {+ ReferenceContainer c0 = this.ram.delete(wordHash);ReferenceContainer c1 = this.array.get(wordHash);if (c1 == null) {if (c0 == null) return null;@@ -136,8 +142,8 @@ public final class IndexCell extends AbstractIndex implements Index {* all containers in the BLOBs and the RAM are merged and returned* @throws IOException*/- public ReferenceContainer getReferences(String wordHash, Set<String> urlselection) throws IOException {- ReferenceContainer c0 = this.ram.getReferences(wordHash, null);+ public ReferenceContainer get(String wordHash, Set<String> urlselection) throws IOException {+ ReferenceContainer c0 = this.ram.get(wordHash, null);ReferenceContainer c1 = this.array.get(wordHash);if (c1 == null) {if (c0 == null) return null;@@ -147,8 +153,8 @@ public final class IndexCell extends AbstractIndex implements Index {return c1.merge(c0);}- public int countReferences(String wordHash) {- ReferenceContainer c0 = this.ram.getReferences(wordHash, null);+ public int count(String wordHash) {+ ReferenceContainer c0 = this.ram.get(wordHash, null);ReferenceContainer c1;try {c1 = this.array.get(wordHash);@@ -166,8 +172,8 @@ public final class IndexCell extends AbstractIndex implements Index {/*** checks if there is any container for this wordHash, either in RAM or any BLOB*/- public boolean hasReferences(String wordHash) {- if (this.ram.hasReferences(wordHash)) return true;+ public boolean has(String wordHash) {+ if (this.ram.has(wordHash)) return true;return this.array.has(wordHash);}@@ -184,12 +190,12 @@ public final class IndexCell extends AbstractIndex implements Index {* @throws IOException* @throws IOException*/- public int removeReferences(String wordHash, Set<String> urlHashes) throws IOException {+ public int remove(String wordHash, Set<String> urlHashes) throws IOException {int reduced = this.array.replace(wordHash, new RemoveRewriter(urlHashes));return reduced / this.array.rowdef().objectsize;}- public boolean removeReference(String wordHash, String urlHash) throws IOException {+ public boolean remove(String wordHash, String urlHash) throws IOException {int reduced = this.array.replace(wordHash, new RemoveRewriter(urlHash));return reduced > 0;}@@ -198,14 +204,30 @@ public final class IndexCell extends AbstractIndex implements Index {return this.ram.size() + this.array.size();}- public CloneableIterator<ReferenceContainer> referenceIterator(String startWordHash, boolean rot, boolean ram) {+ public CloneableIterator<ReferenceContainer> references(String startWordHash, boolean rot) {+ final Order<ReferenceContainer> containerOrder = new ReferenceContainerOrder(this.ram.rowdef().getOrdering().clone());+ containerOrder.rotate(new ReferenceContainer(startWordHash, this.ram.rowdef(), 0));+ return new MergeIterator<ReferenceContainer>(+ this.ram.references(startWordHash, rot),+ new MergeIterator<ReferenceContainer>(+ this.ram.references(startWordHash, false),+ this.array.wordContainerIterator(startWordHash, false, false),+ containerOrder,+ ReferenceContainer.containerMergeMethod,+ true),+ containerOrder,+ ReferenceContainer.containerMergeMethod,+ true);+ }++ public CloneableIterator<ReferenceContainer> references(String startWordHash, boolean rot, boolean ram) {final Order<ReferenceContainer> containerOrder = new ReferenceContainerOrder(this.ram.rowdef().getOrdering().clone());containerOrder.rotate(new ReferenceContainer(startWordHash, this.ram.rowdef(), 0));if (ram) {- return this.ram.referenceIterator(startWordHash, rot, true);+ return this.ram.references(startWordHash, rot);}return new MergeIterator<ReferenceContainer>(- this.ram.referenceIterator(startWordHash, false, true),+ this.ram.references(startWordHash, false),this.array.wordContainerIterator(startWordHash, false, false),containerOrder,ReferenceContainer.containerMergeMethod,diff --git a/source/de/anomic/kelondro/text/IndexCollection.java b/source/de/anomic/kelondro/text/IndexCollection.javaindex 444328b9d..57252018b 100644--- a/source/de/anomic/kelondro/text/IndexCollection.java+++ b/source/de/anomic/kelondro/text/IndexCollection.java@@ -90,9 +90,9 @@ public class IndexCollection extends AbstractIndex implements Index {public IndexCollection(final File path,- final String filenameStub,- final int keyLength,- final ByteOrder indexOrder,+ final String filenameStub,+ final int keyLength,+ final ByteOrder wordOrder,final int maxpartitions,final Row payloadrow,boolean useCommons) throws IOException {@@ -119,8 +119,8 @@ public class IndexCollection extends AbstractIndex implements Index {// open index and array filesthis.arrays = new HashMap<String, FixedWidthArray>(); // all entries will be dynamically created with getArray()- index = openIndexFile(path, this.keylength, filenameStub, indexOrder, loadfactor, payloadrow, 0);- openAllArrayFiles(false, indexOrder);+ index = openIndexFile(path, this.keylength, filenameStub, wordOrder, loadfactor, payloadrow, 0);+ openAllArrayFiles(false, wordOrder);} else {// calculate initialSpacefinal String[] list = this.path.list();@@ -133,7 +133,7 @@ public class IndexCollection extends AbstractIndex implements Index {final int partitionNumber = Integer.parseInt(list[i].substring(pos + 9, pos + 11), 16);final int serialNumber = Integer.parseInt(list[i].substring(pos + 12, pos + 14), 16);try {- array = openArrayFile(this.path, this.filenameStub, this.keylength, partitionNumber, serialNumber, indexOrder, this.payloadrow.objectsize, true);+ array = openArrayFile(this.path, this.filenameStub, this.keylength, partitionNumber, serialNumber, wordOrder, this.payloadrow.objectsize, true);initialSpace += array.size();array.close();} catch (final IOException e) {@@ -142,7 +142,7 @@ public class IndexCollection extends AbstractIndex implements Index {}}Log.logFine("COLLECTION INDEX STARTUP", "STARTED INITIALIZATION OF NEW COLLECTION INDEX WITH " + initialSpace + " ENTRIES. THIS WILL TAKE SOME TIME. " + (MemoryControl.available() / 1024 / 1024) + "MB AVAILABLE.");- final Row indexRowdef = indexRow(keyLength, indexOrder);+ final Row indexRowdef = indexRow(keyLength, wordOrder);final long necessaryRAM4fullTable = minimumRAM4Eco + (indexRowdef.objectsize + 4) * initialSpace * 3 / 2;// initialize (new generation) index table from file@@ -150,12 +150,16 @@ public class IndexCollection extends AbstractIndex implements Index {// open array filesthis.arrays = new HashMap<String, FixedWidthArray>(); // all entries will be dynamically created with getArray()- openAllArrayFiles(true, indexOrder);+ openAllArrayFiles(true, wordOrder);Log.logFine("COLLECTION INDEX STARTUP", "FINISHED INITIALIZATION OF NEW COLLECTION INDEX.");}}- public synchronized CloneableIterator<ReferenceContainer> referenceIterator(final String startWordHash, final boolean rot, final boolean ram) {+ public ByteOrder ordering() {+ return index.row().objectOrder;+ }++ public synchronized CloneableIterator<ReferenceContainer> references(final String startWordHash, final boolean rot) {return new wordContainersIterator(startWordHash, rot);}@@ -192,11 +196,11 @@ public class IndexCollection extends AbstractIndex implements Index {}- public boolean hasReferences(final String wordHash) {+ public boolean has(final String wordHash) {return this.has(wordHash.getBytes());}- public ReferenceContainer getReferences(final String wordHash, final Set<String> urlselection) {+ public ReferenceContainer get(final String wordHash, final Set<String> urlselection) {try {final RowSet collection = this.get(wordHash.getBytes());if (collection != null) collection.select(urlselection);@@ -207,7 +211,7 @@ public class IndexCollection extends AbstractIndex implements Index {}}- public ReferenceContainer deleteAllReferences(final String wordHash) {+ public ReferenceContainer delete(final String wordHash) {try {final RowSet collection = this.delete(wordHash.getBytes());if (collection == null) return null;@@ -217,13 +221,13 @@ public class IndexCollection extends AbstractIndex implements Index {}}- public boolean removeReference(final String wordHash, final String urlHash) {+ public boolean remove(final String wordHash, final String urlHash) {final HashSet<String> hs = new HashSet<String>();hs.add(urlHash);- return removeReferences(wordHash, hs) == 1;+ return remove(wordHash, hs) == 1;}- public int removeReferences(final String wordHash, final Set<String> urlHashes) {+ public int remove(final String wordHash, final Set<String> urlHashes) {try {return this.remove(wordHash.getBytes(), urlHashes);} catch (final kelondroOutOfLimitsException e) {@@ -235,7 +239,7 @@ public class IndexCollection extends AbstractIndex implements Index {}}- public void addReferences(final ReferenceContainer newEntries) {+ public void add(final ReferenceContainer newEntries) {if (newEntries == null) return;try {this.merge(newEntries);@@ -246,7 +250,7 @@ public class IndexCollection extends AbstractIndex implements Index {}}- public void addReference(String wordhash, ReferenceRow entry) {+ public void add(String wordhash, ReferenceRow entry) {if (entry == null) return;try {this.merge(new ReferenceContainer(wordhash, entry));@@ -257,7 +261,7 @@ public class IndexCollection extends AbstractIndex implements Index {}}- public int countReferences(String key) {+ public int count(String key) {try {final RowSet collection = this.get(key.getBytes());if (collection == null) return 0;@@ -313,12 +317,12 @@ public class IndexCollection extends AbstractIndex implements Index {this.index.deleteOnExit();}- private void openAllArrayFiles(final boolean indexGeneration, final ByteOrder indexOrder) throws IOException {+ private void openAllArrayFiles(final boolean indexGeneration, final ByteOrder wordOrder) throws IOException {final String[] list = this.path.list();FixedWidthArray array;- final Row irow = indexRow(keylength, indexOrder);+ final Row irow = indexRow(keylength, wordOrder);final int t = RowCollection.daysSince2000(System.currentTimeMillis());for (int i = 0; i < list.length; i++) if (list[i].endsWith(".kca")) {@@ -329,7 +333,7 @@ public class IndexCollection extends AbstractIndex implements Index {final int partitionNumber = Integer.parseInt(list[i].substring(pos + 9, pos + 11), 16);final int serialNumber = Integer.parseInt(list[i].substring(pos + 12, pos + 14), 16);try {- array = openArrayFile(this.path, this.filenameStub, this.keylength, partitionNumber, serialNumber, indexOrder, this.payloadrow.objectsize, true);+ array = openArrayFile(this.path, this.filenameStub, this.keylength, partitionNumber, serialNumber, wordOrder, this.payloadrow.objectsize, true);} catch (final IOException e) {e.printStackTrace();continue;@@ -407,7 +411,7 @@ public class IndexCollection extends AbstractIndex implements Index {* @param path* @param filenameStub* @param keylength- * @param indexOrder+ * @param wordOrder* @param payloadrow* @return* @throws IOException@@ -416,13 +420,13 @@ public class IndexCollection extends AbstractIndex implements Index {final File path,final String filenameStub,final int keylength,- final ByteOrder indexOrder,+ final ByteOrder wordOrder,final Row payloadrow) throws IOException {final String[] list = path.list();FixedWidthArray array;System.out.println("COLLECTION INDEX REFERENCE COLLECTION startup");- IntegerHandleIndex references = new IntegerHandleIndex(keylength, indexOrder, 0, 1000000);+ IntegerHandleIndex references = new IntegerHandleIndex(keylength, wordOrder, 0, 1000000);for (int i = 0; i < list.length; i++) if (list[i].endsWith(".kca")) {// open arrayfinal int pos = list[i].indexOf('.');@@ -431,7 +435,7 @@ public class IndexCollection extends AbstractIndex implements Index {final int serialNumber = Integer.parseInt(list[i].substring(pos + 12, pos + 14), 16);System.out.println("COLLECTION INDEX REFERENCE COLLECTION opening partition " + partitionNumber + ", " + i + " of " + list.length);try {- array = openArrayFile(path, filenameStub, keylength, partitionNumber, serialNumber, indexOrder, payloadrow.objectsize, true);+ array = openArrayFile(path, filenameStub, keylength, partitionNumber, serialNumber, wordOrder, payloadrow.objectsize, true);} catch (final IOException e) {e.printStackTrace();continue;@@ -491,25 +495,27 @@ public class IndexCollection extends AbstractIndex implements Index {private static FixedWidthArray openArrayFile(File path, String filenameStub, int keylength,- final int partitionNumber, final int serialNumber, final ByteOrder indexOrder, int objectsize, final boolean create) throws IOException {+ final int partitionNumber, final int serialNumber,+ final ByteOrder wordOrder, int objectsize,+ final boolean create) throws IOException {final File f = arrayFile(path, filenameStub, loadfactor, objectsize, partitionNumber, serialNumber);final int load = arrayCapacity(partitionNumber);final Row rowdef = new Row("byte[] key-" + keylength + "," +"byte[] collection-" + (RowCollection.exportOverheadSize + load * objectsize),- indexOrder );+ wordOrder );if ((!(f.exists())) && (!create)) return null;final FixedWidthArray a = new FixedWidthArray(f, rowdef, 0);Log.logFine("STARTUP", "opened array file " + f + " with " + a.size() + " RWIs");return a;}- private FixedWidthArray getArray(final int partitionNumber, final int serialNumber, final ByteOrder indexOrder, final int chunksize) {+ private FixedWidthArray getArray(final int partitionNumber, final int serialNumber, final ByteOrder wordOrder, final int chunksize) {final String accessKey = partitionNumber + "-" + chunksize;FixedWidthArray array = arrays.get(accessKey);if (array != null) return array;try {- array = openArrayFile(this.path, this.filenameStub, this.keylength, partitionNumber, serialNumber, indexOrder, this.payloadrow.objectsize, true);+ array = openArrayFile(this.path, this.filenameStub, this.keylength, partitionNumber, serialNumber, wordOrder, this.payloadrow.objectsize, true);} catch (final IOException e) {e.printStackTrace();return null;diff --git a/source/de/anomic/kelondro/text/IndexPackage.java b/source/de/anomic/kelondro/text/IndexPackage.javadeleted file mode 100644index 66cf55837..000000000--- a/source/de/anomic/kelondro/text/IndexPackage.java+++ /dev/null@@ -1,86 +0,0 @@-// IndexPackage.java-// ------------------------------// (C) 2009 by Michael Peter Christen; [email protected], Frankfurt a. M., Germany-// first published 15.3.2009 on http://yacy.net-//-// This is a part of YaCy, a peer-to-peer based web search engine-//-// $LastChangedDate: 2006-04-02 22:40:07 +0200 (So, 02 Apr 2006) $-// $LastChangedRevision: 1986 $-// $LastChangedBy: orbiter $-//-// LICENSE-//-// This program is free software; you can redistribute it and/or modify-// it under the terms of the GNU General Public License as published by-// the Free Software Foundation; either version 2 of the License, or-// (at your option) any later version.-//-// This program is distributed in the hope that it will be useful,-// but WITHOUT ANY WARRANTY; without even the implied warranty of-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-// GNU General Public License for more details.-//-// You should have received a copy of the GNU General Public License-// along with this program; if not, write to the Free Software-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA--package de.anomic.kelondro.text;--import java.util.HashMap;-import java.util.Set;-import java.util.TreeSet;--/*- * an IndexPackage is an integration of different index types, i.e.- * - ReferenceContainerArray- * - ReferenceContainerCache- * - IndexCache (which is a wrapper of a ReferenceContainerCache)- * - IndexCollection- * This interface was created from the methods that are used in CachedIndexCollection- * (which integrates IndexCache and IndexCollection)- * and is applied to the new index integration class IndexCell- * (which integrates ReferenceContainerArray and ReferenceContainerCache)- * to make it possible to switch between the old and new index data structure- */-public interface IndexPackage extends Index {-- /*- * methods for monitoring of the cache- */-- public int maxURLinCache();-- public long minAgeOfCache();-- public long maxAgeOfCache();-- public int indexCacheSize();-- public long indexCacheSizeBytes();-- public void setMaxWordCount(final int maxWords);-- public void cacheFlushControl();-- public void flushCacheFor(int time);-- public int backendSize();-- public int cacheSize();---- /*- * methods to search the index- */-- public HashMap<String, ReferenceContainer>[] localSearchContainers(- final TreeSet<String> queryHashes,- final TreeSet<String> excludeHashes,- final Set<String> urlselection);-- public TreeSet<ReferenceContainer> indexContainerSet(final String startHash, final boolean ram, final boolean rot, int count);---}diff --git a/source/de/anomic/kelondro/text/IndexReader.java b/source/de/anomic/kelondro/text/IndexReader.javaindex c6d8add73..196838914 100644--- a/source/de/anomic/kelondro/text/IndexReader.java+++ b/source/de/anomic/kelondro/text/IndexReader.java@@ -33,9 +33,9 @@ import de.anomic.kelondro.order.CloneableIterator;public interface IndexReader {public int size();- public boolean hasReferences(String wordHash); // should only be used if in case that true is returned the getContainer is NOT called- public ReferenceContainer getReferences(String wordHash, Set<String> urlselection);- public CloneableIterator<ReferenceContainer> referenceIterator(String startWordHash, boolean rot, boolean ram);+ public boolean has(String wordHash); // should only be used if in case that true is returned the getContainer is NOT called+ public ReferenceContainer get(String wordHash, Set<String> urlselection);+ public CloneableIterator<ReferenceContainer> references(String startWordHash, boolean rot);public void close();}diff --git a/source/de/anomic/kelondro/text/ReferenceContainerArray.java b/source/de/anomic/kelondro/text/ReferenceContainerArray.javaindex 4c91a9d33..87c8dce22 100644--- a/source/de/anomic/kelondro/text/ReferenceContainerArray.java+++ b/source/de/anomic/kelondro/text/ReferenceContainerArray.java@@ -36,6 +36,7 @@ import de.anomic.kelondro.blob.BLOB;import de.anomic.kelondro.blob.BLOBArray;import de.anomic.kelondro.index.Row;import de.anomic.kelondro.index.RowSet;+import de.anomic.kelondro.order.ByteOrder;import de.anomic.kelondro.order.CloneableIterator;public final class ReferenceContainerArray {@@ -55,13 +56,14 @@ public final class ReferenceContainerArray {*/public ReferenceContainerArray(final File heapLocation,+ final ByteOrder wordOrder,final Row payloadrow) throws IOException {this.payloadrow = payloadrow;this.array = new BLOBArray(heapLocation,"index",payloadrow.primaryKeyLength,- payloadrow.getOrdering(),+ wordOrder,0);}@@ -77,6 +79,10 @@ public final class ReferenceContainerArray {return (this.array == null) ? 0 : this.array.size();}+ public ByteOrder ordering() {+ return this.array.ordering();+ }+public File newContainerBLOBFile() {return this.array.newBLOB(new Date());}diff --git a/source/de/anomic/kelondro/text/ReferenceContainerCache.java b/source/de/anomic/kelondro/text/ReferenceContainerCache.javaindex eddbb3d6c..59fad9e16 100644--- a/source/de/anomic/kelondro/text/ReferenceContainerCache.java+++ b/source/de/anomic/kelondro/text/ReferenceContainerCache.java@@ -51,6 +51,7 @@ import de.anomic.kelondro.index.RowSet;public final class ReferenceContainerCache extends AbstractIndex implements Index, IndexReader, Iterable<ReferenceContainer> {private final Row payloadrow;+ private final ByteOrder wordOrder;private SortedMap<String, ReferenceContainer> cache;/**@@ -60,8 +61,9 @@ public final class ReferenceContainerCache extends AbstractIndex implements Inde* @param payloadrow* @param log*/- public ReferenceContainerCache(final Row payloadrow) {+ public ReferenceContainerCache(final Row payloadrow, ByteOrder wordOrder) {this.payloadrow = payloadrow;+ this.wordOrder = wordOrder;this.cache = null;}@@ -83,7 +85,7 @@ public final class ReferenceContainerCache extends AbstractIndex implements Inde* another dump reading afterwards is not possible*/public void initWriteMode() {- this.cache = Collections.synchronizedSortedMap(new TreeMap<String, ReferenceContainer>(new ByteOrder.StringOrder(payloadrow.getOrdering())));+ this.cache = Collections.synchronizedSortedMap(new TreeMap<String, ReferenceContainer>(new ByteOrder.StringOrder(this.wordOrder)));}/**@@ -96,7 +98,7 @@ public final class ReferenceContainerCache extends AbstractIndex implements Indepublic void initWriteModeFromHeap(final File heapFile) throws IOException {Log.logInfo("indexContainerRAMHeap", "restoring dump for rwi heap '" + heapFile.getName() + "'");final long start = System.currentTimeMillis();- this.cache = Collections.synchronizedSortedMap(new TreeMap<String, ReferenceContainer>(new ByteOrder.StringOrder(payloadrow.getOrdering())));+ this.cache = Collections.synchronizedSortedMap(new TreeMap<String, ReferenceContainer>(new ByteOrder.StringOrder(this.wordOrder)));int urlCount = 0;synchronized (cache) {for (final ReferenceContainer container : new heapFileEntries(heapFile, this.payloadrow)) {@@ -117,7 +119,7 @@ public final class ReferenceContainerCache extends AbstractIndex implements Indepublic void initWriteModeFromBLOB(final File blobFile) throws IOException {Log.logInfo("indexContainerRAMHeap", "restoring rwi blob dump '" + blobFile.getName() + "'");final long start = System.currentTimeMillis();- this.cache = Collections.synchronizedSortedMap(new TreeMap<String, ReferenceContainer>(new ByteOrder.StringOrder(payloadrow.getOrdering())));+ this.cache = Collections.synchronizedSortedMap(new TreeMap<String, ReferenceContainer>(new ByteOrder.StringOrder(this.wordOrder)));int urlCount = 0;synchronized (cache) {for (final ReferenceContainer container : new blobFileEntries(blobFile, this.payloadrow)) {@@ -332,13 +334,13 @@ public final class ReferenceContainerCache extends AbstractIndex implements Inde* in the cache, so that manipulations of the iterated objects do not change* objects in the cache.*/- public synchronized CloneableIterator<ReferenceContainer> referenceIterator(final String startWordHash, final boolean rot, final boolean ram) {+ public synchronized CloneableIterator<ReferenceContainer> references(final String startWordHash, final boolean rot) {return new heapCacheIterator(startWordHash, rot);}public Iterator<ReferenceContainer> iterator() {- return referenceIterator(null, false, true);+ return references(null, false);}@@ -399,7 +401,7 @@ public final class ReferenceContainerCache extends AbstractIndex implements Inde* @param key* @return true, if the key is used in the heap; false othervise*/- public boolean hasReferences(final String key) {+ public boolean has(final String key) {return this.cache.containsKey(key);}@@ -408,7 +410,7 @@ public final class ReferenceContainerCache extends AbstractIndex implements Inde* @param key* @return the indexContainer if one exist, null otherwise*/- public ReferenceContainer getReferences(final String key, Set<String> urlselection) {+ public ReferenceContainer get(final String key, Set<String> urlselection) {if (urlselection == null) return this.cache.get(key);ReferenceContainer c = this.cache.get(key);if (c == null) return null;@@ -428,7 +430,7 @@ public final class ReferenceContainerCache extends AbstractIndex implements Inde* @param key* @return*/- public int countReferences(final String key) {+ public int count(final String key) {ReferenceContainer c = this.cache.get(key);if (c == null) return 0;return c.size();@@ -439,19 +441,19 @@ public final class ReferenceContainerCache extends AbstractIndex implements Inde* @param wordHash* @return the indexContainer if the cache contained the container, null othervise*/- public synchronized ReferenceContainer deleteAllReferences(final String wordHash) {+ public synchronized ReferenceContainer delete(final String wordHash) {// returns the index that had been deletedassert this.cache != null;return cache.remove(wordHash);}- public synchronized boolean removeReference(final String wordHash, final String urlHash) {+ public synchronized boolean remove(final String wordHash, final String urlHash) {assert this.cache != null;final ReferenceContainer c = cache.get(wordHash);if ((c != null) && (c.remove(urlHash) != null)) {// removal successfulif (c.size() == 0) {- deleteAllReferences(wordHash);+ delete(wordHash);} else {cache.put(wordHash, c);}@@ -460,7 +462,7 @@ public final class ReferenceContainerCache extends AbstractIndex implements Indereturn false;}- public synchronized int removeReferences(final String wordHash, final Set<String> urlHashes) {+ public synchronized int remove(final String wordHash, final Set<String> urlHashes) {assert this.cache != null;if (urlHashes.size() == 0) return 0;final ReferenceContainer c = cache.get(wordHash);@@ -468,7 +470,7 @@ public final class ReferenceContainerCache extends AbstractIndex implements Indeif ((c != null) && ((count = c.removeEntries(urlHashes)) > 0)) {// removal successfulif (c.size() == 0) {- deleteAllReferences(wordHash);+ delete(wordHash);} else {cache.put(wordHash, c);}@@ -477,7 +479,7 @@ public final class ReferenceContainerCache extends AbstractIndex implements Indereturn 0;}- public synchronized void addReferences(final ReferenceContainer container) {+ public synchronized void add(final ReferenceContainer container) {// this puts the entries into the cacheint added = 0;if ((container == null) || (container.size() == 0)) return;@@ -499,7 +501,7 @@ public final class ReferenceContainerCache extends AbstractIndex implements Indereturn;}- public synchronized void addReference(final String wordHash, final ReferenceRow newEntry) {+ public synchronized void add(final String wordHash, final ReferenceRow newEntry) {assert this.cache != null;ReferenceContainer container = cache.get(wordHash);if (container == null) container = new ReferenceContainer(wordHash, this.payloadrow, 1);@@ -511,4 +513,8 @@ public final class ReferenceContainerCache extends AbstractIndex implements Indereturn 0;}+ public ByteOrder ordering() {+ return this.wordOrder;+ }+}diff --git a/source/de/anomic/plasma/plasmaDbImporter.java b/source/de/anomic/plasma/plasmaDbImporter.javaindex 973e1a617..a02b3067a 100644--- a/source/de/anomic/plasma/plasmaDbImporter.java+++ b/source/de/anomic/plasma/plasmaDbImporter.java@@ -101,7 +101,7 @@ public class plasmaDbImporter extends AbstractImporter implements Importer {// iterate over all words from import db//Iterator importWordHashIterator = this.importWordIndex.wordHashes(this.wordChunkStartHash, plasmaWordIndex.RL_WORDFILES, false);- Iterator<ReferenceContainer> indexContainerIterator = this.importWordIndex.index().indexContainerSet(this.wordChunkStartHash, false, false, 100).iterator();+ Iterator<ReferenceContainer> indexContainerIterator = this.importWordIndex.index().references(this.wordChunkStartHash, false, 100, false).iterator();while (!isAborted() && indexContainerIterator.hasNext()) {final TreeSet<String> entityUrls = new TreeSet<String>();@@ -169,10 +169,10 @@ public class plasmaDbImporter extends AbstractImporter implements Importer {if (isAborted()) break;// importing entity container to home db- if (newContainer.size() > 0) { homeWordIndex.index().addReferences(newContainer); }+ if (newContainer.size() > 0) { homeWordIndex.index().add(newContainer); }// delete complete index entity file- this.importWordIndex.index().deleteAllReferences(this.wordHash);+ this.importWordIndex.index().delete(this.wordHash);// print out some statistical informationif (this.entryCounter % 500 == 0) {@@ -203,7 +203,7 @@ public class plasmaDbImporter extends AbstractImporter implements Importer {if (!indexContainerIterator.hasNext()) {// We may not be finished yet, try to get the next chunk of wordHashes- final TreeSet<ReferenceContainer> containers = this.importWordIndex.index().indexContainerSet(this.wordHash, false, false, 100);+ final TreeSet<ReferenceContainer> containers = this.importWordIndex.index().references(this.wordHash, false, 100, false);indexContainerIterator = containers.iterator();// Make sure we don't get the same wordhash twice, but don't skip a wordif ((indexContainerIterator.hasNext())&&(!this.wordHash.equals((indexContainerIterator.next()).getWordHash()))) {diff --git a/source/de/anomic/plasma/plasmaRankingCRProcess.java b/source/de/anomic/plasma/plasmaRankingCRProcess.javaindex 9315f133b..a9648b052 100644--- a/source/de/anomic/plasma/plasmaRankingCRProcess.java+++ b/source/de/anomic/plasma/plasmaRankingCRProcess.java@@ -381,7 +381,7 @@ public class plasmaRankingCRProcess {final int size = seq.size();final long start = System.currentTimeMillis();long l;- final CloneableIterator<ReferenceContainer> i = seq.referenceIterator(null, false, false);+ final CloneableIterator<ReferenceContainer> i = seq.references(null, false);ReferenceContainer keycollection;String referee, refereeDom, anchor, anchorDom;RowSet rci_entry;@@ -400,7 +400,7 @@ public class plasmaRankingCRProcess {if (anchor.length() == 6) anchorDom = anchor; else anchorDom = anchor.substring(6);// update domain-specific entry- rci_entry = rci.getReferences(anchorDom, null);+ rci_entry = rci.get(anchorDom, null);if (rci_entry == null) rci_entry = new RowSet(RCI_coli, 0);rci_entry.add(refereeDom.getBytes());diff --git a/source/de/anomic/plasma/plasmaSearchEvent.java b/source/de/anomic/plasma/plasmaSearchEvent.javaindex 07002dd04..ca4f10ba5 100644--- a/source/de/anomic/plasma/plasmaSearchEvent.java+++ b/source/de/anomic/plasma/plasmaSearchEvent.java@@ -251,7 +251,7 @@ public final class plasmaSearchEvent {final Set<String> removeWords = cleanEvent.query.queryHashes;removeWords.addAll(cleanEvent.query.excludeHashes);try {- cleanEvent.wordIndex.index().removeEntriesMultiple(removeWords, cleanEvent.failedURLs.keySet());+ cleanEvent.wordIndex.index().remove(removeWords, cleanEvent.failedURLs.keySet());} catch (IOException e) {e.printStackTrace();}@@ -307,7 +307,7 @@ public final class plasmaSearchEvent {(query.constraint.get(plasmaCondenser.flag_cat_indexof)) &&(!(metadata.dc_title().startsWith("Index of")))) {final Iterator<String> wi = query.queryHashes.iterator();- while (wi.hasNext()) try { wordIndex.index().removeReference(wi.next(), page.hash()); } catch (IOException e) {}+ while (wi.hasNext()) try { wordIndex.index().remove(wi.next(), page.hash()); } catch (IOException e) {}registerFailure(page.hash(), "index-of constraint not fullfilled");return null;}@@ -836,7 +836,7 @@ public final class plasmaSearchEvent {if ((seed == null) || ((address = seed.getPublicAddress()) == null)) {// seed is not known from heretry {- wordIndex.index().removeEntryMultiple(+ wordIndex.index().remove(Word.words2hashes(plasmaCondenser.getWords(("yacyshare " +filename.replace('?', ' ') +diff --git a/source/de/anomic/plasma/plasmaSearchRankingProcess.java b/source/de/anomic/plasma/plasmaSearchRankingProcess.javaindex 19ed465ec..b1514db82 100644--- a/source/de/anomic/plasma/plasmaSearchRankingProcess.java+++ b/source/de/anomic/plasma/plasmaSearchRankingProcess.java@@ -110,7 +110,7 @@ public final class plasmaSearchRankingProcess {public void execQuery() {long timer = System.currentTimeMillis();- this.localSearchContainerMaps = wordIndex.index().localSearchContainers(query.queryHashes, query.excludeHashes, null);+ this.localSearchContainerMaps = wordIndex.localSearchContainers(query.queryHashes, query.excludeHashes, null);serverProfiling.update("SEARCH", new plasmaProfiling.searchEvent(query.id(true), plasmaSearchEvent.COLLECTION, this.localSearchContainerMaps[0].size(), System.currentTimeMillis() - timer), false);// join and exclude the local resultdiff --git a/source/de/anomic/plasma/plasmaSnippetCache.java b/source/de/anomic/plasma/plasmaSnippetCache.javaindex c0c54270e..00d1fe464 100644--- a/source/de/anomic/plasma/plasmaSnippetCache.java+++ b/source/de/anomic/plasma/plasmaSnippetCache.java@@ -952,12 +952,12 @@ public class plasmaSnippetCache {assert plasmaSwitchboard.getSwitchboard().webIndex != null;assert event != null : "eventID = " + eventID;assert event.getQuery() != null;- plasmaSwitchboard.getSwitchboard().webIndex.index().removeEntryMultiple(event.getQuery().queryHashes, urlHash);+ plasmaSwitchboard.getSwitchboard().webIndex.index().remove(event.getQuery().queryHashes, urlHash);event.remove(urlHash);}if (snippet.getErrorCode() == ERROR_NO_MATCH) {log.logInfo("error: '" + snippet.getError() + "', remove words '" + querystring + "' for url = " + snippet.getUrl().toNormalform(false, true) + ", cause: " + snippet.getError());- plasmaSwitchboard.getSwitchboard().webIndex.index().removeEntryMultiple(snippet.remaingHashes, urlHash);+ plasmaSwitchboard.getSwitchboard().webIndex.index().remove(snippet.remaingHashes, urlHash);plasmaSearchEvent.getEvent(eventID).remove(urlHash);}return snippet.getError();diff --git a/source/de/anomic/plasma/plasmaSwitchboard.java b/source/de/anomic/plasma/plasmaSwitchboard.javaindex dda627d8f..9b732fec1 100644--- a/source/de/anomic/plasma/plasmaSwitchboard.java+++ b/source/de/anomic/plasma/plasmaSwitchboard.java@@ -1120,12 +1120,12 @@ public final class plasmaSwitchboard extends serverAbstractSwitch<IndexingStack.}public int rwiCacheSize() {- return webIndex.index().cacheSize();+ return webIndex.index().getBufferSize();}public boolean rwiCacheFlush() {if (rwiCacheSize() == 0) return false;- webIndex.index().flushCacheFor((int) ((this.getConfigLong(plasmaSwitchboardConstants.CACHEFLUSH_BUSYSLEEP, 10000) * this.getConfigLong("performanceIO", 10)) / 100));+ webIndex.index().cleanupBuffer((int) ((this.getConfigLong(plasmaSwitchboardConstants.CACHEFLUSH_BUSYSLEEP, 10000) * this.getConfigLong("performanceIO", 10)) / 100));return true;}@@ -1144,7 +1144,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch<IndexingStack.public void deQueueFreeMem() {// flush some entries from the RAM cache- webIndex.index().flushCacheFor(5000);+ webIndex.index().cleanupBuffer(5000);// empty some cacheswebIndex.metadata().clearCache();plasmaSearchEvent.cleanupEvents(true);@@ -1773,7 +1773,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch<IndexingStack.// delete all word referencesint count = 0;- if (words != null) count = webIndex.index().removeEntryMultiple(Word.words2hashes(words), urlhash);+ if (words != null) count = webIndex.index().remove(Word.words2hashes(words), urlhash);// finally delete the url entry itselfwebIndex.metadata().remove(urlhash);diff --git a/source/de/anomic/plasma/plasmaWordIndex.java b/source/de/anomic/plasma/plasmaWordIndex.javaindex a64e87424..e05107a20 100644--- a/source/de/anomic/plasma/plasmaWordIndex.java+++ b/source/de/anomic/plasma/plasmaWordIndex.java@@ -29,17 +29,21 @@ package de.anomic.plasma;import java.io.File;import java.io.IOException;import java.util.Date;+import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.Map;+import java.util.Set;import java.util.TreeSet;import de.anomic.crawler.CrawlProfile;import de.anomic.crawler.IndexingStack;import de.anomic.htmlFilter.htmlFilterContentScraper;import de.anomic.http.httpdProxyCacheEntry;-import de.anomic.kelondro.text.CachedIndexCollection;-import de.anomic.kelondro.text.IndexPackage;+import de.anomic.kelondro.order.Base64Order;+import de.anomic.kelondro.order.ByteOrder;+import de.anomic.kelondro.text.BufferedIndexCollection;+import de.anomic.kelondro.text.BufferedIndex;import de.anomic.kelondro.text.MetadataRowContainer;import de.anomic.kelondro.text.ReferenceContainer;import de.anomic.kelondro.text.ReferenceRow;@@ -77,8 +81,9 @@ public final class plasmaWordIndex {public static final long CRAWL_PROFILE_SNIPPET_LOCAL_MEDIA_RECRAWL_CYCLE = 60L * 24L * 30L;public static final long CRAWL_PROFILE_SNIPPET_GLOBAL_MEDIA_RECRAWL_CYCLE = 60L * 24L * 30L;+ public static final ByteOrder wordOrder = Base64Order.enhancedCoder;- private final IndexPackage index;+ private final BufferedIndex index;private final Log log;private MetadataRepository metadata;private final yacySeedDB peers;@@ -123,8 +128,10 @@ public final class plasmaWordIndex {}}}- this.index = new CachedIndexCollection(+ this.index = new BufferedIndexCollection(indexPrimaryTextLocation,+ wordOrder,+ ReferenceRow.urlEntryRow,entityCacheMaxSize,useCommons,redundancy,@@ -212,7 +219,7 @@ public final class plasmaWordIndex {return this.peers;}- public IndexPackage index() {+ public BufferedIndex index() {return this.index;}@@ -385,7 +392,7 @@ public final class plasmaWordIndex {outlinksSame, outlinksOther,wprop.flags);try {- this.index.addReference(Word.word2hash(word), ientry);+ this.index.add(Word.word2hash(word), ientry);} catch (IOException e) {e.printStackTrace();}@@ -517,6 +524,58 @@ public final class plasmaWordIndex {return newEntry;}+ @SuppressWarnings("unchecked")+ public HashMap<String, ReferenceContainer>[] localSearchContainers(+ final TreeSet<String> queryHashes,+ final TreeSet<String> excludeHashes,+ final Set<String> urlselection) {+ // search for the set of hashes and return a map of of wordhash:indexContainer containing the seach result++ // retrieve entities that belong to the hashes+ HashMap<String, ReferenceContainer> inclusionContainers = (queryHashes.size() == 0) ? new HashMap<String, ReferenceContainer>(0) : getContainers(+ queryHashes,+ urlselection);+ if ((inclusionContainers.size() != 0) && (inclusionContainers.size() < queryHashes.size())) inclusionContainers = new HashMap<String, ReferenceContainer>(0); // prevent that only a subset is returned+ final HashMap<String, ReferenceContainer> exclusionContainers = (inclusionContainers.size() == 0) ? new HashMap<String, ReferenceContainer>(0) : getContainers(+ excludeHashes,+ urlselection);+ return new HashMap[]{inclusionContainers, exclusionContainers};+ }++ /**+ * collect containers for given word hashes. This collection stops if a single container does not contain any references.+ * In that case only a empty result is returned.+ * @param wordHashes+ * @param urlselection+ * @return map of wordhash:indexContainer+ */+ private HashMap<String, ReferenceContainer> getContainers(final Set<String> wordHashes, final Set<String> urlselection) {+ // retrieve entities that belong to the hashes+ final HashMap<String, ReferenceContainer> containers = new HashMap<String, ReferenceContainer>(wordHashes.size());+ String singleHash;+ ReferenceContainer singleContainer;+ final Iterator<String> i = wordHashes.iterator();+ while (i.hasNext()) {++ // get next word hash:+ singleHash = i.next();++ // retrieve index+ try {+ singleContainer = index.get(singleHash, urlselection);+ } catch (IOException e) {+ e.printStackTrace();+ continue;+ }++ // check result+ if ((singleContainer == null || singleContainer.size() == 0)) return new HashMap<String, ReferenceContainer>(0);++ containers.put(singleHash, singleContainer);+ }+ return containers;+ }+// The Cleaner class was provided as "UrldbCleaner" by Hydroxpublic synchronized ReferenceCleaner getReferenceCleaner(final String startHash) {return new ReferenceCleaner(startHash);@@ -543,46 +602,50 @@ public final class plasmaWordIndex {ReferenceRow entry = null;yacyURL url = null;final HashSet<String> urlHashs = new HashSet<String>();- Iterator<ReferenceContainer> indexContainerIterator = index.indexContainerSet(startHash, false, false, 100).iterator();- while (indexContainerIterator.hasNext() && run) {- waiter();- container = indexContainerIterator.next();- final Iterator<ReferenceRow> containerIterator = container.entries();- wordHashNow = container.getWordHash();- while (containerIterator.hasNext() && run) {+ try {+ Iterator<ReferenceContainer> indexContainerIterator = index.references(startHash, false, 100, false).iterator();+ while (indexContainerIterator.hasNext() && run) {waiter();- entry = containerIterator.next();- // System.out.println("Wordhash: "+wordHash+" UrlHash:- // "+entry.getUrlHash());- final MetadataRowContainer ue = metadata.load(entry.urlHash(), entry, 0);- if (ue == null) {- urlHashs.add(entry.urlHash());- } else {- url = ue.metadata().url();- if ((url == null) || (plasmaSwitchboard.urlBlacklist.isListed(Blacklist.BLACKLIST_CRAWLER, url) == true)) {+ container = indexContainerIterator.next();+ final Iterator<ReferenceRow> containerIterator = container.entries();+ wordHashNow = container.getWordHash();+ while (containerIterator.hasNext() && run) {+ waiter();+ entry = containerIterator.next();+ // System.out.println("Wordhash: "+wordHash+" UrlHash:+ // "+entry.getUrlHash());+ final MetadataRowContainer ue = metadata.load(entry.urlHash(), entry, 0);+ if (ue == null) {urlHashs.add(entry.urlHash());+ } else {+ url = ue.metadata().url();+ if ((url == null) || (plasmaSwitchboard.urlBlacklist.isListed(Blacklist.BLACKLIST_CRAWLER, url) == true)) {+ urlHashs.add(entry.urlHash());+ }}}- }- if (urlHashs.size() > 0) try {- final int removed = index.removeReferences(container.getWordHash(), urlHashs);- Log.logFine("INDEXCLEANER", container.getWordHash() + ": " + removed + " of " + container.size() + " URL-entries deleted");- lastWordHash = container.getWordHash();- lastDeletionCounter = urlHashs.size();- urlHashs.clear();- } catch (IOException e) {- e.printStackTrace();- }-- if (!containerIterator.hasNext()) {- // We may not be finished yet, try to get the next chunk of wordHashes- final TreeSet<ReferenceContainer> containers = index.indexContainerSet(container.getWordHash(), false, false, 100);- indexContainerIterator = containers.iterator();- // Make sure we don't get the same wordhash twice, but don't skip a word- if ((indexContainerIterator.hasNext()) && (!container.getWordHash().equals(indexContainerIterator.next().getWordHash()))) {+ if (urlHashs.size() > 0) try {+ final int removed = index.remove(container.getWordHash(), urlHashs);+ Log.logFine("INDEXCLEANER", container.getWordHash() + ": " + removed + " of " + container.size() + " URL-entries deleted");+ lastWordHash = container.getWordHash();+ lastDeletionCounter = urlHashs.size();+ urlHashs.clear();+ } catch (IOException e) {+ e.printStackTrace();+ }++ if (!containerIterator.hasNext()) {+ // We may not be finished yet, try to get the next chunk of wordHashes+ final TreeSet<ReferenceContainer> containers = index.references(container.getWordHash(), false, 100, false);indexContainerIterator = containers.iterator();+ // Make sure we don't get the same wordhash twice, but don't skip a word+ if ((indexContainerIterator.hasNext()) && (!container.getWordHash().equals(indexContainerIterator.next().getWordHash()))) {+ indexContainerIterator = containers.iterator();+ }}}+ } catch (IOException e) {+ e.printStackTrace();}Log.logInfo("INDEXCLEANER", "IndexCleaner-Thread stopped");}diff --git a/source/de/anomic/yacy/dht/Dispatcher.java b/source/de/anomic/yacy/dht/Dispatcher.javaindex 5542f7429..b23d57a0a 100755--- a/source/de/anomic/yacy/dht/Dispatcher.java+++ b/source/de/anomic/yacy/dht/Dispatcher.java@@ -33,7 +33,7 @@ import java.util.Iterator;import java.util.Map;import de.anomic.kelondro.order.Base64Order;-import de.anomic.kelondro.text.Index;+import de.anomic.kelondro.text.BufferedIndex;import de.anomic.kelondro.text.ReferenceContainer;import de.anomic.kelondro.text.ReferenceRow;import de.anomic.kelondro.text.MetadataRepository;@@ -81,7 +81,7 @@ public class Dispatcher {private HashMap<String, Transmission.Chunk> transmissionCloud;// the backend is used to store the remaining indexContainers in case that the object is closed- private Index backend;+ private BufferedIndex backend;// the seed databaseprivate yacySeedDB seeds;@@ -96,7 +96,7 @@ public class Dispatcher {private Transmission transmission;public Dispatcher(- final Index backend,+ final BufferedIndex backend,final MetadataRepository repository,final yacySeedDB seeds,final boolean gzipBody,@@ -168,7 +168,7 @@ public class Dispatcher {final ArrayList<ReferenceContainer> containers = new ArrayList<ReferenceContainer>(maxContainerCount);- final Iterator<ReferenceContainer> indexContainerIterator = this.backend.referenceIterator(hash, true, ram);+ final Iterator<ReferenceContainer> indexContainerIterator = this.backend.references(hash, true, ram);ReferenceContainer container;int refcount = 0;@@ -198,7 +198,7 @@ public class Dispatcher {urlHashes.add(it.next().urlHash());}if (this.log.isFine()) this.log.logFine("selected " + urlHashes.size() + " urls for word '" + c.getWordHash() + "'");- if (urlHashes.size() > 0) this.backend.removeReferences(c.getWordHash(), urlHashes);+ if (urlHashes.size() > 0) this.backend.remove(c.getWordHash(), urlHashes);}// finished. The caller must take care of the containers and must put them back if not needed@@ -375,7 +375,7 @@ public class Dispatcher {if (indexingTransmissionProcessor != null) this.indexingTransmissionProcessor.announceShutdown();if (this.transmissionCloud != null) {for (Map.Entry<String, Transmission.Chunk> e : this.transmissionCloud.entrySet()) {- for (ReferenceContainer i : e.getValue()) try {this.backend.addReferences(i);} catch (IOException e1) {}+ for (ReferenceContainer i : e.getValue()) try {this.backend.add(i);} catch (IOException e1) {}}this.transmissionCloud.clear();}diff --git a/source/de/anomic/yacy/dht/Transmission.java b/source/de/anomic/yacy/dht/Transmission.javaindex e7f4351fa..c12e87f41 100644--- a/source/de/anomic/yacy/dht/Transmission.java+++ b/source/de/anomic/yacy/dht/Transmission.java@@ -38,6 +38,7 @@ import de.anomic.kelondro.text.ReferenceContainerCache;import de.anomic.kelondro.text.ReferenceRow;import de.anomic.kelondro.text.MetadataRepository;import de.anomic.kelondro.util.Log;+import de.anomic.plasma.plasmaWordIndex;import de.anomic.server.serverProcessorJob;import de.anomic.yacy.yacyClient;import de.anomic.yacy.yacySeed;@@ -106,7 +107,7 @@ public class Transmission {final Row payloadrow) {super();this.primaryTarget = primaryTarget;- this.containers = new ReferenceContainerCache(payloadrow);+ this.containers = new ReferenceContainerCache(payloadrow, plasmaWordIndex.wordOrder);this.containers.initWriteMode();this.references = new HashMap<String, MetadataRowContainer>();this.badReferences = new HashSet<String>();@@ -138,7 +139,7 @@ public class Transmission {// now delete all references that were not foundfor (String s : notFound) container.remove(s);// finally add the remaining container to the cache- containers.addReferences(container);+ containers.add(container);}/**@@ -235,7 +236,7 @@ public class Transmission {}public void restore() {- for (ReferenceContainer ic : this) try { backend.addReferences(ic); } catch (IOException e) {}+ for (ReferenceContainer ic : this) try { backend.add(ic); } catch (IOException e) {}}}}diff --git a/source/de/anomic/yacy/yacyClient.java b/source/de/anomic/yacy/yacyClient.javaindex 449d26ee3..227773cc7 100644--- a/source/de/anomic/yacy/yacyClient.java+++ b/source/de/anomic/yacy/yacyClient.java@@ -638,7 +638,7 @@ public final class yacyClient {// insert the containers to the indexfor (int m = 0; m < words; m++) try {- wordIndex.index().addReferences(container[m]);+ wordIndex.index().add(container[m]);} catch (IOException e) {e.printStackTrace();}diff --git a/source/yacy.java b/source/yacy.javaindex fd05ca690..5074444f9 100644--- a/source/yacy.java+++ b/source/yacy.java@@ -676,7 +676,7 @@ public final class yacy {if (cacheMem < 2048000) throw new OutOfMemoryError("Not enough memory available to start clean up.");final plasmaWordIndex wordIndex = new plasmaWordIndex(networkName, log, indexPrimaryRoot, indexSecondaryRoot, 10000, false, 1, 0);- final Iterator<ReferenceContainer> indexContainerIterator = wordIndex.index().referenceIterator("AAAAAAAAAAAA", false, false);+ final Iterator<ReferenceContainer> indexContainerIterator = wordIndex.index().references("AAAAAAAAAAAA", false, false);long urlCounter = 0, wordCounter = 0;long wordChunkStart = System.currentTimeMillis(), wordChunkEnd = 0;@@ -867,7 +867,7 @@ public final class yacy {Iterator<ReferenceContainer> indexContainerIterator = null;if (resource.equals("all")) {WordIndex = new plasmaWordIndex("freeworld", log, indexPrimaryRoot, indexSecondaryRoot, 10000, false, 1, 0);- indexContainerIterator = WordIndex.index().referenceIterator(wordChunkStartHash, false, false);+ indexContainerIterator = WordIndex.index().references(wordChunkStartHash, false, false);}int counter = 0;ReferenceContainer container = null;