Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
Added server side columns sorting on the Process Scheduler table
luccioman2bdd71de60a8
diff --git a/htroot/Table_API_p.html b/htroot/Table_API_p.htmlindex 273333314..e3ccd77dd 100644--- a/htroot/Table_API_p.html+++ b/htroot/Table_API_p.html@@ -63,9 +63,9 @@ To see a list of all APIs, please visit the <a href="http://www.yacy-websuche.de<span id="resCounter" style="display: inline;">#(navigation)#::- #(left)#<img src="env/grafics/navdl.gif" alt="no previous page" />::<a href="Table_API_p.html?startRecord=#[startRecord]#&maximumRecords=#[maximumRecords]#&inline=#(inline)#false::true#(/inline)#&filter=#[filter]#&query=#[query]#" target="_self"><img src="env/grafics/navsl.gif" alt="previous page" /></a>#(/left)#+ #(left)#<img src="env/grafics/navdl.gif" alt="no previous page" />::<a href="Table_API_p.html?startRecord=#[startRecord]#&maximumRecords=#[maximumRecords]#&inline=#(inline)#false::true#(/inline)#&filter=#[filter]#&query=#[query]#&sort=#[sort]#" target="_self"><img src="env/grafics/navsl.gif" alt="previous page" /></a>#(/left)##[startRecord]#-#[to]# of #[of]#- #(right)#<img src="env/grafics/navdr.gif" alt="no next page" />::<a href="Table_API_p.html?startRecord=#[startRecord]#&maximumRecords=#[maximumRecords]#&inline=#(inline)#false::true#(/inline)#&filter=#[filter]#&query=#[query]#" target="_self"><img src="env/grafics/navsr.gif" alt="next page" /></a>#(/right)#+ #(right)#<img src="env/grafics/navdr.gif" alt="no next page" />::<a href="Table_API_p.html?startRecord=#[startRecord]#&maximumRecords=#[maximumRecords]#&inline=#(inline)#false::true#(/inline)#&filter=#[filter]#&query=#[query]#&sort=#[sort]#" target="_self"><img src="env/grafics/navsr.gif" alt="next page" /></a>#(/right)#<img src="env/grafics/nave.gif" alt="" />#(/navigation)#@@ -73,23 +73,43 @@ To see a list of all APIs, please visit the <a href="http://www.yacy-websuche.de<input type="hidden" name="maximumRecords" value="#[maximumRecords]#" /><input type="hidden" name="inline" value="#(inline)#false::true#(/inline)#" /><input type="hidden" name="filter" value="#[filter]#" />+ <input type="hidden" name="sort" value="#[sort]#" /><input type="text" name="query" value="#[query]#" onchange="resetStartRecord()" style="font-size:16px;float:left;border:0px;height:20px;background-image:url('env/grafics/find.gif');background-repeat:no-repeat;background-position:right top;"/></span><br/><div style="clear:both;">- <table class="sortable" style="border:0px; padding:2px; border-spacing:1px">+ <table style="border:0px; padding:2px; border-spacing:1px" role="grid"><tr class="TableHeader" valign="bottom"><th class="sorttable_nosort"><input type="checkbox" id="allswitch" onclick="checkAll(this.form.id, this.checked);" /></th>- <th>Type</th>- <th style="width: 100%;">Comment</th>- <th>Call<br/>Count</th>- <th>Recording<br/>Date</th>- <th>Last Exec<br/>Date</th>- <th>Next Exec<br/>Date#(hasEditableNextExecDate)#:: <button type="submit" name="submitNextExecDates" class="btn btn-default btn-xs" title="Apply edited next execution dates">+ <th #(sortedByType)#::aria-sort="#(asc)#descending::ascending#(/asc)#"#(/sortedByType)#>+ <a class="sortTableLink" href="Table_API_p.html?startRecord=#[startRecord]#&maximumRecords=#[maximumRecords]#&sort=#(nextSortTypeDesc)#::-#(/nextSortTypeDesc)#type&inline=#(inline)#false::true#(/inline)#&filter=#[filter]#&query=#[query]#" target="_self" title="Sort by #(nextSortTypeDesc)#ascending::descending#(/nextSortTypeDesc)# types">Type</a>+ #(sortedByType)#::<span class="glyphicon glyphicon-chevron-#(asc)#down::up#(/asc)#"></span>#(/sortedByType)#+ </th>+ <th style="width: 100%;" #(sortedByComment)#::aria-sort="#(asc)#descending::ascending#(/asc)#"#(/sortedByComment)#>+ <a class="sortTableLink" href="Table_API_p.html?startRecord=#[startRecord]#&maximumRecords=#[maximumRecords]#&sort=#(nextSortCommentDesc)#::-#(/nextSortCommentDesc)#comment&inline=#(inline)#false::true#(/inline)#&filter=#[filter]#&query=#[query]#" target="_self" title="Sort by #(nextSortCommentDesc)#ascending::descending#(/nextSortCommentDesc)# comments">Comment</a>+ #(sortedByComment)#::<span class="glyphicon glyphicon-chevron-#(asc)#down::up#(/asc)#"></span>#(/sortedByComment)#+ </th>+ <th #(sortedByApiCallCount)#::aria-sort="#(asc)#descending::ascending#(/asc)#"#(/sortedByApiCallCount)#>+ <a class="sortTableLink" href="Table_API_p.html?startRecord=#[startRecord]#&maximumRecords=#[maximumRecords]#&sort=#(nextSortApiCallCountDesc)#::-#(/nextSortApiCallCountDesc)#apicall_count&inline=#(inline)#false::true#(/inline)#&filter=#[filter]#&query=#[query]#" target="_self" title="Sort by #(nextSortApiCallCountDesc)#ascending::descending#(/nextSortApiCallCountDesc)# call counts">Call Count</a>+ #(sortedByApiCallCount)#::<span class="glyphicon glyphicon-chevron-#(asc)#down::up#(/asc)#"></span>#(/sortedByApiCallCount)#+ </th>+ <th #(sortedByDateRecording)#::aria-sort="#(asc)#descending::ascending#(/asc)#"#(/sortedByDateRecording)#>+ <a class="sortTableLink" href="Table_API_p.html?startRecord=#[startRecord]#&maximumRecords=#[maximumRecords]#&sort=#(nextSortDateRecordingDesc)#::-#(/nextSortDateRecordingDesc)#date_recording&inline=#(inline)#false::true#(/inline)#&filter=#[filter]#&query=#[query]#" target="_self" title="Sort by #(nextSortDateRecordingDesc)#ascending::descending#(/nextSortDateRecordingDesc)# recording dates">Recording Date</a>+ #(sortedByDateRecording)#::<span class="glyphicon glyphicon-chevron-#(asc)#down::up#(/asc)#"></span>#(/sortedByDateRecording)#+ </th>+ <th #(sortedByDateLastExec)#::aria-sort="#(asc)#descending::ascending#(/asc)#"#(/sortedByDateLastExec)#>+ <a class="sortTableLink" href="Table_API_p.html?startRecord=#[startRecord]#&maximumRecords=#[maximumRecords]#&sort=#(nextSortDateLastExecDesc)#::-#(/nextSortDateLastExecDesc)#date_last_exec&inline=#(inline)#false::true#(/inline)#&filter=#[filter]#&query=#[query]#" target="_self" title="Sort by #(nextSortDateLastExecDesc)#ascending::descending#(/nextSortDateLastExecDesc)# last execution dates">Last Exec Date</a>+ #(sortedByDateLastExec)#::<span class="glyphicon glyphicon-chevron-#(asc)#down::up#(/asc)#"></span>#(/sortedByDateLastExec)#+ </th>+ <th #(sortedByDateNextExec)#::aria-sort="#(asc)#descending::ascending#(/asc)#"#(/sortedByDateNextExec)#>+ <a class="sortTableLink" href="Table_API_p.html?startRecord=#[startRecord]#&maximumRecords=#[maximumRecords]#&sort=#(nextSortDateNextExecDesc)#::-#(/nextSortDateNextExecDesc)#date_next_exec&inline=#(inline)#false::true#(/inline)#&filter=#[filter]#&query=#[query]#" target="_self" title="Sort by #(nextSortDateNextExecDesc)#ascending::descending#(/nextSortDateNextExecDesc)# last execution dates">Next Exec Date</a>+ #(sortedByDateNextExec)#::<span class="glyphicon glyphicon-chevron-#(asc)#down::up#(/asc)#"></span>#(/sortedByDateNextExec)#+ #(hasEditableNextExecDate)#:: <button type="submit" name="submitNextExecDates" class="btn btn-default btn-xs" title="Apply edited next execution dates"><span class="glyphicon glyphicon-ok"></span><span> Apply</span>- </button>#(/hasEditableNextExecDate)#+ </button>+ #(/hasEditableNextExecDate)#</th><th class="sorttable_nosort">Event Trigger</th><th class="sorttable_nosort">Scheduler</th>diff --git a/htroot/Table_API_p.java b/htroot/Table_API_p.javaindex 1b36adaba..24400f3a7 100644--- a/htroot/Table_API_p.java+++ b/htroot/Table_API_p.java@@ -44,6 +44,7 @@ import net.yacy.data.TransactionManager;import net.yacy.data.WorkTables;import net.yacy.kelondro.blob.Tables;import net.yacy.kelondro.blob.Tables.Row;+import net.yacy.kelondro.blob.Tables.SortDirection;import net.yacy.search.Switchboard;import net.yacy.search.SwitchboardConstants;import net.yacy.search.query.QueryParams;@@ -86,6 +87,21 @@ public class Table_API_p {if (post != null && post.containsKey("filter") && post.get("filter", "").length() > 0) {typefilter = Pattern.compile(post.get("filter", ".*"));}++ /* Applying JSON API convention for the sort parameter format (http://jsonapi.org/format/#fetching-sorting) */+ String sortParam = WorkTables.TABLE_API_COL_DATE_RECORDING;+ if(post != null) {+ sortParam = post.get("sort", WorkTables.TABLE_API_COL_DATE_RECORDING).trim();+ }+ final SortDirection sortDir;+ final String sortColumn;+ if(sortParam.startsWith("-")) {+ sortColumn = sortParam.substring(1);+ sortDir = SortDirection.DESC;+ } else {+ sortColumn = sortParam;+ sortDir = SortDirection.ASC;+ }// process scheduler and event input actionsboolean scheduleeventaction = false; // flag if schedule info of row changes@@ -310,6 +326,8 @@ public class Table_API_p {final String nextTransactionToken = TransactionManager.getTransactionToken(header);prop.put(TransactionManager.TRANSACTION_TOKEN_PARAM, nextTransactionToken);prop.put("showtable_" + TransactionManager.TRANSACTION_TOKEN_PARAM, nextTransactionToken);++ final Date now = new Date();// insert rowsfinal List<Tables.Row> table = new ArrayList<Tables.Row>(maximumRecords);@@ -319,7 +337,22 @@ public class Table_API_p {try {tablesize = sb.tables.size(WorkTables.TABLE_API_NAME);final Iterator<Tables.Row> plainIterator = sb.tables.iterator(WorkTables.TABLE_API_NAME);- final Iterator<Tables.Row> mapIterator = Tables.orderBy(plainIterator, -1, WorkTables.TABLE_API_COL_DATE_RECORDING).iterator();+ final Iterator<Tables.Row> mapIterator;+ if(sortColumn.isEmpty()) {+ mapIterator = plainIterator;+ } else {+ if (WorkTables.TABLE_API_COL_APICALL_COUNT.equals(sortColumn)+ || WorkTables.TABLE_API_COL_APICALL_SCHEDULE_TIME.equals(sortColumn)) {+ mapIterator = Tables.orderByInt(plainIterator, sortColumn, 0, sortDir).iterator();+ } else if (WorkTables.TABLE_API_COL_DATE.equals(sortColumn)+ || WorkTables.TABLE_API_COL_DATE_RECORDING.equals(sortColumn)+ || WorkTables.TABLE_API_COL_DATE_LAST_EXEC.equals(sortColumn)+ || WorkTables.TABLE_API_COL_DATE_NEXT_EXEC.equals(sortColumn)) {+ mapIterator = Tables.orderByDate(plainIterator, sortColumn, now, sortDir).iterator();+ } else {+ mapIterator = Tables.orderByString(plainIterator, sortColumn, "", sortDir).iterator();+ }+ }Tables.Row r;boolean dark = true;boolean scheduledactions = false;@@ -380,7 +413,6 @@ public class Table_API_p {// then work on the listfor (final Tables.Row row : table) {final String rowPKStr = UTF8.String(row.getPK());- final Date now = new Date();final Date date = row.containsKey(WorkTables.TABLE_API_COL_DATE) ? row.get(WorkTables.TABLE_API_COL_DATE, now) : null;final Date date_recording = row.get(WorkTables.TABLE_API_COL_DATE_RECORDING, date);final Date date_last_exec = row.get(WorkTables.TABLE_API_COL_DATE_LAST_EXEC, date);@@ -536,6 +568,10 @@ public class Table_API_p {prop.put("showtable_inline", (inline) ? 1 : 0);prop.put("showtable_filter", typefilter.pattern());prop.put("showtable_query", queryParam);+ prop.put("showtable_sort", sortParam);++ putTableSortProperties(prop, sortDir, sortColumn);+if (filteredSize > maximumRecords) {prop.put("showtable_navigation", 1);prop.put("showtable_navigation_startRecord", startRecord);@@ -547,6 +583,7 @@ public class Table_API_p {prop.put("showtable_navigation_left_inline", (inline) ? 1 : 0);prop.put("showtable_navigation_left_filter", typefilter.pattern());prop.put("showtable_navigation_left_query", queryParam);+ prop.put("showtable_navigation_left_sort", sortParam);prop.put("showtable_navigation_left", startRecord == 0 ? 0 : 1);prop.put("showtable_navigation_filter", typefilter.pattern());prop.put("showtable_navigation_right", startRecord + maximumRecords >= filteredSize ? 0 : 1);@@ -555,6 +592,7 @@ public class Table_API_p {prop.put("showtable_navigation_right_inline", (inline) ? 1 : 0);prop.put("showtable_navigation_right_filter", typefilter.pattern());prop.put("showtable_navigation_right_query", queryParam);+ prop.put("showtable_navigation_right_sort", sortParam);} else {prop.put("showtable_navigation", 0);}@@ -562,4 +600,47 @@ public class Table_API_p {// return rewrite propertiesreturn prop;}++ /**+ * Fill the serverObjects instance with table columns sort properties.+ *+ * @param prop+ * the serverObjects instance to fill. Must not be null.+ * @param sortDir+ * the current sort direction+ * @param sortColumn+ * the current sort column+ */+ private static void putTableSortProperties(final serverObjects prop, final SortDirection sortDir,+ final String sortColumn) {+ boolean sortedByAsc = WorkTables.TABLE_API_COL_TYPE.equals(sortColumn) && sortDir == SortDirection.ASC;+ prop.put("showtable_sortedByType", WorkTables.TABLE_API_COL_TYPE.equals(sortColumn));+ prop.put("showtable_sortedByType_asc", sortedByAsc);+ prop.put("showtable_nextSortTypeDesc", sortedByAsc);++ sortedByAsc = WorkTables.TABLE_API_COL_COMMENT.equals(sortColumn) && sortDir == SortDirection.ASC;+ prop.put("showtable_sortedByComment", WorkTables.TABLE_API_COL_COMMENT.equals(sortColumn));+ prop.put("showtable_sortedByComment_asc", sortedByAsc);+ prop.put("showtable_nextSortCommentDesc", sortedByAsc);++ sortedByAsc = WorkTables.TABLE_API_COL_APICALL_COUNT.equals(sortColumn) && sortDir == SortDirection.ASC;+ prop.put("showtable_sortedByApiCallCount", WorkTables.TABLE_API_COL_APICALL_COUNT.equals(sortColumn));+ prop.put("showtable_sortedByApiCallCount_asc", sortedByAsc);+ prop.put("showtable_nextSortApiCallCountDesc", sortedByAsc);++ sortedByAsc = WorkTables.TABLE_API_COL_DATE_RECORDING.equals(sortColumn) && sortDir == SortDirection.ASC;+ prop.put("showtable_sortedByDateRecording", WorkTables.TABLE_API_COL_DATE_RECORDING.equals(sortColumn));+ prop.put("showtable_sortedByDateRecording_asc", sortedByAsc);+ prop.put("showtable_nextSortDateRecordingDesc", sortedByAsc);++ sortedByAsc = WorkTables.TABLE_API_COL_DATE_LAST_EXEC.equals(sortColumn) && sortDir == SortDirection.ASC;+ prop.put("showtable_sortedByDateLastExec", WorkTables.TABLE_API_COL_DATE_LAST_EXEC.equals(sortColumn));+ prop.put("showtable_sortedByDateLastExec_asc", sortedByAsc);+ prop.put("showtable_nextSortDateLastExecDesc", sortedByAsc);++ sortedByAsc = WorkTables.TABLE_API_COL_DATE_NEXT_EXEC.equals(sortColumn) && sortDir == SortDirection.ASC;+ prop.put("showtable_sortedByDateNextExec", WorkTables.TABLE_API_COL_DATE_NEXT_EXEC.equals(sortColumn));+ prop.put("showtable_sortedByDateNextExec_asc", sortedByAsc);+ prop.put("showtable_nextSortDateNextExecDesc", sortedByAsc);+ }}diff --git a/htroot/env/base.css b/htroot/env/base.cssindex bce01887e..71c481513 100644--- a/htroot/env/base.css+++ b/htroot/env/base.css@@ -15,7 +15,7 @@## "global classes" ### i.e. ".strong"; ".left"; ".error";###############################################-## "privat classes" ##+## "private classes" ### all HTML-elements with a specific class# i.e. "div.content"; "span.left";# and@@ -607,6 +607,12 @@ a.thumblink {overflow: hidden;}+/* Link in a table header that triggers server-side table sorting */+a.sortTableLink, a.sortTableLink:link, a.sortTableLink:visited, a.sortTableLink:hover {+ text-decoration: none;+ color: white;+}+/*----------<em>*/diff --git a/locales/de.lng b/locales/de.lngindex 2b746b4f7..f7927e349 100644--- a/locales/de.lng+++ b/locales/de.lng@@ -3294,13 +3294,12 @@ to a scheduler for a periodic execution.==einem Scheduler für periodische Ausf"next page"=="Keine nächste Seite""previous page"=="Keine vorherige Seite"of #[of]#== von #[of]#->Date==>Datum>Type==>Typ>Comment==>Kommentar-Call<br/>Count<==Aufruf<br/>Zähler<-Recording<==Aufzeichnungs<-Last Exec==Letzte Ausführung-Next Exec==Nächste Ausführung+Call Count<==Aufruf Zähler<+Recording Date==Aufzeichnungs Datum+Last Exec Date==Letzte Ausführung Datum+Next Exec Date==Nächste Ausführung Datum#>URL<==>URL<>Event Trigger<==>Ereignis Auslöser<"clone"=="Ereignis klonen"diff --git a/locales/it.lng b/locales/it.lngindex 13023a70b..37743f18b 100644--- a/locales/it.lng+++ b/locales/it.lng@@ -1215,7 +1215,7 @@ YaCy Supporters<==Sostenitori di YaCy<"next page"=="pagina successiva""previous page"=="pagina precedente"# of #[of]#== su #[of]#->Date==>Data+ Date== Data>URL<==>URL<"clone"=="clona">Scheduler<==>Schedulatore<diff --git a/locales/master.lng.xlf b/locales/master.lng.xlfindex b4fa62804..26ef0b7c9 100644--- a/locales/master.lng.xlf+++ b/locales/master.lng.xlf@@ -8765,9 +8765,6 @@<trans-unit id="1449865e" xml:space="preserve" approved="no" translate="yes"><source> of #[of]#</source></trans-unit>- <trans-unit id="38a150c" xml:space="preserve" approved="no" translate="yes">- <source>>Date</source>- </trans-unit><trans-unit id="391b498" xml:space="preserve" approved="no" translate="yes"><source>>Type</source></trans-unit>@@ -8775,16 +8772,16 @@<source>>Comment</source></trans-unit><trans-unit id="c2a0ac2a" xml:space="preserve" approved="no" translate="yes">- <source>Call<br/>Count<</source>+ <source>Call Count<</source></trans-unit><trans-unit id="a2a91c8b" xml:space="preserve" approved="no" translate="yes">- <source>Recording<</source>+ <source>Recording&nbsp;Date</source></trans-unit><trans-unit id="9c5940cb" xml:space="preserve" approved="no" translate="yes">- <source>Last&nbsp;Exec</source>+ <source>Last&nbsp;Exec&nbsp;Date</source></trans-unit><trans-unit id="409928e8" xml:space="preserve" approved="no" translate="yes">- <source>Next&nbsp;Exec</source>+ <source>Next&nbsp;Exec&nbsp;Date</source></trans-unit><trans-unit id="2ef20848" xml:space="preserve" approved="no" translate="yes"><source>>Event Trigger<</source>diff --git a/locales/ru.lng b/locales/ru.lngindex 32d670cbb..cbf42041f 100644--- a/locales/ru.lng+++ b/locales/ru.lng@@ -3444,13 +3444,12 @@ to a scheduler for a periodic execution.==в планировщик для пе"next page"=="следующая страница""previous page"=="предыдущая страница"of #[of]#== по #[of]#->Date==>Дата>Type==>Тип>Comment==>Комментарий-Call<br/>Count<==Количество<br/>вызовов<-Recording<==Запись<-Last Exec==Дата последнего запуска-Next Exec==Дата следующего запуска+Call Count<==Количество вызовов<+Recording Date==Запись Дата+Last Exec Date==Дата последнего запуска Дата+Next Exec Date==Дата следующего запуска Дата#>URL<==>URL-адрес<>Event Trigger<==>Триггер событий<"clone"=="клонировать"diff --git a/locales/uk.lng b/locales/uk.lngindex 2691b3c69..53f9f3bae 100644--- a/locales/uk.lng+++ b/locales/uk.lng@@ -2993,10 +2993,10 @@ to a scheduler for a periodic execution.==для періодичного самof #[of]#== з #[of]#>Type==>Тип>Comment==>Примітка-Call<br/>Count<==Виклики<->Recording<br/>Date<==>Дата<br/>запису<->Last Exec<br/>Date<==>Останній<br/>запуск<->Next Exec<br/>Date<==>Наступний<br/>запуск<+Call Count<==Виклики<+>Recording Date<==>Дата запису<+>Last Exec Date<==>Останній запуск<+>Next Exec Date<==>Наступний запуск<>Scheduler<==>Планувальник<>no repetition<==>без повторення<>activate scheduler<==>з плануванням<diff --git a/locales/zh.lng b/locales/zh.lngindex d3863a48c..8ea342a7a 100644--- a/locales/zh.lng+++ b/locales/zh.lng@@ -3307,13 +3307,12 @@ to a scheduler for a periodic execution.==或者用于周期执行一系列动"next page"=="下一页""previous page"=="上一页"of #[of]#== 共 #[of]#->Date==>日期>Type==>类型>Comment==>注释-Call<br/>Count<==调用<br/>次数<-Recording<==正在记录<-Last Exec==上次 执行-Next Exec==下次 执行+Call Count<==调用 次数<+Recording Date==正在记录 日期+Last Exec Date==上次 执行 日期+Next Exec Date==下次 执行 日期>Scheduler<==>定时器<#>URL<==>URL>no repetition<==>无安排<diff --git a/source/net/yacy/kelondro/blob/Tables.java b/source/net/yacy/kelondro/blob/Tables.javaindex af3519a2e..dc807fb13 100644--- a/source/net/yacy/kelondro/blob/Tables.java+++ b/source/net/yacy/kelondro/blob/Tables.java@@ -33,6 +33,7 @@ import java.text.ParseException;import java.util.ArrayList;import java.util.Arrays;import java.util.Collection;+import java.util.Comparator;import java.util.Date;import java.util.HashMap;import java.util.HashSet;@@ -40,7 +41,6 @@ import java.util.Iterator;import java.util.LinkedHashMap;import java.util.Map;import java.util.Set;-import java.util.TreeMap;import java.util.TreeSet;import java.util.concurrent.ConcurrentHashMap;import java.util.regex.Pattern;@@ -481,26 +481,152 @@ public class Tables implements Iterable<String> {return new OrderedRowIterator(table, wherePattern, up);}- public static Collection<Row> orderBy(final Iterator<Row> rowIterator, int maxcount, final String sortColumn) {- final TreeMap<String, Row> sortTree = new TreeMap<String, Row>();- Row row;- byte[] r;- while ((maxcount < 0 || maxcount-- > 0) && rowIterator.hasNext()) {- row = rowIterator.next();- r = row.get(sortColumn);- if (r == null) {- sortTree.put("0000" + UTF8.String(row.pk), row);- } else {- sortTree.put(UTF8.String(r) + UTF8.String(row.pk), row);- }- }- return sortTree.values();- }+ /**+ * @param rowIterator+ * an open iterator on a table. Must not be null.+ * @param sortColumn+ * the name of the column to use for sorting.+ * @return all the rows of the table sorted in ascending order on the given+ * column name+ */+ public static Collection<Row> orderBy(final Iterator<Row> rowIterator, final String sortColumn) {+ return orderByString(rowIterator, sortColumn, "", SortDirection.ASC);+ }++ /**+ * @param rowIterator+ * an open iterator on a table. Must not be null.+ * @param sortColumn+ * the name of the column to use for sorting.+ * @param defaultValue+ * the default value to use when the column value is null.+ * @param sortDir+ * the sorting direction. When null, {@link SortDirection#ASC} is applied.+ * @return all the rows of the table sorted on the given column name+ */+ public static Collection<Row> orderByInt(final Iterator<Row> rowIterator, final String sortColumn,+ final int defaultValue, final SortDirection sortDir) {+ /* Compare first on the given column */+ Comparator<Row> comparator = Comparator.<Row>comparingInt(row -> row.get(sortColumn, defaultValue));+ /*+ * Then in case of equality, compare on the primary key. Ensure also that+ * eventual null rows do not make the process fail.+ */+ comparator = Comparator.nullsFirst(comparator.thenComparing(row -> UTF8.String(row.pk)));+ if (sortDir == SortDirection.DESC) {+ comparator = comparator.reversed();+ }+ return orderBy(rowIterator, comparator);+ }++ /**+ * @param rowIterator+ * an open iterator on a table. Must not be null.+ * @param sortColumn+ * the name of the column to use for sorting.+ * @param defaultValue+ * the default value to use when the column value is null.+ * @param sortDir+ * the sorting direction. When null, {@link SortDirection#ASC} is applied.+ * @return all the rows of the table sorted on the given column name+ */+ public static Collection<Row> orderByLong(final Iterator<Row> rowIterator, final String sortColumn,+ final long defaultValue, final SortDirection sortDir) {+ /* Compare first on the given column */+ Comparator<Row> comparator = Comparator.<Row>comparingLong(row -> row.get(sortColumn, defaultValue));+ /*+ * Then in case of equality, compare on the primary key. Ensure also that+ * eventual null rows do not make the process fail.+ */+ comparator = Comparator.nullsFirst(comparator.thenComparing(row -> UTF8.String(row.pk)));+ if (sortDir == SortDirection.DESC) {+ comparator = comparator.reversed();+ }+ return orderBy(rowIterator, comparator);+ }++ /**+ * @param rowIterator+ * an open iterator on a table. Must not be null.+ * @param sortColumn+ * the name of the column to use for sorting.+ * @param defaultValue+ * the default value to use when the column value is null.+ * @param sortDir+ * the sorting direction. When null, {@link SortDirection#ASC} is applied.+ * @return all the rows of the table sorted on the given column name+ */+ public static Collection<Row> orderByString(final Iterator<Row> rowIterator, final String sortColumn,+ final String defaultValue, final SortDirection sortDir) {+ /* Compare first on the given column */+ Comparator<Row> comparator = Comparator+ .nullsFirst(Comparator.<Row, String>comparing(row -> row.get(sortColumn, defaultValue)));+ /*+ * Then in case of equality, compare on the primary key. Ensure also that+ * eventual null rows do not make the process fail.+ */+ comparator = Comparator.nullsFirst(comparator.thenComparing(row -> UTF8.String(row.pk)));+ if (sortDir == SortDirection.DESC) {+ comparator = comparator.reversed();+ }+ return orderBy(rowIterator, comparator);+ }++ /**+ * @param rowIterator+ * an open iterator on a table. Must not be null.+ * @param sortColumn+ * the name of the column to use for sorting.+ * @param defaultValue+ * the default value to use when the column value is null.+ * @param sortDir+ * the sorting direction. When null, {@link SortDirection#ASC} is applied.+ * @return all the rows of the table sorted on the given column name+ */+ public static Collection<Row> orderByDate(final Iterator<Row> rowIterator, final String sortColumn,+ final Date defaultValue, final SortDirection sortDir) {+ /* Compare first on the given column */+ Comparator<Row> comparator = Comparator+ .nullsFirst(Comparator.<Row, Date>comparing(row -> row.get(sortColumn, defaultValue)));+ /*+ * Then in case of equality, compare on the primary key. Ensure also that+ * eventual null rows do not make the process fail.+ */+ comparator = Comparator.nullsFirst(comparator.thenComparing(row -> UTF8.String(row.pk)));+ if (sortDir == SortDirection.DESC) {+ comparator = comparator.reversed();+ }+ return orderBy(rowIterator, comparator);+ }++ /**+ * @param rowIterator+ * an open iterator on a table. Must not be null.+ * @param comparator+ * the eventual comparator to use.+ * @return all the rows of the table sorted using the given comparator, or+ * sorted on rows natural order when comparator is null.+ */+ public static Collection<Row> orderBy(final Iterator<Row> rowIterator, final Comparator<Row> comparator) {+ final TreeSet<Row> sortTree = new TreeSet<Row>(comparator);+ while (rowIterator.hasNext()) {+ sortTree.add(rowIterator.next());+ }+ return sortTree;+ }public ArrayList<String> columns(final String table) throws IOException {final BEncodedHeap heap = getHeap(table);return heap.columns();}++ /** Sort direction for ordering rows */+ public enum SortDirection {+ /** Ascending order */+ ASC,+ /** Descending order */+ DESC+ }public class HeapRowIterator extends LookAheadIterator<Row> implements Iterator<Row> {diff --git a/source/net/yacy/search/Switchboard.java b/source/net/yacy/search/Switchboard.javaindex 8af9024f5..957289dee 100644--- a/source/net/yacy/search/Switchboard.java+++ b/source/net/yacy/search/Switchboard.java@@ -188,6 +188,7 @@ import net.yacy.http.YaCyHttpServer;import net.yacy.kelondro.blob.ArrayStack;import net.yacy.kelondro.blob.BEncodedHeap;import net.yacy.kelondro.blob.Tables;+import net.yacy.kelondro.blob.Tables.SortDirection;import net.yacy.kelondro.data.meta.URIMetadataNode;import net.yacy.kelondro.data.word.Word;import net.yacy.kelondro.logging.GuiHandler;@@ -2495,7 +2496,7 @@ public final class Switchboard extends serverSwitch {final Date now = new Date();try {final Iterator<Tables.Row> plainIterator = this.tables.iterator(WorkTables.TABLE_API_NAME);- final Iterator<Tables.Row> mapIterator = Tables.orderBy(plainIterator, -1, WorkTables.TABLE_API_COL_DATE_LAST_EXEC).iterator();+ final Iterator<Tables.Row> mapIterator = Tables.orderByDate(plainIterator, WorkTables.TABLE_API_COL_DATE_LAST_EXEC, null, SortDirection.ASC).iterator();while (mapIterator.hasNext()) {row = mapIterator.next();if (row == null) continue;