Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
added rules to set specific RWIs as private RWIs which are not transmitted to remote peers. This will be used for private index copies and phonetic indexes.
Michael Christene9dc99fe151f
diff --git a/htroot/IndexControlRWIs_p.java b/htroot/IndexControlRWIs_p.javaindex 619309d3d..adf2ee61c 100644--- a/htroot/IndexControlRWIs_p.java+++ b/htroot/IndexControlRWIs_p.java@@ -377,7 +377,7 @@ public class IndexControlRWIs_pif ( post.containsKey("keyhashsimilar") ) {try {final Iterator<ReferenceContainer<WordReference>> containerIt =- segment.termIndex().referenceContainer(keyhash, true, 256, false).iterator();+ segment.termIndex().referenceContainer(keyhash, true, false, 256, false).iterator();ReferenceContainer<WordReference> container;i = 0;int rows = 0, cols = 0;diff --git a/htroot/api/termlist_p.java b/htroot/api/termlist_p.javaindex f98c87002..4cc86a547 100644--- a/htroot/api/termlist_p.java+++ b/htroot/api/termlist_p.java@@ -50,7 +50,7 @@ public class termlist_p {segment = sb.indexSegments.segment(post.get("segment"));}if (segment == null) segment = sb.indexSegments.segment(Segments.Process.PUBLIC);- final Iterator<Rating<byte[]>> i = segment.termIndex().referenceCountIterator(null, false);+ final Iterator<Rating<byte[]>> i = segment.termIndex().referenceCountIterator(null, false, false);Rating<byte[]> e;int c = 0, termnumber = 0;byte[] termhash, maxterm = null;diff --git a/source/net/yacy/kelondro/blob/Heap.java b/source/net/yacy/kelondro/blob/Heap.javaindex 7b3ac75a2..0eb79de12 100755--- a/source/net/yacy/kelondro/blob/Heap.java+++ b/source/net/yacy/kelondro/blob/Heap.java@@ -125,12 +125,12 @@ public final class Heap extends HeapModifier implements BLOB {*/@Overridepublic boolean containsKey(byte[] key) {- assert index != null;+ assert this.index != null;key = normalizeKey(key);synchronized (this) {// check the buffer- assert buffer != null;- if (buffer != null) {+ assert this.buffer != null;+ if (this.buffer != null) {if (this.buffer.containsKey(key)) return true;}return super.containsKey(key);@@ -147,13 +147,13 @@ public final class Heap extends HeapModifier implements BLOB {private void add(byte[] key, final byte[] blob) throws IOException {assert blob.length > 0;if ((blob == null) || (blob.length == 0)) return;- final int pos = (int) file.length();+ final int pos = (int) this.file.length();try {- index.put(key, pos);- file.seek(pos);- file.writeInt(this.keylength + blob.length);- file.write(key);- file.write(blob, 0, blob.length);+ this.index.put(key, pos);+ this.file.seek(pos);+ this.file.writeInt(this.keylength + blob.length);+ this.file.write(key);+ this.file.write(blob, 0, blob.length);} catch (RowSpaceExceededException e) {throw new IOException(e.getMessage()); // should never occur;}@@ -166,8 +166,8 @@ public final class Heap extends HeapModifier implements BLOB {* @throws RowSpaceExceededException*/public void flushBuffer() throws IOException {- assert buffer != null;- if (buffer == null) return;+ assert this.buffer != null;+ if (this.buffer == null) return;// check size of bufferIterator<Map.Entry<byte[], byte[]>> i = this.buffer.entrySet().iterator();@@ -196,18 +196,18 @@ public final class Heap extends HeapModifier implements BLOB {// append all contents of the buffer into one byte[]i = this.buffer.entrySet().iterator();- final long pos = file.length();+ final long pos = this.file.length();long posFile = pos;posBuffer = 0;byte[] ba = new byte[l + (4 + this.keylength) * this.buffer.size()];byte[] b;- SortedMap<byte[], byte[]> nextBuffer = new TreeMap<byte[], byte[]>(ordering);+ SortedMap<byte[], byte[]> nextBuffer = new TreeMap<byte[], byte[]>(this.ordering);flush: while (i.hasNext()) {entry = i.next();key = normalizeKey(entry.getKey());blob = entry.getValue();try {- index.put(key, posFile);+ this.index.put(key, posFile);} catch (RowSpaceExceededException e) {nextBuffer.put(entry.getKey(), blob);continue flush;@@ -245,8 +245,8 @@ public final class Heap extends HeapModifier implements BLOB {synchronized (this) {// check the buffer- assert buffer != null;- if (buffer != null) {+ assert this.buffer != null;+ if (this.buffer != null) {byte[] blob = this.buffer.get(key);if (blob != null) return blob;}@@ -267,8 +267,8 @@ public final class Heap extends HeapModifier implements BLOB {synchronized (this) {// check the buffer- assert buffer != null;- if (buffer != null) {+ assert this.buffer != null;+ if (this.buffer != null) {byte[] blob = this.buffer.get(key);if (blob != null) return blob.length;}@@ -284,8 +284,8 @@ public final class Heap extends HeapModifier implements BLOB {@Overridepublic synchronized void clear() throws IOException {Log.logInfo("Heap", "clearing heap " + this.name());- assert buffer != null;- if (buffer == null) buffer = new TreeMap<byte[], byte[]>(ordering);+ assert this.buffer != null;+ if (this.buffer == null) this.buffer = new TreeMap<byte[], byte[]>(this.ordering);this.buffer.clear();this.buffersize = 0;super.clear();@@ -297,7 +297,7 @@ public final class Heap extends HeapModifier implements BLOB {@Overridepublic synchronized void close(final boolean writeIDX) {Log.logInfo("Heap", "closing heap " + this.name());- if (file != null && buffer != null) {+ if (this.file != null && this.buffer != null) {try {flushBuffer();} catch (IOException e) {@@ -306,7 +306,7 @@ public final class Heap extends HeapModifier implements BLOB {}this.buffer = null;super.close(writeIDX);- assert file == null;+ assert this.file == null;}@Override@@ -351,11 +351,11 @@ public final class Heap extends HeapModifier implements BLOB {assert this.buffer != null;// if there is not enough space in the buffer, flush all- if (this.buffersize + b.length > buffermax || MemoryControl.shortStatus()) {+ if (this.buffersize + b.length > this.buffermax || MemoryControl.shortStatus()) {// this is too big. Flush everythingsuper.shrinkWithGapsAtEnd();flushBuffer();- if (b.length > buffermax) {+ if (b.length > this.buffermax) {this.add(key, b);} else {if (this.buffer != null) {@@ -387,6 +387,7 @@ public final class Heap extends HeapModifier implements BLOB {final int reclen = b.length + this.keylength;Map.Entry<Long, Integer> entry;Iterator<Map.Entry<Long, Integer>> i = this.free.entrySet().iterator();+ int acount = 0, bcount = 0;while (i.hasNext()) {entry = i.next();if (entry.getValue().intValue() == reclen) {@@ -397,14 +398,14 @@ public final class Heap extends HeapModifier implements BLOB {this.index.put(key, entry.getKey());// write to file- file.seek(entry.getKey().longValue());- final int reclenf = file.readInt();+ this.file.seek(entry.getKey().longValue());+ final int reclenf = this.file.readInt();assert reclenf == reclen;- file.write(key);+ this.file.write(key);if (this.keylength > key.length) {- for (int j = 0; j < this.keylength - key.length; j++) file.write(HeapWriter.ZERO);+ for (int j = 0; j < this.keylength - key.length; j++) this.file.write(HeapWriter.ZERO);}- file.write(b);+ this.file.write(b);// remove the entry from the free listi.remove();@@ -414,10 +415,13 @@ public final class Heap extends HeapModifier implements BLOB {// finished!return true;}+ acount++;// look for the biggest size- if (entry.getValue() > lsize) {+ if (entry.getValue().intValue() > lsize) {lseek = entry.getKey();lsize = entry.getValue();+ bcount++;+ if (acount > 100 || bcount > 10) break; // in case that we have really a lot break here}}@@ -429,21 +433,21 @@ public final class Heap extends HeapModifier implements BLOB {// data structure in the file// write the new entry- file.seek(lseek);- file.writeInt(reclen);- file.write(key);+ this.file.seek(lseek);+ this.file.writeInt(reclen);+ this.file.write(key);if (this.keylength > key.length) {- for (int j = 0; j < this.keylength - key.length; j++) file.write(HeapWriter.ZERO);+ for (int j = 0; j < this.keylength - key.length; j++) this.file.write(HeapWriter.ZERO);}- file.write(b);+ this.file.write(b);// add the index to the new entry- index.put(key, lseek);+ this.index.put(key, lseek);// define the new empty entryfinal int newfreereclen = lsize - reclen - 4;assert newfreereclen > 0;- file.writeInt(newfreereclen);+ this.file.writeInt(newfreereclen);// remove the old free entrythis.free.remove(lseek);@@ -473,8 +477,8 @@ public final class Heap extends HeapModifier implements BLOB {super.deleteFingerprint();// check the buffer- assert buffer != null;- if (buffer != null) {+ assert this.buffer != null;+ if (this.buffer != null) {byte[] blob = this.buffer.remove(key);if (blob != null) {this.buffersize -= blob.length;diff --git a/source/net/yacy/kelondro/data/meta/URIMetadataRow.java b/source/net/yacy/kelondro/data/meta/URIMetadataRow.javaindex 7deb02a02..4f1fcb564 100644--- a/source/net/yacy/kelondro/data/meta/URIMetadataRow.java+++ b/source/net/yacy/kelondro/data/meta/URIMetadataRow.java@@ -428,7 +428,7 @@ public class URIMetadataRow implements URIMetadata {public byte[] language() {byte[] b = this.entry.getColBytes(col_lang, true);- if (b[0] == (byte)'[') {+ if (b == null || b[0] == (byte)'[') {String tld = this.metadata().url.getTLD();if (tld.length() < 2 || tld.length() > 2) return ASCII.getBytes("en");return ASCII.getBytes(tld);diff --git a/source/net/yacy/kelondro/data/word/Word.java b/source/net/yacy/kelondro/data/word/Word.javaindex b90f8df89..b4986d0dd 100644--- a/source/net/yacy/kelondro/data/word/Word.java+++ b/source/net/yacy/kelondro/data/word/Word.java@@ -116,6 +116,13 @@ public class Word {return word2hash(word.toString());}+ private final static byte lowByte = Base64Order.alpha_enhanced[0];+ private final static byte highByte = Base64Order.alpha_enhanced[Base64Order.alpha_enhanced.length - 1];++ public static boolean isPrivate(byte[] hash) {+ return hash[0] == highByte && hash[1] == highByte && hash[2] == highByte && hash[3] == highByte && hash[4] == highByte;+ }+// create a word hashpublic static final byte[] word2hash(final String word) {final String wordlc = word.toLowerCase(Locale.ENGLISH);@@ -123,6 +130,12 @@ public class Word {if (h != null) return h;// calculate the hashh = Base64Order.enhancedCoder.encodeSubstring(Digest.encodeMD5Raw(wordlc), commonHashLength);+ while (h[0] == highByte && h[1] == highByte && h[2] == highByte && h[3] == highByte && h[4] == highByte) {+ // ensure that word hashes do not start with hash '_____' which is a key for an extra hash range for private usage on the local peer+ // statistically we are inside this loop only every 2^^30 calls of word2hash (which means almost never)+ System.arraycopy(h, 1, h, 0, commonHashLength - 1);+ h[commonHashLength - 1] = lowByte;+ }assert h[2] != '@';if (MemoryControl.shortStatus()) {hashCache.clear();@@ -133,6 +146,16 @@ public class Word {return h;}+ public final static byte PRIVATE_TYPE_COPY = 'C'; // used for a private local copy of the index+ public final static byte PRIVATE_TYPE_PHONETIC = 'K'; // used for ColognePhonetics++ public static final byte[] hash2private(final byte[] hash, byte privateType) {+ byte[] p = new byte[commonHashLength];+ p[0] = highByte; p[1] = highByte; p[2] = highByte; ; p[3] = highByte; ; p[4] = highByte; p[5] = privateType;+ System.arraycopy(hash, 0, p, 6, commonHashLength - 6); // 36 bits left for private hashes should be enough+ return p;+ }+public static final HandleSet words2hashesHandles(final Set<String> words) {final HandleSet hashes = new HandleSet(WordReferenceRow.urlEntryRow.primaryKeyLength, WordReferenceRow.urlEntryRow.objectOrder, words.size());for (final String word: words)diff --git a/source/net/yacy/kelondro/order/Base64Order.java b/source/net/yacy/kelondro/order/Base64Order.javaindex 5b462a24f..d264be900 100644--- a/source/net/yacy/kelondro/order/Base64Order.java+++ b/source/net/yacy/kelondro/order/Base64Order.java@@ -36,10 +36,10 @@ import net.yacy.cora.ranking.Order;public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Comparator<byte[]>, Cloneable {- protected static final byte[] alpha_standard = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".getBytes();- protected static final byte[] alpha_enhanced = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".getBytes();- protected static final byte[] ahpla_standard = new byte[128];- protected static final byte[] ahpla_enhanced = new byte[128];+ public static final byte[] alpha_standard = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".getBytes();+ public static final byte[] alpha_enhanced = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".getBytes();+ private static final byte[] ahpla_standard = new byte[128];+ private static final byte[] ahpla_enhanced = new byte[128];static {for (int i = 0; i < 128; i++) {@@ -92,16 +92,19 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Comreturn z;}+ @Overridepublic Order<byte[]> clone() {final Base64Order o = new Base64Order(this.asc, this.rfc1113compliant);o.rotate(this.zero);return o;}+ @Overridepublic final boolean wellformed(final byte[] a) {return wellformed(a, 0, a.length);}+ @Overridepublic final boolean wellformed(final byte[] a, final int astart, final int alength) {assert (astart + alength <= a.length) : "astart = " + astart + ", alength = " + alength + ", a.length = " + a.length;int b;@@ -120,6 +123,7 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Comreturn null;}+ @Overridepublic final String signature() {if ((!this.asc) && (!this.rfc1113compliant)) return "Bd";if ((!this.asc) && ( this.rfc1113compliant)) return "bd";@@ -347,6 +351,7 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Comreturn b;}+ @Overridepublic final long cardinal(final byte[] key) {if (this.zero == null) return cardinalI(key, 0, key.length);final long zeroCardinal = cardinalI(this.zero, 0, this.zero.length);@@ -355,6 +360,7 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Comreturn Long.MAX_VALUE - keyCardinal + zeroCardinal;}+ @Overridepublic final long cardinal(final byte[] key, final int off, final int len) {if (this.zero == null) return cardinalI(key, off, len);final long zeroCardinal = cardinalI(this.zero, 0, this.zero.length);@@ -375,6 +381,7 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Comreturn (x > 0) ? 1 : (x < 0) ? -1 : 0;}+ @Overridepublic final boolean equal(final byte[] a, final byte[] b) {if ((a == null) && (b == null)) return true;if ((a == null) || (b == null)) return false;@@ -388,6 +395,7 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Comreturn true;}+ @Overridepublic final boolean equal(final byte[] a, int astart, final byte[] b, int bstart, int length) {if ((a == null) && (b == null)) return true;if ((a == null) || (b == null)) return false;@@ -397,6 +405,7 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Comreturn true;}+ @Overridepublic final int compare(final byte[] a, final byte[] b) {try {return (this.asc) ?@@ -423,6 +432,7 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com}}+ @Overridepublic final int compare(final byte[] a, final byte[] b, final int length) {try {return (this.asc) ?@@ -444,6 +454,7 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com}}+ @Overridepublic final int compare(final byte[] a, final int aoffset, final byte[] b, final int boffset, final int length) {try {return (this.asc) ?diff --git a/source/net/yacy/kelondro/rwi/AbstractBufferedIndex.java b/source/net/yacy/kelondro/rwi/AbstractBufferedIndex.javaindex 8acec27c7..569180dfc 100644--- a/source/net/yacy/kelondro/rwi/AbstractBufferedIndex.java+++ b/source/net/yacy/kelondro/rwi/AbstractBufferedIndex.java@@ -40,7 +40,7 @@ public abstract class AbstractBufferedIndex<ReferenceType extends Reference> extsuper(factory);}- public synchronized TreeSet<ReferenceContainer<ReferenceType>> referenceContainer(byte[] startHash, final boolean rot, int count, final boolean ram) throws IOException {+ public synchronized TreeSet<ReferenceContainer<ReferenceType>> referenceContainer(byte[] startHash, final boolean rot, final boolean excludePrivate, int count, final boolean ram) throws IOException {// creates a set of indexContainers// this does not use the cachefinal Order<ReferenceContainer<ReferenceType>> containerOrder = new ReferenceContainerOrder<ReferenceType>(this.factory, termKeyOrdering().clone());@@ -48,7 +48,7 @@ public abstract class AbstractBufferedIndex<ReferenceType extends Reference> extfinal ReferenceContainer<ReferenceType> emptyContainer = ReferenceContainer.emptyContainer(this.factory, startHash);containerOrder.rotate(emptyContainer);final TreeSet<ReferenceContainer<ReferenceType>> containers = new TreeSet<ReferenceContainer<ReferenceType>>(containerOrder);- final Iterator<ReferenceContainer<ReferenceType>> i = referenceContainerIterator(startHash, rot, ram);+ final Iterator<ReferenceContainer<ReferenceType>> i = referenceContainerIterator(startHash, rot, excludePrivate, ram);if (ram) count = Math.min(size(), count);ReferenceContainer<ReferenceType> container;// this loop does not terminate using the i.hasNex() predicate when rot == truediff --git a/source/net/yacy/kelondro/rwi/AbstractIndex.java b/source/net/yacy/kelondro/rwi/AbstractIndex.javaindex 9c78d2c5a..e357d54ed 100644--- a/source/net/yacy/kelondro/rwi/AbstractIndex.java+++ b/source/net/yacy/kelondro/rwi/AbstractIndex.java@@ -54,6 +54,7 @@ public abstract class AbstractIndex <ReferenceType extends Reference> implements* @throws IOException* @throws RowSpaceExceededException*/+ @Overridepublic void merge(final Index<ReferenceType> otherIndex) throws IOException, RowSpaceExceededException {byte[] term;for (final ReferenceContainer<ReferenceType> otherContainer: otherIndex) {@@ -71,6 +72,7 @@ public abstract class AbstractIndex <ReferenceType extends Reference> implements}}+ @Overridepublic void removeDelayed(final HandleSet termHashes, final byte[] urlHashBytes) throws IOException {// remove the same url hashes for multiple words// this is mainly used when correcting a index after a search@@ -80,6 +82,7 @@ public abstract class AbstractIndex <ReferenceType extends Reference> implements}}+ @Overridepublic int remove(final HandleSet termHashes, final byte[] urlHashBytes) throws IOException {// remove the same url hashes for multiple words// this is mainly used when correcting a index after a search@@ -91,14 +94,14 @@ public abstract class AbstractIndex <ReferenceType extends Reference> implementsreturn c;}- public synchronized TreeSet<ReferenceContainer<ReferenceType>> referenceContainer(final byte[] startHash, final boolean rot, int count) throws IOException {+ public synchronized TreeSet<ReferenceContainer<ReferenceType>> referenceContainer(final byte[] startHash, final boolean rot, final boolean excludePrivate, int count) throws IOException {// creates a set of indexContainers// this does not use the cachefinal Order<ReferenceContainer<ReferenceType>> containerOrder = new ReferenceContainerOrder<ReferenceType>(this.factory, termKeyOrdering().clone());final ReferenceContainer<ReferenceType> emptyContainer = ReferenceContainer.emptyContainer(this.factory, startHash);containerOrder.rotate(emptyContainer);final TreeSet<ReferenceContainer<ReferenceType>> containers = new TreeSet<ReferenceContainer<ReferenceType>>(containerOrder);- final Iterator<ReferenceContainer<ReferenceType>> i = referenceContainerIterator(startHash, rot);+ final Iterator<ReferenceContainer<ReferenceType>> i = referenceContainerIterator(startHash, rot, excludePrivate);//if (ram) count = Math.min(size(), count);ReferenceContainer<ReferenceType> container;// this loop does not terminate using the i.hasNex() predicate when rot == true@@ -126,6 +129,7 @@ public abstract class AbstractIndex <ReferenceType extends Reference> implements* @param urlselection* @return map of wordhash:indexContainer*/+ @Overridepublic TreeMap<byte[], ReferenceContainer<ReferenceType>> searchConjunction(final HandleSet wordHashes, final HandleSet urlselection) {// first check if there is any entry that has no match; this uses only operations in ram/*@@ -212,6 +216,7 @@ public abstract class AbstractIndex <ReferenceType extends Reference> implementsreturn new TermSearch<ReferenceType>(this, queryHashes, excludeHashes, urlselection, termFactory, maxDistance);}+ @Overridepublic Row referenceRow() {return this.factory.getRow();}diff --git a/source/net/yacy/kelondro/rwi/BufferedIndex.java b/source/net/yacy/kelondro/rwi/BufferedIndex.javaindex b4e056547..23959a994 100644--- a/source/net/yacy/kelondro/rwi/BufferedIndex.java+++ b/source/net/yacy/kelondro/rwi/BufferedIndex.java@@ -108,6 +108,7 @@ public interface BufferedIndex<ReferenceType extends Reference> extends Index<Republic CloneableIterator<ReferenceContainer<ReferenceType>> referenceContainerIterator(byte[] startHash,boolean rot,+ boolean excludePrivate,boolean buffer) throws IOException;@@ -127,6 +128,7 @@ public interface BufferedIndex<ReferenceType extends Reference> extends Index<Republic TreeSet<ReferenceContainer<ReferenceType>> referenceContainer(byte[] startHash,boolean rot,+ boolean excludePrivate,int count,boolean buffer) throws IOException;diff --git a/source/net/yacy/kelondro/rwi/Index.java b/source/net/yacy/kelondro/rwi/Index.javaindex 14a377858..bf33dcf27 100644--- a/source/net/yacy/kelondro/rwi/Index.java+++ b/source/net/yacy/kelondro/rwi/Index.java@@ -146,7 +146,8 @@ public interface Index <ReferenceType extends Reference> extends Iterable<Refere*/public CloneableIterator<Rating<byte[]>> referenceCountIterator(byte[] startHash,- boolean rot+ boolean rot,+ boolean excludePrivate) throws IOException;/**@@ -159,13 +160,15 @@ public interface Index <ReferenceType extends Reference> extends Iterable<Refere*/public CloneableIterator<ReferenceContainer<ReferenceType>> referenceContainerIterator(byte[] startHash,- boolean rot+ boolean rot,+ boolean excludePrivate) throws IOException;public TreeSet<ReferenceContainer<ReferenceType>> referenceContainer(byte[] startHash,boolean rot,+ boolean excludePrivate,int count) throws IOException;diff --git a/source/net/yacy/kelondro/rwi/IndexCell.java b/source/net/yacy/kelondro/rwi/IndexCell.javaindex 5218d3702..7125ebdeb 100644--- a/source/net/yacy/kelondro/rwi/IndexCell.java+++ b/source/net/yacy/kelondro/rwi/IndexCell.java@@ -107,6 +107,7 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractBu}private class CleanupThread extends Thread {+ @Overridepublic void run() {while (IndexCell.this.cleanupShallRun) {try {@@ -211,6 +212,7 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractBu* every index entry is made for a term which has a fixed size* @return the size of the term*/+ @Overridepublic int termKeyLength() {return this.ram.termKeyLength();}@@ -220,6 +222,7 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractBu* @throws IOException* @throws RowSpaceExceededException*/+ @Overridepublic void add(final ReferenceContainer<ReferenceType> newEntries) throws IOException, RowSpaceExceededException {try {this.ram.add(newEntries);@@ -234,6 +237,7 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractBu}+ @Overridepublic void add(final byte[] termHash, final ReferenceType entry) throws IOException, RowSpaceExceededException {try {this.ram.add(termHash, entry);@@ -250,6 +254,7 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractBu/*** checks if there is any container for this termHash, either in RAM or any BLOB*/+ @Overridepublic boolean has(final byte[] termHash) {if (this.ram.has(termHash)) return true;return this.array.has(termHash);@@ -259,6 +264,7 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractBu* count number of references for a given term* this method may cause strong IO load if called too frequently.*/+ @Overridepublic int count(final byte[] termHash) {final Integer cachedCount = this.countCache.get(termHash);if (cachedCount != null) return cachedCount.intValue();@@ -295,6 +301,7 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractBu* @throws IOException* @return a container with merged ReferenceContainer from RAM and the file array or null if there is no data to be returned*/+ @Overridepublic ReferenceContainer<ReferenceType> get(final byte[] termHash, final HandleSet urlselection) throws IOException {final ReferenceContainer<ReferenceType> c0 = this.ram.get(termHash, null);ReferenceContainer<ReferenceType> c1 = null;@@ -335,6 +342,7 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractBu* the deleted containers are merged and returned as result of the method* @throws IOException*/+ @Overridepublic ReferenceContainer<ReferenceType> delete(final byte[] termHash) throws IOException {removeDelayed();ReferenceContainer<ReferenceType> c1 = null;@@ -362,6 +370,7 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractBu}}+ @Overridepublic void removeDelayed(final byte[] termHash, final HandleSet urlHashes) {HandleSet r;synchronized (this.removeDelayedURLs) {@@ -381,6 +390,7 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractBu}}+ @Overridepublic void removeDelayed(final byte[] termHash, final byte[] urlHashBytes) {HandleSet r;synchronized (this.removeDelayedURLs) {@@ -400,6 +410,7 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractBu}}+ @Overridepublic void removeDelayed() throws IOException {final HandleSet words = new HandleSet(URIMetadataRow.rowdef.primaryKeyLength, URIMetadataRow.rowdef.objectOrder, 0); // a set of url hashes where a worker thread tried to work on, but failed.synchronized (this.removeDelayedURLs) {@@ -422,6 +433,7 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractBu* new BLOBs. This returns the sum of all url references that have been removed* @throws IOException*/+ @Overridepublic int remove(final byte[] termHash, final HandleSet urlHashes) throws IOException {this.countCache.remove(termHash);final int removed = this.ram.remove(termHash, urlHashes);@@ -437,6 +449,7 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractBureturn removed + (reduced / this.array.rowdef().objectsize);}+ @Overridepublic boolean remove(final byte[] termHash, final byte[] urlHashBytes) throws IOException {this.countCache.remove(termHash);final boolean removed = this.ram.remove(termHash, urlHashBytes);@@ -469,6 +482,7 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractBu}}+ @Overridepublic ReferenceContainer<ReferenceType> reduce(final ReferenceContainer<ReferenceType> container) {container.sort();container.removeEntries(this.urlHashes);@@ -477,48 +491,46 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractBu}+ @Overridepublic Iterator<ReferenceContainer<ReferenceType>> iterator() {- return referenceContainerIterator(null, false);+ return referenceContainerIterator(null, false, false);}- public CloneableIterator<Rating<byte[]>> referenceCountIterator(final byte[] starttermHash, final boolean rot) {- return this.array.referenceCountIterator(starttermHash, false);+ @Override+ public CloneableIterator<Rating<byte[]>> referenceCountIterator(final byte[] starttermHash, final boolean rot, final boolean excludePrivate) {+ return this.array.referenceCountIterator(starttermHash, false, excludePrivate);}- public CloneableIterator<ReferenceContainer<ReferenceType>> referenceContainerIterator(final byte[] starttermHash, final boolean rot) {- final Order<ReferenceContainer<ReferenceType>> containerOrder = new ReferenceContainerOrder<ReferenceType>(this.factory, this.ram.rowdef().getOrdering().clone());- containerOrder.rotate(new ReferenceContainer<ReferenceType>(this.factory, starttermHash));- return new MergeIterator<ReferenceContainer<ReferenceType>>(- this.ram.referenceContainerIterator(starttermHash, rot),- new MergeIterator<ReferenceContainer<ReferenceType>>(- this.ram.referenceContainerIterator(starttermHash, false),- this.array.referenceContainerIterator(starttermHash, false),- containerOrder,- ReferenceContainer.containerMergeMethod,- true),- containerOrder,- ReferenceContainer.containerMergeMethod,- true);+ @Override+ public CloneableIterator<ReferenceContainer<ReferenceType>> referenceContainerIterator(final byte[] startTermHash, final boolean rot, final boolean excludePrivate) {+ return referenceContainerIterator(startTermHash, rot, excludePrivate);}- public CloneableIterator<ReferenceContainer<ReferenceType>> referenceContainerIterator(final byte[] startTermHash, final boolean rot, final boolean ram) {+ @Override+ public CloneableIterator<ReferenceContainer<ReferenceType>> referenceContainerIterator(final byte[] startTermHash, final boolean rot, final boolean excludePrivate, final boolean ram) {final Order<ReferenceContainer<ReferenceType>> containerOrder = new ReferenceContainerOrder<ReferenceType>(this.factory, this.ram.rowdef().getOrdering().clone());containerOrder.rotate(new ReferenceContainer<ReferenceType>(this.factory, startTermHash));if (ram) {- return this.ram.referenceContainerIterator(startTermHash, rot);+ return this.ram.referenceContainerIterator(startTermHash, rot, excludePrivate);}return new MergeIterator<ReferenceContainer<ReferenceType>>(- this.ram.referenceContainerIterator(startTermHash, false),- this.array.referenceContainerIterator(startTermHash, false),+ this.ram.referenceContainerIterator(startTermHash, rot, excludePrivate),+ new MergeIterator<ReferenceContainer<ReferenceType>>(+ this.ram.referenceContainerIterator(startTermHash, false, excludePrivate),+ this.array.referenceContainerIterator(startTermHash, false, excludePrivate),containerOrder,ReferenceContainer.containerMergeMethod,- true);+ true),+ containerOrder,+ ReferenceContainer.containerMergeMethod,+ true);}/*** clear the RAM and BLOB part, deletes everything in the cell* @throws IOException*/+ @Overridepublic synchronized void clear() throws IOException {this.countCache.clear();this.removeDelayedURLs.clear();@@ -531,6 +543,7 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractBu* BLOB file the next time a cell is opened. A name for the dump is automatically generated* and is composed of the current date and the cell salt*/+ @Overridepublic synchronized void close() {this.countCache.clear();try {removeDelayed();} catch (final IOException e) {}@@ -543,6 +556,7 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractButhis.array.close();}+ @Overridepublic int size() {throw new UnsupportedOperationException("an accumulated size of index entries would not reflect the real number of words, which cannot be computed easily");}@@ -563,10 +577,12 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractBureturn m;}+ @Overridepublic int minMem() {return 10 * 1024 * 1024;}+ @Overridepublic ByteOrder termKeyOrdering() {return this.array.ordering();}@@ -581,26 +597,32 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractButhis.array.mountBLOBFile(blobFile);}+ @Overridepublic long getBufferMaxAge() {return System.currentTimeMillis();}+ @Overridepublic int getBufferMaxReferences() {return this.ram.maxReferences();}+ @Overridepublic long getBufferMinAge() {return System.currentTimeMillis();}+ @Overridepublic int getBufferSize() {return this.ram.size();}+ @Overridepublic long getBufferSizeBytes() {return 10000 * this.ram.size(); // guessed; we don't know that exactly because there is no statistics here (expensive, not necessary)}+ @Overridepublic void setBufferMaxWordCount(final int maxWords) {this.maxRamEntries = maxWords;}diff --git a/source/net/yacy/kelondro/rwi/IndexReader.java b/source/net/yacy/kelondro/rwi/IndexReader.javaindex e1db98ecc..2857c3bd1 100644--- a/source/net/yacy/kelondro/rwi/IndexReader.java+++ b/source/net/yacy/kelondro/rwi/IndexReader.java@@ -35,7 +35,7 @@ public interface IndexReader<ReferenceType extends Reference> {public int size();public boolean has(byte[] wordHash); // should only be used if in case that true is returned the getContainer is NOT calledpublic ReferenceContainer<ReferenceType> get(byte[] wordHash, HandleSet urlselection);- public CloneableIterator<ReferenceContainer<ReferenceType>> referenceContainerIterator(byte[] startWordHash, boolean rot);+ public CloneableIterator<ReferenceContainer<ReferenceType>> referenceContainerIterator(byte[] startWordHash, boolean rot, boolean excludePrivate);public void close();}diff --git a/source/net/yacy/kelondro/rwi/ReferenceContainerArray.java b/source/net/yacy/kelondro/rwi/ReferenceContainerArray.javaindex c492ffee1..96e111f05 100644--- a/source/net/yacy/kelondro/rwi/ReferenceContainerArray.java+++ b/source/net/yacy/kelondro/rwi/ReferenceContainerArray.java@@ -32,6 +32,7 @@ import java.util.Iterator;import net.yacy.cora.ranking.Rating;import net.yacy.kelondro.blob.ArrayStack;import net.yacy.kelondro.blob.BLOB;+import net.yacy.kelondro.data.word.Word;import net.yacy.kelondro.index.HandleMap;import net.yacy.kelondro.index.Row;import net.yacy.kelondro.index.RowSet;@@ -110,9 +111,9 @@ public final class ReferenceContainerArray<ReferenceType extends Reference> {* objects in the cache.* @throws IOException*/- public CloneableIterator<ReferenceContainer<ReferenceType>> referenceContainerIterator(final byte[] startWordHash, final boolean rot) {+ public CloneableIterator<ReferenceContainer<ReferenceType>> referenceContainerIterator(final byte[] startWordHash, final boolean rot, final boolean excludePrivate) {try {- return new ReferenceContainerIterator(startWordHash, rot);+ return new ReferenceContainerIterator(startWordHash, rot, excludePrivate);} catch (final IOException e) {Log.logException(e);return null;@@ -126,33 +127,39 @@ public final class ReferenceContainerArray<ReferenceType extends Reference> {// so this class simulates wCache.tailMap(startWordHash).values().iterator()// plus the mentioned features- private final boolean rot;+ private final boolean rot, excludePrivate;protected CloneableIterator<byte[]> iterator;- public ReferenceContainerIterator(final byte[] startWordHash, final boolean rot) throws IOException {+ public ReferenceContainerIterator(final byte[] startWordHash, final boolean rot, final boolean excludePrivate) throws IOException {this.rot = rot;+ this.excludePrivate = excludePrivate;this.iterator = ReferenceContainerArray.this.array.keys(true, startWordHash);// The collection's iterator will return the values in the order that their corresponding keys appear in the tree.}+ @Overridepublic ReferenceContainerIterator clone(final Object secondWordHash) {try {- return new ReferenceContainerIterator((byte[]) secondWordHash, this.rot);+ return new ReferenceContainerIterator((byte[]) secondWordHash, this.rot, this.excludePrivate);} catch (final IOException e) {Log.logException(e);return null;}}+ @Overridepublic boolean hasNext() {if (this.iterator == null) return false;if (this.rot) return true;return this.iterator.hasNext();}+ @Overridepublic ReferenceContainer<ReferenceType> next() {- if (this.iterator.hasNext()) try {- return get(this.iterator.next());+ while (this.iterator.hasNext()) try {+ byte[] b = this.iterator.next();+ if (this.excludePrivate && Word.isPrivate(b)) continue;+ return get(b);} catch (final Throwable e) {Log.logException(e);return null;@@ -163,17 +170,24 @@ public final class ReferenceContainerArray<ReferenceType extends Reference> {}try {this.iterator = ReferenceContainerArray.this.array.keys(true, null);- return get(this.iterator.next());+ while (this.iterator.hasNext()) {+ byte[] b = this.iterator.next();+ if (this.excludePrivate && Word.isPrivate(b)) continue;+ return get(b);+ }+ return null;} catch (final Throwable e) {Log.logException(e);return null;}}+ @Overridepublic void remove() {this.iterator.remove();}+ @Overridepublic Iterator<ReferenceContainer<ReferenceType>> iterator() {return this;}@@ -185,9 +199,9 @@ public final class ReferenceContainerArray<ReferenceType extends Reference> {* the startWordHash may be null to iterate all from the beginning* @throws IOException*/- public CloneableIterator<Rating<byte[]>> referenceCountIterator(final byte[] startWordHash, final boolean rot) {+ public CloneableIterator<Rating<byte[]>> referenceCountIterator(final byte[] startWordHash, final boolean rot, final boolean excludePrivate) {try {- return new ReferenceCountIterator(startWordHash, rot);+ return new ReferenceCountIterator(startWordHash, rot, excludePrivate);} catch (final IOException e) {Log.logException(e);return null;@@ -196,34 +210,39 @@ public final class ReferenceContainerArray<ReferenceType extends Reference> {public class ReferenceCountIterator implements CloneableIterator<Rating<byte[]>>, Iterable<Rating<byte[]>> {- private final boolean rot;+ private final boolean rot, excludePrivate;protected CloneableIterator<byte[]> iterator;- public ReferenceCountIterator(final byte[] startWordHash, final boolean rot) throws IOException {+ public ReferenceCountIterator(final byte[] startWordHash, final boolean rot, final boolean excludePrivate) throws IOException {this.rot = rot;+ this.excludePrivate = excludePrivate;this.iterator = ReferenceContainerArray.this.array.keys(true, startWordHash);// The collection's iterator will return the values in the order that their corresponding keys appear in the tree.}+ @Overridepublic ReferenceCountIterator clone(final Object secondWordHash) {try {- return new ReferenceCountIterator((byte[]) secondWordHash, this.rot);+ return new ReferenceCountIterator((byte[]) secondWordHash, this.rot, this.excludePrivate);} catch (final IOException e) {Log.logException(e);return null;}}+ @Overridepublic boolean hasNext() {if (this.iterator == null) return false;if (this.rot) return true;return this.iterator.hasNext();}+ @Overridepublic Rating<byte[]> next() {byte[] reference;- if (this.iterator.hasNext()) try {+ while (this.iterator.hasNext()) try {reference = this.iterator.next();+ if (this.excludePrivate && Word.isPrivate(reference)) continue;return new Rating<byte[]>(reference, count(reference));} catch (final Throwable e) {Log.logException(e);@@ -233,20 +252,24 @@ public final class ReferenceContainerArray<ReferenceType extends Reference> {if (!this.rot) {return null;}- try {+ while (this.iterator.hasNext()) try {this.iterator = ReferenceContainerArray.this.array.keys(true, null);reference = this.iterator.next();+ if (this.excludePrivate && Word.isPrivate(reference)) continue;return new Rating<byte[]>(reference, count(reference));} catch (final Throwable e) {Log.logException(e);return null;}+ return null;}+ @Overridepublic void remove() {this.iterator.remove();}+ @Overridepublic Iterator<Rating<byte[]>> iterator() {return this;}@@ -355,6 +378,7 @@ public final class ReferenceContainerArray<ReferenceType extends Reference> {this.wordHash = wordHash;}+ @Overridepublic byte[] rewrite(final byte[] b) throws RowSpaceExceededException {if (b == null) return null;final ReferenceContainer<ReferenceType> c = this.rewriter.reduce(new ReferenceContainer<ReferenceType>(ReferenceContainerArray.this.factory, this.wordHash, RowSet.importRowSet(b, ReferenceContainerArray.this.factory.getRow())));diff --git a/source/net/yacy/kelondro/rwi/ReferenceContainerCache.java b/source/net/yacy/kelondro/rwi/ReferenceContainerCache.javaindex 64f020916..53063e792 100644--- a/source/net/yacy/kelondro/rwi/ReferenceContainerCache.java+++ b/source/net/yacy/kelondro/rwi/ReferenceContainerCache.java@@ -38,6 +38,7 @@ import java.util.concurrent.ConcurrentHashMap;import net.yacy.cora.ranking.Rating;import net.yacy.kelondro.blob.HeapWriter;+import net.yacy.kelondro.data.word.Word;import net.yacy.kelondro.index.HandleSet;import net.yacy.kelondro.index.Row;import net.yacy.kelondro.index.RowSpaceExceededException;@@ -89,14 +90,17 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte* every index entry is made for a term which has a fixed size* @return the size of the term*/+ @Overridepublic int termKeyLength() {return this.termSize;}+ @Overridepublic void clear() {if (this.cache != null) this.cache.clear();}+ @Overridepublic void close() {this.cache = null;}@@ -191,6 +195,7 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> extereturn list;}+ @Overridepublic int size() {return (this.cache == null) ? 0 : this.cache.size();}@@ -209,8 +214,9 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> extereturn max;}+ @Overridepublic Iterator<ReferenceContainer<ReferenceType>> iterator() {- return referenceContainerIterator(null, false);+ return referenceContainerIterator(null, false, false);}/**@@ -218,8 +224,9 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte* in the cache, so that manipulations of the iterated objects do not change* objects in the cache.*/- public synchronized CloneableIterator<ReferenceContainer<ReferenceType>> referenceContainerIterator(final byte[] startWordHash, final boolean rot) {- return new ReferenceContainerIterator(startWordHash, rot);+ @Override+ public synchronized CloneableIterator<ReferenceContainer<ReferenceType>> referenceContainerIterator(final byte[] startWordHash, final boolean rot, final boolean excludePrivate) {+ return new ReferenceContainerIterator(startWordHash, rot, excludePrivate);}/**@@ -233,40 +240,47 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte// so this class simulates wCache.tailMap(startWordHash).values().iterator()// plus the mentioned features- private final boolean rot;+ private final boolean rot, excludePrivate;private final List<ReferenceContainer<ReferenceType>> cachecopy;private int p;private byte[] latestTermHash;- public ReferenceContainerIterator(byte[] startWordHash, final boolean rot) {+ public ReferenceContainerIterator(byte[] startWordHash, final boolean rot, final boolean excludePrivate) {this.rot = rot;+ this.excludePrivate = excludePrivate;if (startWordHash != null && startWordHash.length == 0) startWordHash = null;this.cachecopy = sortedClone();assert this.cachecopy != null;assert ReferenceContainerCache.this.termOrder != null;this.p = 0;if (startWordHash != null) {+ byte[] b;while ( this.p < this.cachecopy.size() &&- ReferenceContainerCache.this.termOrder.compare(this.cachecopy.get(this.p).getTermHash(), startWordHash) < 0+ ReferenceContainerCache.this.termOrder.compare(b = this.cachecopy.get(this.p).getTermHash(), startWordHash) < 0 &&+ !(excludePrivate && Word.isPrivate(b))) this.p++;}this.latestTermHash = null;// The collection's iterator will return the values in the order that their corresponding keys appear in the tree.}+ @Overridepublic ReferenceContainerIterator clone(final Object secondWordHash) {- return new ReferenceContainerIterator((byte[]) secondWordHash, this.rot);+ return new ReferenceContainerIterator((byte[]) secondWordHash, this.rot, this.excludePrivate);}+ @Overridepublic boolean hasNext() {if (this.rot) return this.cachecopy.size() > 0;return this.p < this.cachecopy.size();}+ @Overridepublic ReferenceContainer<ReferenceType> next() {- if (this.p < this.cachecopy.size()) {+ while (this.p < this.cachecopy.size()) {final ReferenceContainer<ReferenceType> c = this.cachecopy.get(this.p++);this.latestTermHash = c.getTermHash();+ if (this.excludePrivate && Word.isPrivate(this.latestTermHash)) continue;try {return c.topLevelClone();} catch (final RowSpaceExceededException e) {@@ -280,21 +294,27 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte}if (this.cachecopy.isEmpty()) return null;this.p = 0;- final ReferenceContainer<ReferenceType> c = this.cachecopy.get(this.p++);- this.latestTermHash = c.getTermHash();- try {- return c.topLevelClone();- } catch (final RowSpaceExceededException e) {- Log.logException(e);- return null;+ while (this.p < this.cachecopy.size()) {+ final ReferenceContainer<ReferenceType> c = this.cachecopy.get(this.p++);+ this.latestTermHash = c.getTermHash();+ if (this.excludePrivate && Word.isPrivate(this.latestTermHash)) continue;+ try {+ return c.topLevelClone();+ } catch (final RowSpaceExceededException e) {+ Log.logException(e);+ return null;+ }}+ return null;}+ @Overridepublic void remove() {System.arraycopy(this.cachecopy, this.p, this.cachecopy, this.p - 1, this.cachecopy.size() - this.p);ReferenceContainerCache.this.cache.remove(new ByteArray(this.latestTermHash));}+ @Overridepublic Iterator<ReferenceContainer<ReferenceType>> iterator() {return this;}@@ -302,8 +322,8 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte}@Override- public CloneableIterator<Rating<byte[]>> referenceCountIterator(final byte[] startHash, final boolean rot) {- return new ReferenceCountIterator(startHash, rot);+ public CloneableIterator<Rating<byte[]>> referenceCountIterator(final byte[] startHash, final boolean rot, boolean excludePrivate) {+ return new ReferenceCountIterator(startHash, rot, excludePrivate);}/**@@ -312,40 +332,47 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte*/public class ReferenceCountIterator implements CloneableIterator<Rating<byte[]>>, Iterable<Rating<byte[]>> {- private final boolean rot;+ private final boolean rot, excludePrivate;private final List<Rating<ByteArray>> cachecounts;private int p;private byte[] latestTermHash;- public ReferenceCountIterator(byte[] startWordHash, final boolean rot) {+ public ReferenceCountIterator(byte[] startWordHash, final boolean rot, boolean excludePrivate) {this.rot = rot;+ this.excludePrivate = excludePrivate;if (startWordHash != null && startWordHash.length == 0) startWordHash = null;this.cachecounts = ratingList();assert this.cachecounts != null;assert ReferenceContainerCache.this.termOrder != null;this.p = 0;if (startWordHash != null) {+ byte[] b;while ( this.p < this.cachecounts.size() &&- ReferenceContainerCache.this.termOrder.compare(this.cachecounts.get(this.p).getObject().asBytes(), startWordHash) < 0+ ReferenceContainerCache.this.termOrder.compare(b = this.cachecounts.get(this.p).getObject().asBytes(), startWordHash) < 0 &&+ !(excludePrivate && Word.isPrivate(b))) this.p++;}this.latestTermHash = null;// The collection's iterator will return the values in the order that their corresponding keys appear in the tree.}+ @Overridepublic ReferenceCountIterator clone(final Object secondWordHash) {- return new ReferenceCountIterator((byte[]) secondWordHash, this.rot);+ return new ReferenceCountIterator((byte[]) secondWordHash, this.rot, this.excludePrivate);}+ @Overridepublic boolean hasNext() {if (this.rot) return this.cachecounts.size() > 0;return this.p < this.cachecounts.size();}+ @Overridepublic Rating<byte[]> next() {- if (this.p < this.cachecounts.size()) {+ while (this.p < this.cachecounts.size()) {final Rating<ByteArray> c = this.cachecounts.get(this.p++);this.latestTermHash = c.getObject().asBytes();+ if (this.excludePrivate && Word.isPrivate(this.latestTermHash)) continue;return new Rating<byte[]>(c.getObject().asBytes(), c.getScore());}// rotation iteration@@ -354,16 +381,22 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte}if (this.cachecounts.isEmpty()) return null;this.p = 0;- final Rating<ByteArray> c = this.cachecounts.get(this.p++);- this.latestTermHash = c.getObject().asBytes();- return new Rating<byte[]>(c.getObject().asBytes(), c.getScore());+ while (this.p < this.cachecounts.size()) {+ final Rating<ByteArray> c = this.cachecounts.get(this.p++);+ this.latestTermHash = c.getObject().asBytes();+ if (this.excludePrivate && Word.isPrivate(this.latestTermHash)) continue;+ return new Rating<byte[]>(c.getObject().asBytes(), c.getScore());+ }+ return null;}+ @Overridepublic void remove() {System.arraycopy(this.cachecounts, this.p, this.cachecounts, this.p - 1, this.cachecounts.size() - this.p);ReferenceContainerCache.this.cache.remove(new ByteArray(this.latestTermHash));}+ @Overridepublic Iterator<Rating<byte[]>> iterator() {return this;}@@ -376,6 +409,7 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte* @param key* @return true, if the key is used in the heap; false otherwise*/+ @Overridepublic boolean has(final byte[] key) {return this.cache.containsKey(new ByteArray(key));}@@ -386,7 +420,9 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte* @return the indexContainer if one exist, null otherwise* @throws*/+ @Overridepublic ReferenceContainer<ReferenceType> get(final byte[] key, final HandleSet urlselection) {+ if (this.cache == null) return null;final ReferenceContainer<ReferenceType> c = this.cache.get(new ByteArray(key));if (urlselection == null) return c;if (c == null) return null;@@ -413,6 +449,7 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte* @param key* @return*/+ @Overridepublic int count(final byte[] key) {final ReferenceContainer<ReferenceType> c = this.cache.get(new ByteArray(key));if (c == null) return 0;@@ -424,6 +461,7 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte* @param wordHash* @return the indexContainer if the cache contained the container, null otherwise*/+ @Overridepublic ReferenceContainer<ReferenceType> delete(final byte[] termHash) {// returns the index that had been deletedassert this.cache != null;@@ -431,9 +469,11 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> extereturn this.cache.remove(new ByteArray(termHash));}+ @Overridepublic void removeDelayed(final byte[] termHash, final byte[] urlHashBytes) {remove(termHash, urlHashBytes);}+ @Overridepublic boolean remove(final byte[] termHash, final byte[] urlHashBytes) {assert this.cache != null;if (this.cache == null) return false;@@ -453,10 +493,12 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> extereturn false;}+ @Overridepublic void removeDelayed(final byte[] termHash, final HandleSet urlHashes) {remove(termHash, urlHashes);}+ @Overridepublic int remove(final byte[] termHash, final HandleSet urlHashes) {assert this.cache != null;if (this.cache == null) return 0;@@ -478,8 +520,10 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> extereturn 0;}+ @Overridepublic void removeDelayed() {}+ @Overridepublic void add(final ReferenceContainer<ReferenceType> container) throws RowSpaceExceededException {// this puts the entries into the cacheif (this.cache == null || container == null || container.isEmpty()) return;@@ -503,6 +547,7 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte}}+ @Overridepublic void add(final byte[] termHash, final ReferenceType newEntry) throws RowSpaceExceededException {assert this.cache != null;if (this.cache == null) return;@@ -535,10 +580,12 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte}}+ @Overridepublic int minMem() {return 0;}+ @Overridepublic ByteOrder termKeyOrdering() {return this.termOrder;}@@ -548,6 +595,7 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> extepublic ContainerOrder(final ByteOrder order) {this.o = order;}+ @Overridepublic int compare(final ReferenceContainer<ReferenceType> arg0, final ReferenceContainer<ReferenceType> arg1) {if (arg0 == arg1) return 0;if (arg0 == null) return -1;diff --git a/source/net/yacy/peers/dht/Dispatcher.java b/source/net/yacy/peers/dht/Dispatcher.javaindex 0098eb785..2d8f3258a 100755--- a/source/net/yacy/peers/dht/Dispatcher.java+++ b/source/net/yacy/peers/dht/Dispatcher.java@@ -34,6 +34,7 @@ import java.util.concurrent.ConcurrentHashMap;import net.yacy.cora.document.ASCII;import net.yacy.kelondro.data.meta.URIMetadataRow;+import net.yacy.kelondro.data.word.Word;import net.yacy.kelondro.data.word.WordReference;import net.yacy.kelondro.index.HandleSet;import net.yacy.kelondro.index.RowSpaceExceededException;@@ -168,7 +169,7 @@ public class Dispatcher {final ArrayList<ReferenceContainer<WordReference>> containers = new ArrayList<ReferenceContainer<WordReference>>(maxContainerCount);- final Iterator<ReferenceContainer<WordReference>> indexContainerIterator = this.segment.termIndex().referenceContainerIterator(hash, true, ram);+ final Iterator<ReferenceContainer<WordReference>> indexContainerIterator = this.segment.termIndex().referenceContainerIterator(hash, true, true, ram); // very important that rotation is true hereReferenceContainer<WordReference> container;int refcount = 0;@@ -185,6 +186,7 @@ public class Dispatcher {) {if (container.isEmpty()) continue;+ if (Word.isPrivate(container.getTermHash())) continue; // exclude private containersrefcount += container.size();containers.add(container);}diff --git a/source/net/yacy/peers/dht/PeerSelection.java b/source/net/yacy/peers/dht/PeerSelection.javaindex 4b1542a72..4bd012c3a 100755--- a/source/net/yacy/peers/dht/PeerSelection.java+++ b/source/net/yacy/peers/dht/PeerSelection.java@@ -231,7 +231,7 @@ public class PeerSelection {private final SeedDB seedDB;private final HandleSet doublecheck;private int remaining;- private boolean alsoMyOwn;+ private final boolean alsoMyOwn;private acceptRemoteIndexSeedEnum(SeedDB seedDB, final byte[] starthash, int max, boolean alsoMyOwn) {this.seedDB = seedDB;@@ -242,19 +242,20 @@ public class PeerSelection {this.alsoMyOwn = alsoMyOwn;}+ @Overridepublic boolean hasNext() {- return nextSeed != null;+ return this.nextSeed != null;}private Seed nextInternal() {if (this.remaining <= 0) return null;Seed s;try {- while (se.hasNext()) {- s = se.next();+ while (this.se.hasNext()) {+ s = this.se.next();if (s == null) return null;byte[] hashb = ASCII.getBytes(s.hash);- if (doublecheck.has(hashb)) return null;+ if (this.doublecheck.has(hashb)) return null;try {this.doublecheck.put(hashb);} catch (RowSpaceExceededException e) {@@ -262,7 +263,7 @@ public class PeerSelection {break;}if (s.getFlagAcceptRemoteIndex() ||- (alsoMyOwn && s.hash.equals(seedDB.mySeed().hash)) // Accept own peer regardless of FlagAcceptRemoteIndex+ (this.alsoMyOwn && s.hash.equals(this.seedDB.mySeed().hash)) // Accept own peer regardless of FlagAcceptRemoteIndex) {this.remaining--;return s;@@ -271,18 +272,20 @@ public class PeerSelection {} catch (final kelondroException e) {System.out.println("DEBUG acceptRemoteIndexSeedEnum:" + e.getMessage());Network.log.logSevere("database inconsistency (" + e.getMessage() + "), re-set of db.");- seedDB.resetActiveTable();+ this.seedDB.resetActiveTable();return null;}return null;}+ @Overridepublic Seed next() {- final Seed next = nextSeed;- nextSeed = nextInternal();+ final Seed next = this.nextSeed;+ this.nextSeed = nextInternal();return next;}+ @Overridepublic void remove() {throw new UnsupportedOperationException();}@@ -309,8 +312,8 @@ public class PeerSelection {private Iterator<Seed> e;private int steps;- private float minVersion;- private SeedDB seedDB;+ private final float minVersion;+ private final SeedDB seedDB;private boolean alsoMyOwn;private int pass, insertOwnInPass;private Seed nextSeed;@@ -330,41 +333,44 @@ public class PeerSelection {this.nextSeed = nextInternal();}+ @Overridepublic boolean hasNext() {- return (nextSeed != null) || alsoMyOwn;+ return (this.nextSeed != null) || this.alsoMyOwn;}public Seed nextInternal() {- if (steps == 0) return null;- steps--;+ if (this.steps == 0) return null;+ this.steps--;- if (!e.hasNext() && pass == 1) {- e = seedDB.seedsConnected(true, false, null, minVersion);- pass = 2;+ if (!this.e.hasNext() && this.pass == 1) {+ this.e = this.seedDB.seedsConnected(true, false, null, this.minVersion);+ this.pass = 2;}- if (e.hasNext()) {- return e.next();+ if (this.e.hasNext()) {+ return this.e.next();}- steps = 0;+ this.steps = 0;return null;}+ @Overridepublic Seed next() {- if (alsoMyOwn &&- ((pass > insertOwnInPass) ||- (pass == insertOwnInPass && nextSeed == null) || // Own hash is last in line- (pass == insertOwnInPass && nextSeed != null && (Base64Order.enhancedCoder.compare(ASCII.getBytes(seedDB.mySeed().hash), ASCII.getBytes(nextSeed.hash)) < 0)))+ if (this.alsoMyOwn &&+ ((this.pass > this.insertOwnInPass) ||+ (this.pass == this.insertOwnInPass && this.nextSeed == null) || // Own hash is last in line+ (this.pass == this.insertOwnInPass && this.nextSeed != null && (Base64Order.enhancedCoder.compare(ASCII.getBytes(this.seedDB.mySeed().hash), ASCII.getBytes(this.nextSeed.hash)) < 0)))) {// take my own seed hash instead the enumeration result- alsoMyOwn = false;- return seedDB.mySeed();+ this.alsoMyOwn = false;+ return this.seedDB.mySeed();} else {- final Seed next = nextSeed;- nextSeed = nextInternal();+ final Seed next = this.nextSeed;+ this.nextSeed = nextInternal();return next;}}+ @Overridepublic void remove() {throw new UnsupportedOperationException();}@@ -381,49 +387,53 @@ public class PeerSelection {private static class providesRemoteCrawlURLsEnum implements Iterator<Seed> {- private Iterator<Seed> se;+ private final Iterator<Seed> se;private Seed nextSeed;- private SeedDB seedDB;+ private final SeedDB seedDB;private providesRemoteCrawlURLsEnum(final SeedDB seedDB) {this.seedDB = seedDB;- se = getDHTSeeds(seedDB, null, yacyVersion.YACY_POVIDES_REMOTECRAWL_LISTS);- nextSeed = nextInternal();+ this.se = getDHTSeeds(seedDB, null, yacyVersion.YACY_POVIDES_REMOTECRAWL_LISTS);+ this.nextSeed = nextInternal();}+ @Overridepublic boolean hasNext() {- return nextSeed != null;+ return this.nextSeed != null;}private Seed nextInternal() {Seed s;try {- while (se.hasNext()) {- s = se.next();+ while (this.se.hasNext()) {+ s = this.se.next();if (s == null) return null;if (s.getLong(Seed.RCOUNT, 0) > 0) return s;}} catch (final kelondroException e) {System.out.println("DEBUG providesRemoteCrawlURLsEnum:" + e.getMessage());Network.log.logSevere("database inconsistency (" + e.getMessage() + "), re-set of db.");- seedDB.resetActiveTable();+ this.seedDB.resetActiveTable();return null;}return null;}+ @Overridepublic Seed next() {- final Seed next = nextSeed;- nextSeed = nextInternal();+ final Seed next = this.nextSeed;+ this.nextSeed = nextInternal();return next;}+ @Overridepublic void remove() {throw new UnsupportedOperationException();}}+/*** get either the youngest or oldest peers from the seed db. Count as many as requested* @param seedDB@@ -431,7 +441,7 @@ public class PeerSelection {* @param count number of wanted peers* @return a hash map of peer hashes to seed object*/- public static Map<String, Seed> seedsByAge(final SeedDB seedDB, final boolean up, int count) {+ public static Map<String, Seed> seedsByAgeX(final SeedDB seedDB, final boolean up, int count) {if (count > seedDB.sizeConnected()) count = seedDB.sizeConnected();@@ -467,4 +477,38 @@ public class PeerSelection {return null;}}-}++++ /**+ * get either the youngest or oldest peers from the seed db. Count as many as requested+ * @param seedDB+ * @param up if up = true then get the most recent peers, if up = false then get oldest+ * @param count number of wanted peers+ * @return a hash map of peer hashes to seed object+ */+ public static Map<String, Seed> seedsByAge(final SeedDB seedDB, final boolean up, int count) {+ if (count > seedDB.sizeConnected()) count = seedDB.sizeConnected();+ Seed ys;+ long age;+ final Iterator<Seed> s = seedDB.seedsSortedConnected(!up, Seed.LASTSEEN);+ try {+ final Map<String, Seed> result = new HashMap<String, Seed>();+ while (s.hasNext() && count-- > 0) {+ ys = s.next();+ if (ys != null && ys.hash != null) {+ age = (System.currentTimeMillis() - ys.getLastSeenUTC()) / 1000 / 60;+ System.out.println("selected seedsByAge up=" + up + ", age/min = " + age);+ result.put(ys.hash, ys);+ }+ }+ return result;+ } catch (final kelondroException e) {+ Network.log.logSevere("Internal Error at yacySeedDB.seedsByAge: " + e.getMessage(), e);+ return null;+ }+ }++++}\ No newline at end of filediff --git a/source/net/yacy/search/index/Segment.java b/source/net/yacy/search/index/Segment.javaindex 3bf2f6eee..3742d0203 100644--- a/source/net/yacy/search/index/Segment.java+++ b/source/net/yacy/search/index/Segment.java@@ -253,6 +253,7 @@ public class Segment {}wordCount++;if (searchEvent != null && !searchEvent.getQuery().excludeHashes.has(wordhash) && searchEvent.getQuery().queryHashes.has(wordhash)) {+ // if the page was added in the context of a heuristic this shall ensure that findings will fire directly into the search resultReferenceContainer<WordReference> container;try {container = ReferenceContainer.emptyContainer(Segment.wordReferenceFactory, wordhash, 1);@@ -472,6 +473,7 @@ public class Segment {this.rwiCountAtStart = termIndex().sizesMax();}+ @Overridepublic void run() {Log.logInfo("INDEXCLEANER", "IndexCleaner-Thread started");ReferenceContainer<WordReference> container = null;@@ -479,7 +481,7 @@ public class Segment {DigestURI url = null;final HandleSet urlHashs = new HandleSet(URIMetadataRow.rowdef.primaryKeyLength, URIMetadataRow.rowdef.objectOrder, 0);try {- Iterator<ReferenceContainer<WordReference>> indexContainerIterator = Segment.this.termIndex.referenceContainer(this.startHash, false, 100, false).iterator();+ Iterator<ReferenceContainer<WordReference>> indexContainerIterator = Segment.this.termIndex.referenceContainer(this.startHash, false, false, 100, false).iterator();while (indexContainerIterator.hasNext() && this.run) {waiter();container = indexContainerIterator.next();@@ -512,7 +514,7 @@ public class Segment {if (!containerIterator.hasNext()) {// We may not be finished yet, try to get the next chunk of wordHashes- final TreeSet<ReferenceContainer<WordReference>> containers = Segment.this.termIndex.referenceContainer(container.getTermHash(), false, 100, false);+ final TreeSet<ReferenceContainer<WordReference>> containers = Segment.this.termIndex.referenceContainer(container.getTermHash(), false, false, 100, false);indexContainerIterator = containers.iterator();// Make sure we don't get the same wordhash twice, but don't skip a wordif ((indexContainerIterator.hasNext()) && (!container.getTermHash().equals(indexContainerIterator.next().getTermHash()))) {diff --git a/source/net/yacy/search/query/QueryParams.java b/source/net/yacy/search/query/QueryParams.javaindex 57483398f..ec344512d 100644--- a/source/net/yacy/search/query/QueryParams.java+++ b/source/net/yacy/search/query/QueryParams.java@@ -29,7 +29,6 @@ package net.yacy.search.query;import java.io.UnsupportedEncodingException;import java.net.URLEncoder;import java.util.HashMap;-import java.util.HashSet;import java.util.Iterator;import java.util.Map;import java.util.Set;@@ -147,13 +146,13 @@ public final class QueryParams {final Segment indexSegment,final RankingProfile ranking,final String userAgent) {-- if ((queryString.length() == 12) && (Base64Order.enhancedCoder.wellformed(UTF8.getBytes(queryString)))) {+ byte[] queryHash;+ if ((queryString.length() == 12) && (Base64Order.enhancedCoder.wellformed(queryHash = UTF8.getBytes(queryString)))) {this.queryString = null;this.queryHashes = new HandleSet(WordReferenceRow.urlEntryRow.primaryKeyLength, WordReferenceRow.urlEntryRow.objectOrder, 0);this.excludeHashes = new HandleSet(WordReferenceRow.urlEntryRow.primaryKeyLength, WordReferenceRow.urlEntryRow.objectOrder, 0);try {- this.queryHashes.put(UTF8.getBytes(queryString));+ this.queryHashes.put(queryHash);} catch (final RowSpaceExceededException e) {Log.logException(e);}