Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
moved table row/column matching method from front-end to back-end
orbiter0018163c0779
diff --git a/htroot/Table_API_p.java b/htroot/Table_API_p.javaindex 6e7b24d4c..797cd6fb3 100644--- a/htroot/Table_API_p.java+++ b/htroot/Table_API_p.java@@ -106,7 +106,8 @@ public class Table_API_p {// insert rowsint count = 0;try {- final Iterator<Tables.Row> mapIterator = sb.tables.orderBy(WorkTables.TABLE_API_NAME, -1, WorkTables.TABLE_API_COL_DATE).iterator();+ final Iterator<Tables.Row> plainIterator = sb.tables.iterator(WorkTables.TABLE_API_NAME);+ final Iterator<Tables.Row> mapIterator = sb.tables.orderBy(plainIterator, -1, WorkTables.TABLE_API_COL_DATE).iterator();Tables.Row row;boolean dark = true;while (mapIterator.hasNext()) {diff --git a/htroot/Tables_p.java b/htroot/Tables_p.javaindex 4054c665f..2b6e76047 100644--- a/htroot/Tables_p.java+++ b/htroot/Tables_p.java@@ -173,26 +173,15 @@ public class Tables_p {}count = 0;try {- final Iterator<Tables.Row> mapIterator = sb.tables.orderByPK(table, (matcher == null) ? maxcount : -1).iterator();+ final Iterator<Tables.Row> plainIterator = sb.tables.iterator(table, matcher);+ final Iterator<Tables.Row> mapIterator = sb.tables.orderByPK(plainIterator, maxcount).iterator();Tables.Row row;boolean dark = true;byte[] cell;- tableloop: while (mapIterator.hasNext() && count < maxcount) {+ while (mapIterator.hasNext() && count < maxcount) {row = mapIterator.next();if (row == null) continue;- // check matcher- boolean matched = matcher == null;- if (matcher != null) checkloop: for (int i = 0; i < columns.size(); i++) {- cell = row.from(columns.get(i));- if (cell == null) continue checkloop;- if (matcher.matcher(new String(cell)).matches()) {- matched = true;- break checkloop;- }- }- if (!matched) continue tableloop;-// write table contentprop.put("showtable_list_" + count + "_dark", ((dark) ? 1 : 0) ); dark=!dark;prop.put("showtable_list_" + count + "_pk", new String(row.getPK()));diff --git a/htroot/api/table_p.java b/htroot/api/table_p.javaindex cbd9dcb67..3692c4fb6 100644--- a/htroot/api/table_p.java+++ b/htroot/api/table_p.java@@ -82,7 +82,8 @@ public class table_p {}int count = 0;try {- final Iterator<Tables.Row> mapIterator = sb.tables.orderByPK(table, maxCount).iterator();+ final Iterator<Tables.Row> plainIterator = sb.tables.iterator(table);+ final Iterator<Tables.Row> mapIterator = sb.tables.orderByPK(plainIterator, maxCount).iterator();Tables.Row trow;boolean dark = true;byte[] cell;diff --git a/source/net/yacy/kelondro/blob/Tables.java b/source/net/yacy/kelondro/blob/Tables.javaindex f67076a11..3d621ef4c 100644--- a/source/net/yacy/kelondro/blob/Tables.java+++ b/source/net/yacy/kelondro/blob/Tables.java@@ -36,6 +36,7 @@ import java.util.Iterator;import java.util.Map;import java.util.TreeMap;import java.util.concurrent.ConcurrentHashMap;+import java.util.regex.Pattern;import net.yacy.kelondro.index.RowSpaceExceededException;import net.yacy.kelondro.logging.Log;@@ -334,37 +335,35 @@ public class Tables {return new RowIterator(table);}- public Iterator<Row> iterator(String table, String whereKey, byte[] whereValue) throws IOException {- return new RowIterator(table, whereKey, whereValue);+ public Iterator<Row> iterator(String table, String whereColumn, byte[] whereValue) throws IOException {+ return new RowIterator(table, whereColumn, whereValue);}- public Collection<Row> orderByPK(String table, int maxcount) throws IOException {- return orderByPK(table, maxcount, null, null);+ public Iterator<Row> iterator(String table, String whereColumn, Pattern wherePattern) throws IOException {+ return new RowIterator(table, whereColumn, wherePattern);}- public Collection<Row> orderByPK(String table, int maxcount, String whereKey, byte[] whereValue) throws IOException {+ public Iterator<Row> iterator(String table, Pattern wherePattern) throws IOException {+ return new RowIterator(table, wherePattern);+ }++ public Collection<Row> orderByPK(Iterator<Row> rowIterator, int maxcount) throws IOException {TreeMap<String, Row> sortTree = new TreeMap<String, Row>();- Iterator<Row> i = iterator(table, whereKey, whereValue);Row row;- while ((maxcount < 0 || maxcount-- > 0) && i.hasNext()) {- row = i.next();+ while ((maxcount < 0 || maxcount-- > 0) && rowIterator.hasNext()) {+ row = rowIterator.next();sortTree.put(new String(row.pk), row);}return sortTree.values();}- public Collection<Row> orderBy(String table, int maxcount, String sortField) throws IOException {- return orderBy(table, maxcount, sortField, null, null);- }-- public Collection<Row> orderBy(String table, int maxcount, String sortField, String whereKey, byte[] whereValue) throws IOException {+ public Collection<Row> orderBy(Iterator<Row> rowIterator, int maxcount, String sortColumn) throws IOException {TreeMap<String, Row> sortTree = new TreeMap<String, Row>();- Iterator<Row> i = iterator(table, whereKey, whereValue);Row row;byte[] r;- while ((maxcount < 0 || maxcount-- > 0) && i.hasNext()) {- row = i.next();- r = row.from(sortField);+ while ((maxcount < 0 || maxcount-- > 0) && rowIterator.hasNext()) {+ row = rowIterator.next();+ r = row.from(sortColumn);if (r == null) continue;sortTree.put(new String(r) + new String(row.pk), row);}@@ -378,20 +377,68 @@ public class Tables {public class RowIterator extends LookAheadIterator<Row> implements Iterator<Row> {- private final String whereKey;+ private final String whereColumn;private final byte[] whereValue;+ private final Pattern wherePattern;private final Iterator<Map.Entry<byte[], Map<String, byte[]>>> i;+ /**+ * iterator that iterates all elements in the given table+ * @param table+ * @throws IOException+ */public RowIterator(String table) throws IOException {- this.whereKey = null;+ this.whereColumn = null;this.whereValue = null;+ this.wherePattern = null;BEncodedHeap heap = getHeap(table);i = heap.iterator();}- public RowIterator(String table, String whereKey, byte[] whereValue) throws IOException {- this.whereKey = whereKey;+ /**+ * iterator that iterates all elements in the given table+ * where a given column is equal to a given value+ * @param table+ * @param whereColumn+ * @param whereValue+ * @throws IOException+ */+ public RowIterator(String table, String whereColumn, byte[] whereValue) throws IOException {+ assert whereColumn != null || whereValue == null;+ this.whereColumn = whereColumn;this.whereValue = whereValue;+ this.wherePattern = null;+ BEncodedHeap heap = getHeap(table);+ i = heap.iterator();+ }++ /**+ * iterator that iterates all elements in the given table+ * where a given column matches with a given value+ * @param table+ * @param whereColumn+ * @param wherePattern+ * @throws IOException+ */+ public RowIterator(String table, String whereColumn, Pattern wherePattern) throws IOException {+ this.whereColumn = whereColumn;+ this.whereValue = null;+ this.wherePattern = wherePattern;+ BEncodedHeap heap = getHeap(table);+ i = heap.iterator();+ }++ /**+ * iterator that iterates all elements in the given table+ * where any column matches with a given value+ * @param table+ * @param pattern+ * @throws IOException+ */+ public RowIterator(String table, Pattern pattern) throws IOException {+ this.whereColumn = null;+ this.whereValue = null;+ this.wherePattern = pattern;BEncodedHeap heap = getHeap(table);i = heap.iterator();}@@ -399,8 +446,21 @@ public class Tables {protected Row next0() {while (i.hasNext()) {Row r = new Row(i.next());- if (this.whereKey == null) return r;- if (ByteBuffer.equals(r.from(this.whereKey), this.whereValue)) return r;+ if (this.whereValue != null) {+ if (ByteBuffer.equals(r.from(this.whereColumn), this.whereValue)) return r;+ } else if (this.wherePattern != null) {+ if (this.whereColumn == null) {+ // shall match any column+ for (byte[] b: r.values()) {+ if (this.wherePattern.matcher(new String(b)).matches()) return r;+ }+ } else {+ // must match the given column+ if (this.wherePattern.matcher(new String(r.from(this.whereColumn))).matches()) return r;+ }+ } else {+ return r;+ }}return null;}@@ -450,6 +510,10 @@ public class Tables {return r;}+ protected Collection<byte[]> values() {+ return this.map.values();+ }+public String toString() {StringBuilder sb = new StringBuilder(keymaxlen + 20 * map.size());sb.append(new String(pk)).append(":").append(map.toString());