Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
- added signatures to ordering - added storage of orderings to database - orderings can be read from database when opening a database
orbiterc51e18c4ade3
diff --git a/source/de/anomic/kelondro/kelondroBase64Order.java b/source/de/anomic/kelondro/kelondroBase64Order.javaindex d31b0499a..ee058a30b 100644--- a/source/de/anomic/kelondro/kelondroBase64Order.java+++ b/source/de/anomic/kelondro/kelondroBase64Order.java@@ -83,6 +83,22 @@ public class kelondroBase64Order extends kelondroAbstractOrder implements kelondahpla = (rfc1113compliant) ? ahpla_standard : ahpla_enhanced;}+ public static kelondroOrder bySignature(String signature) {+ if (signature.equals("Bd")) return new kelondroBase64Order(false, false);+ if (signature.equals("bd")) return new kelondroBase64Order(false, true);+ if (signature.equals("Bu")) return new kelondroBase64Order(true, false);+ if (signature.equals("du")) return new kelondroBase64Order(true, true);+ return null;+ }++ public String signature() {+ if ((!asc) && (!rfc1113compliant)) return "Bd";+ if ((!asc) && ( rfc1113compliant)) return "bd";+ if (( asc) && (!rfc1113compliant)) return "Bu";+ if (( asc) && ( rfc1113compliant)) return "bu";+ return null;+ }+public char encodeByte(byte b) {return (char) alpha[b];}@@ -260,5 +276,6 @@ public class kelondroBase64Order extends kelondroAbstractOrder implements kelondSystem.out.println(b64.decodeString(s[1]));}}+}diff --git a/source/de/anomic/kelondro/kelondroDyn.java b/source/de/anomic/kelondro/kelondroDyn.javaindex 315c57265..7d08a56ef 100644--- a/source/de/anomic/kelondro/kelondroDyn.java+++ b/source/de/anomic/kelondro/kelondroDyn.java@@ -70,8 +70,12 @@ public class kelondroDyn extends kelondroTree {private int segmentCount;public kelondroDyn(File file, long buffersize /*bytes*/, int key, int nodesize, boolean exitOnFail) {+ this(file, buffersize, key, nodesize, new kelondroNaturalOrder(true), exitOnFail);+ }++ public kelondroDyn(File file, long buffersize /*bytes*/, int key, int nodesize, kelondroOrder objectOrder, boolean exitOnFail) {// creates a new dynamic tree- super(file, buffersize, new int[] {key + counterlen, nodesize}, 1, 8, exitOnFail);+ super(file, buffersize, new int[] {key + counterlen, nodesize}, objectOrder, 1, 8, exitOnFail);this.keylen = columnSize(0) - counterlen;this.reclen = columnSize(1);this.segmentCacheKey = null;diff --git a/source/de/anomic/kelondro/kelondroFScoreCluster.java b/source/de/anomic/kelondro/kelondroFScoreCluster.javaindex 4bf57d64a..5865a0536 100644--- a/source/de/anomic/kelondro/kelondroFScoreCluster.java+++ b/source/de/anomic/kelondro/kelondroFScoreCluster.java@@ -61,7 +61,7 @@ public class kelondroFScoreCluster {private kelondroTree refcountDB;private kelondroTree countrefDB;- public kelondroFScoreCluster(File refcountDBfile, File countrefDBfile, boolean exitOnFail) {+ public kelondroFScoreCluster(File refcountDBfile, File countrefDBfile, kelondroOrder objectOrder, boolean exitOnFail) {if ((refcountDBfile.exists()) && (countrefDBfile.exists())) try {refcountDB = new kelondroTree(refcountDBfile, 0x100000L);refcountDB.setText(0, kelondroBase64Order.enhancedCoder.encodeLong(0, countlength).getBytes()); // counter of all occurrences@@ -70,11 +70,11 @@ public class kelondroFScoreCluster {} catch (IOException e) {refcountDBfile.delete();countrefDBfile.delete();- refcountDB = new kelondroTree(refcountDBfile, 0x100000L, new int[] {wordlength, countlength}, 1, countlength, exitOnFail);- countrefDB = new kelondroTree(countrefDBfile, 0x100000L, new int[] {countlength + wordlength, 4}, 1, countlength, exitOnFail);+ refcountDB = new kelondroTree(refcountDBfile, 0x100000L, new int[] {wordlength, countlength}, objectOrder, 1, countlength, exitOnFail);+ countrefDB = new kelondroTree(countrefDBfile, 0x100000L, new int[] {countlength + wordlength, 4}, objectOrder, 1, countlength, exitOnFail);} else if ((!(refcountDBfile.exists())) && (!(countrefDBfile.exists()))) {- refcountDB = new kelondroTree(refcountDBfile, 0x100000L, new int[] {wordlength, countlength}, 1, countlength, exitOnFail);- countrefDB = new kelondroTree(countrefDBfile, 0x100000L, new int[] {countlength + wordlength, 4}, 1, countlength, exitOnFail);+ refcountDB = new kelondroTree(refcountDBfile, 0x100000L, new int[] {wordlength, countlength}, objectOrder, 1, countlength, exitOnFail);+ countrefDB = new kelondroTree(countrefDBfile, 0x100000L, new int[] {countlength + wordlength, 4}, objectOrder, 1, countlength, exitOnFail);} else {if (exitOnFail) {System.exit(-1);diff --git a/source/de/anomic/kelondro/kelondroNaturalOrder.java b/source/de/anomic/kelondro/kelondroNaturalOrder.javaindex 85fdba178..6cfee96e3 100644--- a/source/de/anomic/kelondro/kelondroNaturalOrder.java+++ b/source/de/anomic/kelondro/kelondroNaturalOrder.java@@ -57,6 +57,18 @@ public class kelondroNaturalOrder extends kelondroAbstractOrder implements kelonthis.asc = ascending;}+ public static kelondroOrder bySignature(String signature) {+ if (signature.equals("nd")) return new kelondroNaturalOrder(false);+ if (signature.equals("nu")) return new kelondroNaturalOrder(true);+ return null;+ }++ public String signature() {+ if (!asc) return "nd";+ if ( asc) return "nu";+ return null;+ }+public long cardinal(byte[] key) {// returns a cardinal number in the range of 0 .. Long.MAX_VALUElong c = 0;diff --git a/source/de/anomic/kelondro/kelondroOrder.java b/source/de/anomic/kelondro/kelondroOrder.javaindex 71693177f..f08775972 100644--- a/source/de/anomic/kelondro/kelondroOrder.java+++ b/source/de/anomic/kelondro/kelondroOrder.java@@ -49,6 +49,8 @@ import java.util.Comparator;public interface kelondroOrder extends Comparator {+ public String signature(); // returns a signature String so that different orderings have different signatures+public long partition(byte[] key, int forkes);public long cardinal(byte[] key); // returns a cardinal number in the range of 0 .. Long.MAX_VALUEdiff --git a/source/de/anomic/kelondro/kelondroSplittedTree.java b/source/de/anomic/kelondro/kelondroSplittedTree.javaindex 3252c5081..30d58f045 100644--- a/source/de/anomic/kelondro/kelondroSplittedTree.java+++ b/source/de/anomic/kelondro/kelondroSplittedTree.java@@ -72,10 +72,11 @@ public class kelondroSplittedTree implements kelondroIndex {return true;}- public kelondroSplittedTree(File pathToFiles, String filenameStub, kelondroOrder order,+ public kelondroSplittedTree(File pathToFiles, String filenameStub, kelondroOrder objectOrder,long buffersize,int forkfactor,- int[] columns, int txtProps, int txtPropsWidth,+ int[] columns,+ int txtProps, int txtPropsWidth,boolean exitOnFail) {ktfs = new kelondroTree[forkfactor];File f;@@ -84,31 +85,32 @@ public class kelondroSplittedTree implements kelondroIndex {if (f.exists()) {try {ktfs[i] = new kelondroTree(f, buffersize/forkfactor);+ this.order = ktfs[i].order();} catch (IOException e) {ktfs[i] = new kelondroTree(f, buffersize/forkfactor,- columns, txtProps, txtPropsWidth, exitOnFail);+ columns, objectOrder, txtProps, txtPropsWidth, exitOnFail);+ this.order = objectOrder;}} else {ktfs[i] = new kelondroTree(f, buffersize/forkfactor,- columns, txtProps, txtPropsWidth, exitOnFail);+ columns, objectOrder, txtProps, txtPropsWidth, exitOnFail);+ this.order = objectOrder;}}ff = forkfactor;- this.order = order;}- public kelondroSplittedTree(File pathToFiles, String filenameStub, kelondroOrder order,+ public kelondroSplittedTree(File pathToFiles, String filenameStub, kelondroOrder objectOrder,long buffersize, int forkfactor, int columns) throws IOException {ktfs = new kelondroTree[forkfactor];for (int i = 0; i < forkfactor; i++) {- ktfs[i] = new kelondroTree(dbFile(pathToFiles, filenameStub, forkfactor, columns, i),- buffersize/forkfactor);+ ktfs[i] = new kelondroTree(dbFile(pathToFiles, filenameStub, forkfactor, columns, i), buffersize/forkfactor);}ff = forkfactor;- this.order = order;+ this.order = objectOrder;}- public static kelondroSplittedTree open(File pathToFiles, String filenameStub, kelondroOrder order,+ public static kelondroSplittedTree open(File pathToFiles, String filenameStub, kelondroOrder objectOrder,long buffersize,int forkfactor,int[] columns, int txtProps, int txtPropsWidth,@@ -116,9 +118,9 @@ public class kelondroSplittedTree implements kelondroIndex {// generated a new splittet tree if it not exists or// opens an existing oneif (existsAll(pathToFiles, filenameStub, forkfactor, columns.length)) {- return new kelondroSplittedTree(pathToFiles, filenameStub, order, buffersize, forkfactor, columns.length);+ return new kelondroSplittedTree(pathToFiles, filenameStub, objectOrder, buffersize, forkfactor, columns.length);} else {- return new kelondroSplittedTree(pathToFiles, filenameStub, order,+ return new kelondroSplittedTree(pathToFiles, filenameStub, objectOrder,buffersize,forkfactor,columns, txtProps, txtPropsWidth,@@ -126,7 +128,6 @@ public class kelondroSplittedTree implements kelondroIndex {}}-public int columns() {return ktfs[0].columns();}diff --git a/source/de/anomic/kelondro/kelondroTree.java b/source/de/anomic/kelondro/kelondroTree.javaindex 2948a1930..5802f2574 100644--- a/source/de/anomic/kelondro/kelondroTree.java+++ b/source/de/anomic/kelondro/kelondroTree.java@@ -78,19 +78,19 @@ public class kelondroTree extends kelondroRecords implements kelondroIndex {private kelondroOrder objectOrder = new kelondroNaturalOrder(true);public kelondroTree(File file, long buffersize, int key, int value, boolean exitOnFail) {- this(file, buffersize, new int[] { key, value }, 1, 8, exitOnFail);+ this(file, buffersize, new int[] { key, value }, new kelondroNaturalOrder(true), 1, 8, exitOnFail);}public kelondroTree(kelondroRA ra, long buffersize, int key, int value, boolean exitOnFail) {- this(ra, buffersize, new int[] { key, value }, 1, 8, exitOnFail);+ this(ra, buffersize, new int[] { key, value }, new kelondroNaturalOrder(true), 1, 8, exitOnFail);}public kelondroTree(File file, long buffersize, int[] columns, boolean exitOnFail) {// this creates a new tree file- this(file, buffersize, columns, columns.length /* txtProps */, 80 /* txtPropWidth */, exitOnFail);+ this(file, buffersize, columns, new kelondroNaturalOrder(true), columns.length /* txtProps */, 80 /* txtPropWidth */, exitOnFail);}- public kelondroTree(File file, long buffersize, int[] columns, int txtProps, int txtPropsWidth, boolean exitOnFail) {+ public kelondroTree(File file, long buffersize, int[] columns, kelondroOrder objectOrder, int txtProps, int txtPropsWidth, boolean exitOnFail) {// this creates a new tree filesuper(file, buffersize, thisOHBytes, thisOHHandles, columns, thisFHandles, txtProps, txtPropsWidth, exitOnFail);try {@@ -100,14 +100,16 @@ public class kelondroTree extends kelondroRecords implements kelondroIndex {if (exitOnFail) System.exit(-1);throw new RuntimeException("cannot set root handle / " + e.getMessage());}+ this.objectOrder = objectOrder;+ writeOrderType();}public kelondroTree(kelondroRA ra, long buffersize, int[] columns, boolean exitOnFail) {// this creates a new tree within a kelondroRA- this(ra, buffersize, columns, columns.length /* txtProps */, 80 /* txtPropWidth */, exitOnFail);+ this(ra, buffersize, columns, new kelondroNaturalOrder(true), columns.length /* txtProps */, 80 /* txtPropWidth */, exitOnFail);}- public kelondroTree(kelondroRA ra, long buffersize, int[] columns, int txtProps, int txtPropsWidth, boolean exitOnFail) {+ public kelondroTree(kelondroRA ra, long buffersize, int[] columns, kelondroOrder objectOrder, int txtProps, int txtPropsWidth, boolean exitOnFail) {// this creates a new tree within a kelondroRAsuper(ra, buffersize, thisOHBytes, thisOHHandles, columns,thisFHandles, txtProps, txtPropsWidth, exitOnFail);@@ -118,18 +120,44 @@ public class kelondroTree extends kelondroRecords implements kelondroIndex {if (exitOnFail) System.exit(-1);throw new RuntimeException("cannot set root handle / " + e.getMessage());}+ this.objectOrder = objectOrder;+ writeOrderType();}public kelondroTree(File file, long buffersize) throws IOException {// this opens a file with an existing tree filesuper(file, buffersize);+ readOrderType();}public kelondroTree(kelondroRA ra, long buffersize) throws IOException {// this opens a file with an existing tree in a kelondroRAsuper(ra, buffersize);+ readOrderType();}+ private void writeOrderType() {+ try {+ super.setDescription(objectOrder.signature().getBytes());+ } catch (IOException e) {};+ }++ private void readOrderType() {+ try {+ byte[] d = super.getDescription();+ String s = new String(d).substring(0, 2);+ this.objectOrder = orderBySignature(s);+ } catch (IOException e) {};+ }++ public static kelondroOrder orderBySignature(String signature) {+ kelondroOrder oo = null;+ if (oo == null) oo = kelondroNaturalOrder.bySignature(signature);+ if (oo == null) oo = kelondroBase64Order.bySignature(signature);+ if (oo == null) oo = new kelondroNaturalOrder(true);+ return oo;+ }+public void clear() throws IOException {super.clear();setHandle(root, null); // reset the root value