From 61be709a976f7b2989e26984c2005a233c12b31a Mon Sep 17 00:00:00 2001 From: JeremyRand Date: Mon, 28 Aug 2017 14:33:53 +0000 Subject: [PATCH 01/10] Add data-ranking attribute to each HTML search item. --- htroot/yacysearchitem.html | 2 +- htroot/yacysearchitem.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/htroot/yacysearchitem.html b/htroot/yacysearchitem.html index aa12fd51a..668e23c18 100644 --- a/htroot/yacysearchitem.html +++ b/htroot/yacysearchitem.html @@ -1,5 +1,5 @@ #(content)#:: -
+

#(favicon)#:: diff --git a/htroot/yacysearchitem.java b/htroot/yacysearchitem.java index 9d145bbfe..bdbd9fc51 100644 --- a/htroot/yacysearchitem.java +++ b/htroot/yacysearchitem.java @@ -279,6 +279,7 @@ public class yacysearchitem { prop.put("content_showSnapshots_link", snapshotPaths.iterator().next().getAbsolutePath()); } prop.put("content_showRanking_ranking", Float.toString(result.score())); + prop.put("content_ranking", Float.toString(result.score())); } prop.put("content_urlhexhash", Seed.b64Hash2hexHash(urlhash)); prop.putHTML("content_urlname", nxTools.shortenURLString(result.urlname(), MAX_URL_LENGTH)); From d37df75afaba7bcc18efa0a83f6e581b000db14d Mon Sep 17 00:00:00 2001 From: JeremyRand Date: Sun, 3 Sep 2017 17:50:08 +0000 Subject: [PATCH 02/10] (WIP) Optionally sort HTML search items via Javascript. TODO: Expose a GUI setting for this. --- defaults/yacy.init | 5 ++ htroot/js/yacysort.js | 139 +++++++++++++++++++++++++++++++++++++++++ htroot/yacysearch.html | 42 +++++++++++-- htroot/yacysearch.java | 9 +++ 4 files changed, 190 insertions(+), 5 deletions(-) create mode 100644 htroot/js/yacysort.js diff --git a/defaults/yacy.init b/defaults/yacy.init index a9dc0abfc..a6365f18f 100644 --- a/defaults/yacy.init +++ b/defaults/yacy.init @@ -907,6 +907,11 @@ search.excludehosth= # the cases of nocache, iffresh and ifexist causes an index deletion search.verify.delete = true +# If enabled, the results are sorted in the browser using Javascript. +# This usually improves ranking accuracy, but doesn't work well for users +# who have Javascript disabled, are using screen readers, or are on slow computers. +search.jsresort = false + # remote search details remotesearch.maxcount = 10 remotesearch.maxtime = 3000 diff --git a/htroot/js/yacysort.js b/htroot/js/yacysort.js new file mode 100644 index 000000000..4ed983506 --- /dev/null +++ b/htroot/js/yacysort.js @@ -0,0 +1,139 @@ +var itemCount = 0; +var highestRanking = Infinity; + +var displayPage = function() { + // For every search item that has already been displayed... + $("#resultscontainer .searchresults").each( function(i) { + // Apply the "earlierpage" class IFF the item is from an earlier page. + $(this).toggleClass("earlierpage", parseFloat($(this).data("ranking")) > highestRanking); + }); + + // For every search item from an earlier page... + $("#resultscontainer .searchresults.earlierpage").each( function(i) { + // Hide the item + $(this).removeClass("currentpage"); + $(this).hide(1000); + }); + + // For every search item from a current or later page... + $("#resultscontainer .searchresults:not(.earlierpage)").each( function(i) { + // If we now have too many results, hide the lowest-ranking ones. + if (i >= requestedResults) { + $(this).removeClass("currentpage"); + $(this).hide(1000); + } + else { + $(this).addClass("currentpage"); + $(this).show(1000); + } + }); + + $("#offset").html($("#resultscontainer .searchresults.earlierpage").length + 1); + $("#itemscount").html($("#resultscontainer .searchresults.earlierpage").length + $("#resultscontainer .searchresults.currentpage").length); + + console.log("Showing results " + ($("#resultscontainer .searchresults.earlierpage").length + 1) + " - " + ($("#resultscontainer .searchresults.earlierpage").length + requestedResults) + " out of " + $("#resultscontainer .searchresults").length + "; notEarlierPage = " + $("#resultscontainer .searchresults:not(.earlierpage)").length); +}; + +var earlierPage = function() { + // Find all items that are on an earlier page. + var allEarlierItems = $("#resultscontainer .searchresults.earlierpage"); + + // If going back one page would put us at the beginning... + if (allEarlierItems.length <= requestedResults) { + highestRanking = Infinity; + } + // If going back one page would still be in the middle of the results... + else { + var earlierItem = allEarlierItems.get().reverse()[ requestedResults - 1 ]; + highestRanking = parseFloat($(earlierItem).data("ranking")); + console.log("highestRanking is now " + highestRanking); + } + + // Update the display to show the new page. + displayPage(); +}; + +var laterPage = function() { + // Find all items that are on a later page. + var allCurrentAndLaterItems = $("#resultscontainer .searchresults:not(.earlierpage)"); + + // If going forward one page would put us past the end... + if (allCurrentAndLaterItems.length <= requestedResults) { + return; + } + // If going forward one page would still be in the middle of the results... + else { + var laterItem = allCurrentAndLaterItems.get(requestedResults); + highestRanking = parseFloat($(laterItem).data("ranking")); + console.log("highestRanking is now " + highestRanking); + } + + // Update the display to show the new page. + displayPage(); +}; + +var processItem = function(data) { + var newItem = $(data).hide(); + + // If we didn't get a valid response from YaCy, wait 1 second and try again. + if( ! newItem.data("ranking") ) { + //console.log("Got undefined item, waiting 1 second..."); + setTimeout(function() { + $.get( + "yacysearchitem.html", + { + eventID: theEventID, + item: itemCount + }, + processItem + ); + }, 1000); + return; + } + + // For every search item that has already been displayed... + $("#resultscontainer .searchresults").each( function(i) { + // If the existing search item is lower-ranked than the new item... + if (parseFloat($(this).data("ranking")) <= parseFloat(newItem.data("ranking")) ) { + // Insert new item before the existing item + newItem.insertBefore(this); + + return false; + } + // If the new item is lower-ranked than all existing items... + else if (i == $("#resultscontainer .searchresults").length - 1) { + // And if the new item (position i + 1) would be ranked 0 to requestedResults - 1... + if (i + 1 < requestedResults) { + // Insert new item at the end + newItem.appendTo("#resultscontainer"); + return false; + } + // If the new item is too irrelevant to be displayed... + else { + // Insert new item at the end + newItem.appendTo("#resultscontainer"); + console.log("Hiding search result because ranking " + newItem.data("ranking") + " too low."); + return false; + } + } + }); + + // Special case if this is the first search item... + if ($("#resultscontainer .searchresults").length === 0) { + // Display the new item + newItem.appendTo("#resultscontainer"); + } + + displayPage(); + + // Increment itemCount and get another item. + itemCount++; + $.get( + "yacysearchitem.html", + { + eventID: theEventID, + item: itemCount + }, + processItem + ); +}; diff --git a/htroot/yacysearch.html b/htroot/yacysearch.html index 8a46a2041..437bfccb5 100644 --- a/htroot/yacysearch.html +++ b/htroot/yacysearch.html @@ -12,6 +12,13 @@ + #(jsResort)#:: + + + #(/jsResort)# #(/jsResort)# @@ -209,11 +210,7 @@ document.getElementById("Enter").innerHTML = "search again"; :: :: :: - #(jsResort)# - - :: -



