From e54cb7fb0ce4993ab3ed8bc6575c1906c222904a Mon Sep 17 00:00:00 2001 From: orbiter Date: Tue, 28 Sep 2010 10:20:46 +0000 Subject: [PATCH] more bugfixes (also for latest commit) git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7202 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/search/SearchEvent.java | 1 + .../data/image/ImageReferenceVars.java | 4 +-- .../kelondro/data/word/WordReferenceVars.java | 12 ++++--- .../yacy/kelondro/rwi/AbstractReference.java | 36 ++++++++++++++----- 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/source/de/anomic/search/SearchEvent.java b/source/de/anomic/search/SearchEvent.java index eadf685db..a9e4f9a44 100644 --- a/source/de/anomic/search/SearchEvent.java +++ b/source/de/anomic/search/SearchEvent.java @@ -517,6 +517,7 @@ public final class SearchEvent { if (checkedPeers.contains(peer)) continue; // do not ask a peer again urls = entry.getValue(); words = wordsFromPeer(peer, urls); + if (words.length() == 0) continue; // ??? assert words.length() >= 12 : "words = " + words; //System.out.println("DEBUG-INDEXABSTRACT ***: peer " + peer + " has urls: " + urls + " from words: " + words); rankedCache.moreFeeders(1); diff --git a/source/net/yacy/kelondro/data/image/ImageReferenceVars.java b/source/net/yacy/kelondro/data/image/ImageReferenceVars.java index 671252ca7..0e4e46357 100644 --- a/source/net/yacy/kelondro/data/image/ImageReferenceVars.java +++ b/source/net/yacy/kelondro/data/image/ImageReferenceVars.java @@ -309,7 +309,7 @@ public class ImageReferenceVars extends AbstractReference implements ImageRefere if (this.virtualAge > (v = other.virtualAge)) this.virtualAge = v; if (this.wordsintext > (v = other.wordsintext)) this.wordsintext = v; if (this.phrasesintext > (v = other.phrasesintext)) this.phrasesintext = v; - if (other.positions != null) a(this.positions, Math.min(min(this.positions), min(other.positions))); + if (other.positions != null) a(this.positions, min(this.positions, other.positions)); if (this.posinphrase > (v = other.posinphrase)) this.posinphrase = v; if (this.posofphrase > (v = other.posofphrase)) this.posofphrase = v; if (this.lastModified > (w = other.lastModified)) this.lastModified = w; @@ -331,7 +331,7 @@ public class ImageReferenceVars extends AbstractReference implements ImageRefere if (this.virtualAge < (v = other.virtualAge)) this.virtualAge = v; if (this.wordsintext < (v = other.wordsintext)) this.wordsintext = v; if (this.phrasesintext < (v = other.phrasesintext)) this.phrasesintext = v; - if (other.positions != null) a(this.positions, Math.max(max(this.positions), max(other.positions))); + if (other.positions != null) a(this.positions, max(this.positions, other.positions)); if (this.posinphrase < (v = other.posinphrase)) this.posinphrase = v; if (this.posofphrase < (v = other.posofphrase)) this.posofphrase = v; if (this.lastModified < (w = other.lastModified)) this.lastModified = w; diff --git a/source/net/yacy/kelondro/data/word/WordReferenceVars.java b/source/net/yacy/kelondro/data/word/WordReferenceVars.java index a9f14f2f0..ffab3d7c8 100644 --- a/source/net/yacy/kelondro/data/word/WordReferenceVars.java +++ b/source/net/yacy/kelondro/data/word/WordReferenceVars.java @@ -27,7 +27,9 @@ package net.yacy.kelondro.data.word; import java.util.ArrayList; +import java.util.Collections; import java.util.Comparator; +import java.util.List; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.Semaphore; @@ -60,7 +62,7 @@ public class WordReferenceVars extends AbstractReference implements WordReferenc posinphrase, posofphrase, urlcomps, urllength, virtualAge, wordsintext, wordsintitle; - private final ArrayList positions; + private final List positions; public double termFrequency; public WordReferenceVars( @@ -71,7 +73,7 @@ public class WordReferenceVars extends AbstractReference implements WordReferenc final int hitcount, // how often appears this word in the text final int wordcount, // total number of words final int phrasecount, // total number of phrases - final ArrayList ps, // positions of words that are joined into the reference + final List ps, // positions of words that are joined into the reference final int posinphrase, // position of word in its phrase final int posofphrase, // number of the phrase where word appears final long lastmodified, // last-modified time of the document where word appears @@ -96,7 +98,7 @@ public class WordReferenceVars extends AbstractReference implements WordReferenc this.llocal = outlinksSame; this.lother = outlinksOther; this.phrasesintext = phrasecount; - this.positions = new ArrayList(ps.size()); + this.positions = Collections.synchronizedList(new ArrayList(ps.size())); for (int i = 0; i < ps.size(); i++) this.positions.add(ps.get(i)); this.posinphrase = posinphrase; this.posofphrase = posofphrase; @@ -317,7 +319,7 @@ public class WordReferenceVars extends AbstractReference implements WordReferenc if (this.virtualAge > (v = other.virtualAge)) this.virtualAge = v; if (this.wordsintext > (v = other.wordsintext)) this.wordsintext = v; if (this.phrasesintext > (v = other.phrasesintext)) this.phrasesintext = v; - if (other.positions != null) a(this.positions, Math.min(min(this.positions), min(other.positions))); + if (other.positions != null) a(this.positions, min(this.positions, other.positions)); if (this.posinphrase > (v = other.posinphrase)) this.posinphrase = v; if (this.posofphrase > (v = other.posofphrase)) this.posofphrase = v; if (this.lastModified > (w = other.lastModified)) this.lastModified = w; @@ -339,7 +341,7 @@ public class WordReferenceVars extends AbstractReference implements WordReferenc if (this.virtualAge < (v = other.virtualAge)) this.virtualAge = v; if (this.wordsintext < (v = other.wordsintext)) this.wordsintext = v; if (this.phrasesintext < (v = other.phrasesintext)) this.phrasesintext = v; - if (other.positions != null) a(this.positions, Math.max(max(this.positions), max(other.positions))); + if (other.positions != null) a(this.positions, max(this.positions, other.positions)); if (this.posinphrase < (v = other.posinphrase)) this.posinphrase = v; if (this.posofphrase < (v = other.posofphrase)) this.posofphrase = v; if (this.lastModified < (w = other.lastModified)) this.lastModified = w; diff --git a/source/net/yacy/kelondro/rwi/AbstractReference.java b/source/net/yacy/kelondro/rwi/AbstractReference.java index 8c2ab30ba..cffb7fbfd 100644 --- a/source/net/yacy/kelondro/rwi/AbstractReference.java +++ b/source/net/yacy/kelondro/rwi/AbstractReference.java @@ -26,28 +26,48 @@ package net.yacy.kelondro.rwi; -import java.util.ArrayList; +import java.util.List; public abstract class AbstractReference implements Reference { - protected static void a(ArrayList a, int i) { + protected static void a(List a, int i) { assert a != null; - a.clear(); - a.add(i); + if (i < 0) return; // signal for 'do nothing' + synchronized (a) { + a.clear(); + a.add(i); + } + } + protected static int max(List a, List b) { + assert a != null; + if (a.size() == 0) return max(b); + if (b.size() == 0) return max(a); + return Math.max(max(a), max(b)); } - protected static int max(ArrayList a) { + protected static int min(List a, List b) { + assert a != null; + if (a.size() == 0) return min(b); + if (b.size() == 0) return min(a); + int ma = min(a); + int mb = min(b); + if (ma == -1) return mb; + if (mb == -1) return ma; + return Math.min(ma, mb); + } + + private static int max(List a) { assert a != null; - assert !a.isEmpty(); + if (a.size() == 0) return -1; if (a.size() == 1) return a.get(0); if (a.size() == 2) return Math.max(a.get(0), a.get(1)); int r = a.get(0); for (int i = 1; i < a.size(); i++) if (a.get(i) > r) r = a.get(i); return r; } - protected static int min(ArrayList a) { + private static int min(List a) { assert a != null; - assert !a.isEmpty(); + if (a.size() == 0) return -1; if (a.size() == 1) return a.get(0); if (a.size() == 2) return Math.min(a.get(0), a.get(1)); int r = a.get(0);