Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

more refactoring

orbiter474aac65af20
diff --git a/htroot/yacy/transferRWI.java b/htroot/yacy/transferRWI.java
index e21792644..bee64d17d 100644
--- a/htroot/yacy/transferRWI.java
+++ b/htroot/yacy/transferRWI.java
@@ -27,6 +27,7 @@
// javac -classpath .:../classes transferRWI.java
+import java.io.IOException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -157,7 +158,11 @@ public final class transferRWI {
}
// learn entry
- sb.webIndex.index().addEntry(wordHash, iEntry, System.currentTimeMillis());
+ try {
+ sb.webIndex.index().addReference(wordHash, iEntry);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
serverCore.checkInterruption();
// check if we need to ask for the corresponding URL
diff --git a/source/de/anomic/kelondro/text/CachedIndexCollection.java b/source/de/anomic/kelondro/text/CachedIndexCollection.java
index 56347d858..4d529dbb0 100644
--- a/source/de/anomic/kelondro/text/CachedIndexCollection.java
+++ b/source/de/anomic/kelondro/text/CachedIndexCollection.java
@@ -109,6 +109,12 @@ public final class CachedIndexCollection extends AbstractIndex implements Index,
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;
@@ -330,17 +336,7 @@ public final class CachedIndexCollection extends AbstractIndex implements Index,
}
- /*
- * methods to update the index
- */
- public void addEntry(final String wordHash, final ReferenceRow entry, final long updateTime) {
- // add the entry
- indexCache.addEntry(wordHash, entry, updateTime, true);
- cacheFlushControl();
- }
-
-
/*
* methods to search the index
*/
diff --git a/source/de/anomic/kelondro/text/Index.java b/source/de/anomic/kelondro/text/Index.java
index c99b49115..cd02c1089 100644
--- a/source/de/anomic/kelondro/text/Index.java
+++ b/source/de/anomic/kelondro/text/Index.java
@@ -37,13 +37,24 @@ public interface Index {
/**
* add references to the reverse index
- * when no references are stored, the new Entries are simply added,
- * if there are already references to the word that is denoted
- * with the reference stored, then merge the old and the new reference
+ * if no references to the word are stored, the new Entries are added,
+ * if there are already references to the word that is denoted with the
+ * reference to be stored, then the old and the new references are merged
* @param newEntries the References to be merged with existing references
* @throws IOException
*/
public void addReferences(ReferenceContainer newEntries) throws IOException;
+
+ /**
+ * add a single reference to the reverse index
+ * if no references to the word are stored, the a new entry is added,
+ * if there are already references to the word hash stored,
+ * then the old and the new references are merged
+ * @param wordHash
+ * @param entry
+ * @throws IOException
+ */
+ public void addReference(final String wordHash, final ReferenceRow entry) throws IOException;
/**
* check if there are references stored to the given word hash
diff --git a/source/de/anomic/kelondro/text/IndexCache.java b/source/de/anomic/kelondro/text/IndexCache.java
index ec5803270..6a5ccd2d1 100644
--- a/source/de/anomic/kelondro/text/IndexCache.java
+++ b/source/de/anomic/kelondro/text/IndexCache.java
@@ -299,8 +299,7 @@ public final class IndexCache extends AbstractIndex implements Index, IndexReade
}
public synchronized void addReferences(final ReferenceContainer container) {
- // this puts the entries into the cache, not into the assortment directly
- if ((container == null) || (container.size() == 0) || heap == null) return;
+ if (container == null || container.size() == 0 || heap == null) return;
// put new words into cache
heap.addReferences(container);
@@ -308,11 +307,13 @@ public final class IndexCache extends AbstractIndex implements Index, IndexReade
hashDate.setScore(container.getWordHash(), intTime(System.currentTimeMillis()));
}
- public synchronized void addEntry(final String wordHash, final ReferenceRow newEntry, final long updateTime, final boolean dhtCase) {
- if (heap == null) return; // there was already a shutdown
- heap.addEntry(wordHash, newEntry);
+ public void addReference(final String wordHash, final ReferenceRow entry) throws IOException {
+ if (entry == null || heap == null) return;
+
+ // put new words into cache
+ heap.addReference(wordHash, entry);
hashScore.incScore(wordHash);
- hashDate.setScore(wordHash, intTime(updateTime));
+ hashDate.setScore(wordHash, intTime(System.currentTimeMillis()));
}
public synchronized void close() {
diff --git a/source/de/anomic/kelondro/text/IndexCell.java b/source/de/anomic/kelondro/text/IndexCell.java
index 0a05ad96f..fd766507a 100644
--- a/source/de/anomic/kelondro/text/IndexCell.java
+++ b/source/de/anomic/kelondro/text/IndexCell.java
@@ -84,6 +84,11 @@ public final class IndexCell extends AbstractIndex implements Index {
if (this.ram.size() > this.maxRamEntries) cacheDump();
}
+ public synchronized void addReference(String hash, ReferenceRow entry) throws IOException {
+ this.ram.addReference(hash, entry);
+ if (this.ram.size() > this.maxRamEntries) cacheDump();
+ }
+
/**
* clear the RAM and BLOB part, deletes everything in the cell
* @throws IOException
diff --git a/source/de/anomic/kelondro/text/IndexCollection.java b/source/de/anomic/kelondro/text/IndexCollection.java
index 450c7f8a7..444328b9d 100644
--- a/source/de/anomic/kelondro/text/IndexCollection.java
+++ b/source/de/anomic/kelondro/text/IndexCollection.java
@@ -246,6 +246,17 @@ public class IndexCollection extends AbstractIndex implements Index {
}
}
+ public void addReference(String wordhash, ReferenceRow entry) {
+ if (entry == null) return;
+ try {
+ this.merge(new ReferenceContainer(wordhash, entry));
+ } catch (final kelondroOutOfLimitsException e) {
+ e.printStackTrace();
+ } catch (final IOException e) {
+ e.printStackTrace();
+ }
+ }
+
public int countReferences(String key) {
try {
final RowSet collection = this.get(key.getBytes());
diff --git a/source/de/anomic/kelondro/text/IndexPackage.java b/source/de/anomic/kelondro/text/IndexPackage.java
index 5257b2bd5..66cf55837 100644
--- a/source/de/anomic/kelondro/text/IndexPackage.java
+++ b/source/de/anomic/kelondro/text/IndexPackage.java
@@ -70,11 +70,6 @@ public interface IndexPackage extends Index {
public int cacheSize();
- /*
- * methods to update the index
- */
-
- public void addEntry(final String wordHash, final ReferenceRow entry, final long updateTime);
/*
* methods to search the index
diff --git a/source/de/anomic/kelondro/text/ReferenceContainer.java b/source/de/anomic/kelondro/text/ReferenceContainer.java
index 94814a819..319aef078 100644
--- a/source/de/anomic/kelondro/text/ReferenceContainer.java
+++ b/source/de/anomic/kelondro/text/ReferenceContainer.java
@@ -53,6 +53,12 @@ public class ReferenceContainer extends RowSet {
this.wordHash = wordHash;
}
+ public ReferenceContainer(String wordHash, ReferenceRow entry) {
+ super(ReferenceRow.urlEntryRow, 1);
+ this.add(entry);
+ this.wordHash = wordHash;
+ }
+
public ReferenceContainer(final String wordHash, final Row rowdef, final int objectCount) {
super(rowdef, objectCount);
this.wordHash = wordHash;
diff --git a/source/de/anomic/kelondro/text/ReferenceContainerCache.java b/source/de/anomic/kelondro/text/ReferenceContainerCache.java
index 3b8f5bc8c..eddbb3d6c 100644
--- a/source/de/anomic/kelondro/text/ReferenceContainerCache.java
+++ b/source/de/anomic/kelondro/text/ReferenceContainerCache.java
@@ -499,7 +499,7 @@ public final class ReferenceContainerCache extends AbstractIndex implements Inde
return;
}
- public synchronized void addEntry(final String wordHash, final ReferenceRow newEntry) {
+ public synchronized void addReference(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);
diff --git a/source/de/anomic/kelondro/text/ReferenceRow.java b/source/de/anomic/kelondro/text/ReferenceRow.java
index 23f3e4ec7..4503687c1 100644
--- a/source/de/anomic/kelondro/text/ReferenceRow.java
+++ b/source/de/anomic/kelondro/text/ReferenceRow.java
@@ -102,7 +102,7 @@ public final class ReferenceRow implements Reference, Cloneable {
final int posofphrase, // number of the phrase where word appears
final long lastmodified, // last-modified time of the document where word appears
final long updatetime, // update time; this is needed to compute a TTL for the word, so it can be removed easily if the TTL is short
- String language, // (guessed) language of document
+ final String language, // (guessed) language of document
final char doctype, // type of document
final int outlinksSame, // outlinks to same domain
final int outlinksOther, // outlinks to other domain
@@ -110,7 +110,6 @@ public final class ReferenceRow implements Reference, Cloneable {
) {
assert (urlHash.length() == 12) : "urlhash = " + urlHash;
- if ((language == null) || (language.length() != urlEntryRow.width(col_language))) language = "uk";
this.entry = urlEntryRow.newEntry();
final int mddlm = MicroDate.microDateDays(lastmodified);
final int mddct = MicroDate.microDateDays(updatetime);
@@ -121,7 +120,7 @@ public final class ReferenceRow implements Reference, Cloneable {
this.entry.setCol(col_wordsInText, wordcount);
this.entry.setCol(col_phrasesInText, phrasecount);
this.entry.setCol(col_doctype, new byte[]{(byte) doctype});
- this.entry.setCol(col_language, language, null);
+ this.entry.setCol(col_language, ((language == null) || (language.length() != urlEntryRow.width(col_language))) ? "uk" : language, null);
this.entry.setCol(col_llocal, outlinksSame);
this.entry.setCol(col_lother, outlinksOther);
this.entry.setCol(col_urlLength, urlLength);
diff --git a/source/de/anomic/plasma/plasmaWordIndex.java b/source/de/anomic/plasma/plasmaWordIndex.java
index e35afdb02..a64e87424 100644
--- a/source/de/anomic/plasma/plasmaWordIndex.java
+++ b/source/de/anomic/plasma/plasmaWordIndex.java
@@ -384,7 +384,11 @@ public final class plasmaWordIndex {
doctype,
outlinksSame, outlinksOther,
wprop.flags);
- this.index.addEntry(Word.word2hash(word), ientry, System.currentTimeMillis());
+ try {
+ this.index.addReference(Word.word2hash(word), ientry);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
wordCount++;
}