Permalink
Browse files

Added user interface feedback on results feeding termination status.

Added as an additional icon with title in the search progress bar, to
inform about background search feeder threads terminated or still
running. While giving a bit more information to users about the p2p
search process, this can help choosing whether or not wait a little bit
more time before going to the next page, in order to get results from
various sources sorted as best as possible (see #91 for a discussion
about sorting accuracy and network latency).

Other related modifications included :
 - regular updates to statistics in the progress bar until the
background feeders are completely terminated.
 - removed some uses of unsecure and discouraged JavaScript elements
  • Loading branch information...
luccioman committed May 15, 2017
1 parent ff63922 commit 31ad043bb92e3bdf8e2ca5cfed1424b39c59c631
@@ -93,12 +93,21 @@ function parseFormattedInt(strIntValue) {
return intValue;
}
function statistics(offset, itemscount, itemsperpage, totalcount, localResourceSize, remoteResourceSize, remoteIndexCount, remotePeerCount, navurlbase, localQuery) {
function statistics(offset, itemscount, itemsperpage, totalcount, localResourceSize, remoteResourceSize, remoteIndexCount, remotePeerCount, navurlbase, localQuery, feedRunning) {
var totalcountIntValue = parseFormattedInt(totalcount);
var offsetIntValue = parseFormattedInt(offset);
var itemscountIntValue = parseFormattedInt(itemscount);
var itemsperpageIntValue = parseFormattedInt(itemsperpage);
var feedingStatusElement = document.getElementById("feedingStatus");
if(feedingStatusElement != null) {
if(feedRunning) {
feedingStatusElement.style.visibility = "visible";
} else {
feedingStatusElement.style.visibility = "hidden";
}
}
if (totalcountIntValue == 0) {
return;
}
@@ -125,7 +125,7 @@
<div id="results"></div>
<div class="progress">
<div class="progress-bar progress-bar-info" id="progressbar" role="progressbar" style="width:0%;">
<span style="position:absolute;display:block;text-align:left;width:100%;color:black;">&nbsp;&nbsp;&nbsp;<strong id="offset">#[offset]#</strong>-<strong id="itemscount">#[itemscount]#</strong> of <strong id="totalcount">#[totalcount]#</strong> #(globalresults)#::; (<strong id="localResourceSize">#[localResourceSize]#</strong> local, <strong id="remoteResourceSize">#[remoteResourceSize]#</strong> remote), <strong id="remoteIndexCount">#[remoteIndexCount]#</strong> from <strong id="remotePeerCount">#[remotePeerCount]#</strong> remote YaCy peers.#(/globalresults)#</span>
<span style="position:absolute;display:block;text-align:left;width:100%;color:black;">&nbsp;&nbsp;&nbsp;<strong id="offset">#[offset]#</strong>-<strong id="itemscount">#[itemscount]#</strong> of <strong id="totalcount">#[totalcount]#</strong> #(globalresults)#::; (<strong id="localResourceSize">#[localResourceSize]#</strong> local, <strong id="remoteResourceSize">#[remoteResourceSize]#</strong> remote), <strong id="remoteIndexCount">#[remoteIndexCount]#</strong> from <strong id="remotePeerCount">#[remotePeerCount]#</strong> remote YaCy peers.#(/globalresults)# <span id="feedingStatus" style="visibility: hidden;" class="glyphicon glyphicon-transfer" title="YaCy server is fetching results from available data sources."></span></span>
</div>
</div>
::
@@ -221,28 +221,28 @@ <h4 class="linktitle">
self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
self.xmlHttpReq.onreadystatechange = function() {
if (self.xmlHttpReq.readyState == 4) {
var rsp = eval("(" + self.xmlHttpReq.responseText + ")");
var rsp = null;
if(self.xmlHttpReq.responseText) {
if(window.JSON && window.JSON.parse) {
/* Prefer use of JSON parser when available instead of discouraged eval() function */
rsp = window.JSON.parse(self.xmlHttpReq.responseText);
} else {
rsp = eval("(" + self.xmlHttpReq.responseText + ")");
}
}
statistics(rsp.offset, rsp.itemscount, rsp.itemsperpage, rsp.totalcount, rsp.localResourceSize, rsp.remoteResourceSize, rsp.remoteIndexCount, rsp.remotePeerCount, rsp.navurlBase, #[localQuery]#);
if(rsp && rsp.offset != null) {
statistics(rsp.offset, rsp.itemscount, rsp.itemsperpage, rsp.totalcount, rsp.localResourceSize, rsp.remoteResourceSize, rsp.remoteIndexCount, rsp.remotePeerCount, rsp.navurlBase, #[localQuery]#, rsp.feedRunning);
if(rsp.feedRunning) {
/* Refresh statistics while server feeders are still running */
window.setTimeout(latestinfo, 1000);
}
}
}
};
self.xmlHttpReq.send(null);
}
window.setTimeout('latestinfo();',500); // we need that to get a correct pagination bar at the end of the page
window.setTimeout('latestinfo();',1000);
// TODO: resets statistic on navigating to next page in Jetty implementation
/*
window.setTimeout('latestinfo();',500);
window.setTimeout('latestinfo();',1000);
window.setTimeout('latestinfo();',1500);
window.setTimeout('latestinfo();',2000);
window.setTimeout('latestinfo();',3000);
window.setTimeout('latestinfo();',4000);
window.setTimeout('latestinfo();',5000);
window.setTimeout('latestinfo();',6000);
window.setTimeout('latestinfo();',8000);
window.setTimeout('latestinfo();',10000);
*/
window.setTimeout(latestinfo, 500); // we need that to get a correct pagination bar at the end of the page
</script>
#%env/templates/footer.template%#
@@ -58,6 +58,6 @@ <h4 class="linktitle">
#(statistics)#::
<script type="text/javascript">
statistics("#[offset]#", "#[itemscount]#", "#[itemsperpage]#", "#[totalcount]#", "#[localResourceSize]#", "#[remoteResourceSize]#", "#[remoteIndexCount]#", "#[remotePeerCount]#", "#[navurlBase]#", #[localQuery]#);
statistics("#[offset]#", "#[itemscount]#", "#[itemsperpage]#", "#[totalcount]#", "#[localResourceSize]#", "#[remoteResourceSize]#", "#[remoteIndexCount]#", "#[remotePeerCount]#", "#[navurlBase]#", #[localQuery]#, #[feedRunning]#);
</script>
#(/statistics)#
@@ -123,6 +123,7 @@ public static serverObjects respond(final RequestHeader header, final serverObje
prop.put("statistics_remotePeerCount", Formatter.number(theSearch.remote_rwi_peerCount.get() + theSearch.remote_solr_peerCount.get(), true));
prop.put("statistics_navurlBase", QueryParams.navurlBase(RequestHeader.FileType.HTML, theSearch.query, null, false).toString());
prop.put("statistics_localQuery", theSearch.query.isLocal() ? "1" : "0");
prop.put("statistics_feedRunning", Boolean.toString(!theSearch.isFeedingFinished()));
final String target_special_pattern = sb.getConfig(SwitchboardConstants.SEARCH_TARGET_SPECIAL_PATTERN, "");
final boolean noreferrer = sb.getConfigBool(SwitchboardConstants.SEARCH_RESULT_NOREFERRER, SwitchboardConstants.SEARCH_RESULT_NOREFERRER_DEFAULT);
@@ -28,6 +28,7 @@ public static serverObjects respond(@SuppressWarnings("unused") final RequestHea
prop.put("remoteIndexCount", 0);
prop.put("remotePeerCount", 0);
prop.putJSON("navurlBase", "#");
prop.put("feedRunning", Boolean.FALSE.toString());
return prop;
}
@@ -42,6 +43,7 @@ public static serverObjects respond(@SuppressWarnings("unused") final RequestHea
prop.put("remoteIndexCount", Formatter.number(theSearch.remote_rwi_available.get() + theSearch.remote_solr_available.get(), true));
prop.put("remotePeerCount", Formatter.number(theSearch.remote_rwi_peerCount.get() + theSearch.remote_solr_peerCount.get(), true));
prop.putJSON("navurlBase", QueryParams.navurlBase(RequestHeader.FileType.HTML, theSearch.query, null, false).toString());
prop.put("feedRunning", Boolean.toString(!theSearch.isFeedingFinished()));
return prop;
}
@@ -7,5 +7,6 @@
"remoteResourceSize": "#[remoteResourceSize]#",
"remoteIndexCount": "#[remoteIndexCount]#",
"remotePeerCount": "#[remotePeerCount]#",
"navurlBase": "#[navurlBase]#"
"navurlBase": "#[navurlBase]#",
"feedRunning": #[feedRunning]#
}
@@ -1605,7 +1605,7 @@ public URIMetadataNode oneResult(final int item, final long timeout) {
}
while ( this.resultList.sizeAvailable() <= resultListIndex &&
(this.rwiQueueSize() > 0 || this.nodeStack.sizeQueue() > 0 ||
(!this.feedingIsFinished() && System.currentTimeMillis() < finishTime))) {
(!this.isFeedingFinished() && System.currentTimeMillis() < finishTime))) {
if (!drainStacksToResult()) {
try {
Thread.sleep(10);
@@ -1797,7 +1797,13 @@ public ReferenceOrder getOrder() {
return this.order;
}
protected boolean feedingIsFinished() {
/**
* Check whether feeding from all available data sources is finished (remote
* RWI and Solr requests, local RWI and Solr requests, Heuristics
* requests...)
* @return true when all available feeders on this search event are terminated
*/
public boolean isFeedingFinished() {
return
this.feedersTerminated.intValue() > (this.remote ? 1 : 0) &&
this.feedersAlive.get() == 0;

0 comments on commit 31ad043

Please sign in to comment.