From 86c902b85336ec43fa4e67f69a8163d8bdb35d54 Mon Sep 17 00:00:00 2001 From: luccioman Date: Fri, 30 Mar 2018 10:21:42 +0200 Subject: [PATCH] Enable api table page navigation with search query Applied the same default results page size as when a type filter is defined for proper and consistend page navigation when combining type filter and search query. --- htroot/Table_API_p.html | 6 +++--- htroot/Table_API_p.java | 17 +++++++++++------ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/htroot/Table_API_p.html b/htroot/Table_API_p.html index 8ad8f4f94..e20dcc2ac 100644 --- a/htroot/Table_API_p.html +++ b/htroot/Table_API_p.html @@ -53,13 +53,13 @@ To see a list of all APIs, please visit the #(navigation)# :: - #(left)#no previous page::previous page#(/left)# + #(left)#no previous page::previous page#(/left)# #[startRecord]#-#[to]# of #[of]# - #(right)#no next page::next page#(/right)# + #(right)#no next page::next page#(/right)# #(/navigation)# - + diff --git a/htroot/Table_API_p.java b/htroot/Table_API_p.java index 07f6e3a88..52cade26c 100644 --- a/htroot/Table_API_p.java +++ b/htroot/Table_API_p.java @@ -47,6 +47,9 @@ import net.yacy.server.serverSwitch; public class Table_API_p { + /** Default results page size */ + private static final int DEFAULT_MAX_RECORDS = 25; + public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) { final Switchboard sb = (Switchboard) env; final serverObjects prop = new serverObjects(); @@ -55,7 +58,7 @@ public class Table_API_p { prop.put("showtable", 0); int startRecord = 0; - int maximumRecords = 25; + int maximumRecords = DEFAULT_MAX_RECORDS; Pattern query = QueryParams.catchall_pattern; if (post != null && post.containsKey("startRecord")) { startRecord = post.getInt("startRecord", 0); @@ -63,10 +66,10 @@ public class Table_API_p { if (post != null && post.containsKey("maximumRecords")) { maximumRecords = post.getInt("maximumRecords", 0); } + String queryParam = ""; if (post != null && post.containsKey("query") && !post.get("query", "").isEmpty()) { - query = Pattern.compile(".*" + post.get("query", "") + ".*"); - startRecord = 0; - maximumRecords = 1000; + queryParam = post.get("query", ""); + query = Pattern.compile(".*" + queryParam + ".*"); } final boolean inline = (post != null && post.getBoolean("inline")); @@ -445,8 +448,8 @@ public class Table_API_p { prop.put("showtable_maximumRecords", maximumRecords); prop.put("showtable_inline", (inline) ? 1 : 0); prop.put("showtable_filter", typefilter.pattern()); - prop.put("showtable_query", query.pattern().replaceAll("\\.\\*", "")); - if (tablesize >= maximumRecords) { + prop.put("showtable_query", queryParam); + if (filteredSize > maximumRecords) { prop.put("showtable_navigation", 1); prop.put("showtable_navigation_startRecord", startRecord); prop.put("showtable_navigation_to", Math.min(tablesize, startRecord + maximumRecords)); @@ -456,6 +459,7 @@ public class Table_API_p { prop.put("showtable_navigation_left_maximumRecords", maximumRecords); 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", startRecord == 0 ? 0 : 1); prop.put("showtable_navigation_filter", typefilter.pattern()); prop.put("showtable_navigation_right", startRecord + maximumRecords >= filteredSize ? 0 : 1); @@ -463,6 +467,7 @@ public class Table_API_p { prop.put("showtable_navigation_right_maximumRecords", maximumRecords); prop.put("showtable_navigation_right_inline", (inline) ? 1 : 0); prop.put("showtable_navigation_right_filter", typefilter.pattern()); + prop.put("showtable_navigation_right_query", queryParam); } else { prop.put("showtable_navigation", 0); }