Prev Page    Next Page

- #(/jsResort)# + :: #(/num-results)# @@ -254,9 +251,9 @@ function latestinfo() { if(rsp && rsp.offset != null) { #(jsResort)# - statistics(rsp.offset, rsp.itemscount, rsp.itemsperpage, rsp.totalcount, rsp.localIndexCount, rsp.remoteIndexCount, rsp.remotePeerCount, rsp.navurlBase, #[localQuery]#, rsp.feedRunning); + statistics(rsp.offset, rsp.itemscount, rsp.itemsperpage, rsp.totalcount, rsp.localIndexCount, rsp.remoteIndexCount, rsp.remotePeerCount, rsp.navurlBase, #[localQuery]#, rsp.feedRunning, false); :: - statistics($("#resultscontainer .searchresults.earlierpage").length + 1, $("#resultscontainer .searchresults.earlierpage").length + $("#resultscontainer .searchresults.currentpage").length, rsp.itemsperpage, rsp.totalcount, rsp.localIndexCount, rsp.remoteIndexCount, rsp.remotePeerCount, rsp.navurlBase, #[localQuery]#, rsp.feedRunning); + statistics($("#resultscontainer .searchresults.earlierpage").length + 1, $("#resultscontainer .searchresults.earlierpage").length + $("#resultscontainer .searchresults.currentpage").length, rsp.itemsperpage, rsp.totalcount, rsp.localIndexCount, rsp.remoteIndexCount, rsp.remotePeerCount, rsp.navurlBase, #[localQuery]#, rsp.feedRunning, true); #(/jsResort)# if(rsp.feedRunning) { /* Refresh statistics while server feeders are still running */ From 86b50949704843ab978f0880ee6d41c6b946a13e Mon Sep 17 00:00:00 2001 From: JeremyRand Date: Sun, 3 Sep 2017 18:03:48 +0000 Subject: [PATCH 07/10] Fix numbered page navigation from getting corrupted when statistics() runs. --- htroot/js/yacysearch.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htroot/js/yacysearch.js b/htroot/js/yacysearch.js index 3bb9001cc..0b397b121 100644 --- a/htroot/js/yacysearch.js +++ b/htroot/js/yacysearch.js @@ -188,7 +188,7 @@ function statistics(offset, itemscount, itemsperpage, totalcount, localIndexCoun progresseBarElement.setAttribute('style',"width:" + percent + "%"); } var resnavElement = document.getElementById("resNav"); - if (resnavElement != null) { + if (resnavElement != null && !jsResort) { resnavElement.innerHTML = renderPaginationButtons(offsetIntValue, itemsperpageIntValue, totalcountIntValue, navurlbase, localQuery, jsResort); } } From ab0e50b94178e6ff59af2829b0dbf80abd363276 Mon Sep 17 00:00:00 2001 From: JeremyRand Date: Sun, 3 Sep 2017 17:34:48 +0000 Subject: [PATCH 08/10] Javascript re-sorting: optimize the jQuery selectors a little bit. --- htroot/js/yacysort.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/htroot/js/yacysort.js b/htroot/js/yacysort.js index 048ee145d..6f2af70c4 100644 --- a/htroot/js/yacysort.js +++ b/htroot/js/yacysort.js @@ -3,20 +3,20 @@ var highestRanking = Infinity; var displayPage = function() { // For every search item that has already been displayed... - $("#resultscontainer .searchresults").each( function(i) { + $("#resultscontainer").find(".searchresults").each( function(i) { // Apply the "earlierpage" class IFF the item is from an earlier page. $(this).toggleClass("earlierpage", parseFloat($(this).data("ranking")) > highestRanking); }); // For every search item from an earlier page... - $("#resultscontainer .searchresults.earlierpage").each( function(i) { + $("#resultscontainer").find(".searchresults.earlierpage").each( function(i) { // Hide the item $(this).removeClass("currentpage"); $(this).hide(1000); }); // For every search item from a current or later page... - $("#resultscontainer .searchresults:not(.earlierpage)").each( function(i) { + $("#resultscontainer").find(".searchresults:not(.earlierpage)").each( function(i) { // If we now have too many results, hide the lowest-ranking ones. if (i >= requestedResults) { $(this).removeClass("currentpage"); @@ -30,11 +30,11 @@ var displayPage = function() { // TODO: The following statistical displays could maybe be moved to the latestinfo() call. - var offset = $("#resultscontainer .searchresults.earlierpage").length + 1; - var itemscount = $("#resultscontainer .searchresults.earlierpage").length + $("#resultscontainer .searchresults.currentpage").length; + var offset = $("#resultscontainer").find(".searchresults.earlierpage").length + 1; + var itemscount = $("#resultscontainer").find(".searchresults.earlierpage").length + $("#resultscontainer").find(".searchresults.currentpage").length; // TODO: This seems to often be smaller than the "totalcount" that statistics() ends up with. Why is that? - var totalcount = $("#resultscontainer .searchresults").length; + var totalcount = $("#resultscontainer").find(".searchresults").length; $("#offset").html(offset); $("#itemscount").html(itemscount); @@ -43,12 +43,12 @@ var displayPage = function() { //latestinfo(); - console.log("Showing results " + ($("#resultscontainer .searchresults.earlierpage").length + 1) + " - " + ($("#resultscontainer .searchresults.earlierpage").length + requestedResults) + " out of " + $("#resultscontainer .searchresults").length + "; notEarlierPage = " + $("#resultscontainer .searchresults:not(.earlierpage)").length); + console.log("Showing results " + ($("#resultscontainer").find(".searchresults.earlierpage").length + 1) + " - " + ($("#resultscontainer").find(".searchresults.earlierpage").length + requestedResults) + " out of " + $("#resultscontainer").find(".searchresults").length + "; notEarlierPage = " + $("#resultscontainer").find(".searchresults:not(.earlierpage)").length); }; var earlierPage = function() { // Find all items that are on an earlier page. - var allEarlierItems = $("#resultscontainer .searchresults.earlierpage"); + var allEarlierItems = $("#resultscontainer").find(".searchresults.earlierpage"); // If going back one page would put us at the beginning... if (allEarlierItems.length <= requestedResults) { @@ -67,7 +67,7 @@ var earlierPage = function() { var laterPage = function() { // Find all items that are on a later page. - var allCurrentAndLaterItems = $("#resultscontainer .searchresults:not(.earlierpage)"); + var allCurrentAndLaterItems = $("#resultscontainer").find(".searchresults:not(.earlierpage)"); // If going forward one page would put us past the end... if (allCurrentAndLaterItems.length <= requestedResults) { @@ -87,7 +87,7 @@ var laterPage = function() { // pageNumber starts at 0. var numberedPage = function(pageNumber) { // Find all items. - var allItems = $("#resultscontainer .searchresults"); + var allItems = $("#resultscontainer").find(".searchresults"); var itemNumber = pageNumber * requestedResults; @@ -290,7 +290,7 @@ var processItem = function(data) { } // For every search item that has already been displayed... - $("#resultscontainer .searchresults").each( function(i) { + $("#resultscontainer").find(".searchresults").each( function(i) { // If the existing search item is lower-ranked than the new item... if (parseFloat($(this).data("ranking")) <= parseFloat(newItem.data("ranking")) ) { // Insert new item before the existing item @@ -299,7 +299,7 @@ var processItem = function(data) { return false; } // If the new item is lower-ranked than all existing items... - else if (i == $("#resultscontainer .searchresults").length - 1) { + else if (i == $("#resultscontainer").find(".searchresults").length - 1) { // And if the new item (position i + 1) would be ranked 0 to requestedResults - 1... if (i + 1 < requestedResults) { // Insert new item at the end @@ -317,7 +317,7 @@ var processItem = function(data) { }); // Special case if this is the first search item... - if ($("#resultscontainer .searchresults").length === 0) { + if ($("#resultscontainer").find(".searchresults").length === 0) { // Display the new item newItem.appendTo("#resultscontainer"); } From 634f52fefcee0ceecff8cf09add6fe6cb80615b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ryszard=20Go=C5=84?= Date: Sun, 10 Sep 2017 17:09:35 +0200 Subject: [PATCH 09/10] Javascript re-sorting: replace jQuery show() with css animations --- htroot/js/yacysort.js | 7 ++++--- htroot/yacysearch.html | 1 + htroot/yacysort.css | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 htroot/yacysort.css diff --git a/htroot/js/yacysort.js b/htroot/js/yacysort.js index 6f2af70c4..3b18b4a03 100644 --- a/htroot/js/yacysort.js +++ b/htroot/js/yacysort.js @@ -12,7 +12,7 @@ var displayPage = function() { $("#resultscontainer").find(".searchresults.earlierpage").each( function(i) { // Hide the item $(this).removeClass("currentpage"); - $(this).hide(1000); + $(this).css('animation', '1s 1 forwards hide'); }); // For every search item from a current or later page... @@ -20,11 +20,12 @@ var displayPage = function() { // If we now have too many results, hide the lowest-ranking ones. if (i >= requestedResults) { $(this).removeClass("currentpage"); - $(this).hide(1000); + $(this).css('animation', '1s 1 forwards hide'); } else { $(this).addClass("currentpage"); - $(this).show(1000); + $(this).css('display', ''); + $(this).css('animation', '1s 1 forwards show'); } }); diff --git a/htroot/yacysearch.html b/htroot/yacysearch.html index 82aff1d50..1e2d1ffe6 100644 --- a/htroot/yacysearch.html +++ b/htroot/yacysearch.html @@ -19,6 +19,7 @@ var theLocalQuery = #[localQuery]#; + #(/jsResort)#