You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
3.4 KiB
68 lines
3.4 KiB
2 years ago
|
package net.yacy.htroot;
|
||
|
|
||
14 years ago
|
import net.yacy.cora.protocol.RequestHeader;
|
||
7 years ago
|
import net.yacy.data.UserDB;
|
||
|
import net.yacy.http.servlets.TemplateMissingParameterException;
|
||
14 years ago
|
import net.yacy.kelondro.util.Formatter;
|
||
7 years ago
|
import net.yacy.search.Switchboard;
|
||
13 years ago
|
import net.yacy.search.query.QueryParams;
|
||
|
import net.yacy.search.query.SearchEvent;
|
||
|
import net.yacy.search.query.SearchEventCache;
|
||
12 years ago
|
import net.yacy.server.serverObjects;
|
||
|
import net.yacy.server.serverSwitch;
|
||
14 years ago
|
|
||
|
|
||
|
public class yacysearchlatestinfo {
|
||
14 years ago
|
|
||
4 years ago
|
public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
|
||
7 years ago
|
if (post == null) {
|
||
|
throw new TemplateMissingParameterException("The eventID parameter is required");
|
||
|
}
|
||
2 years ago
|
|
||
14 years ago
|
final serverObjects prop = new serverObjects();
|
||
2 years ago
|
final Switchboard sb = (Switchboard) env;
|
||
|
|
||
7 years ago
|
final boolean adminAuthenticated = sb.verifyAuthentication(header);
|
||
|
final UserDB.Entry user = sb.userDB != null ? sb.userDB.getUser(header) : null;
|
||
|
final boolean userAuthenticated = (user != null && user.hasRight(UserDB.AccessRight.EXTENDED_SEARCH_RIGHT));
|
||
|
final boolean authenticated = adminAuthenticated || userAuthenticated;
|
||
14 years ago
|
|
||
14 years ago
|
// find search event
|
||
|
final String eventID = post.get("eventID", "");
|
||
|
final SearchEvent theSearch = SearchEventCache.getEvent(eventID);
|
||
|
if (theSearch == null) {
|
||
13 years ago
|
// the event does not exist.
|
||
|
// to avoid missing patterns, we return dummy values
|
||
|
prop.put("offset", 0);
|
||
13 years ago
|
prop.put("itemscount", 0);
|
||
13 years ago
|
prop.put("itemsperpage", 10);
|
||
|
prop.put("totalcount", 0);
|
||
|
prop.put("localResourceSize", 0);
|
||
7 years ago
|
prop.put("localIndexCount", 0);
|
||
13 years ago
|
prop.put("remoteResourceSize", 0);
|
||
|
prop.put("remoteIndexCount", 0);
|
||
|
prop.put("remotePeerCount", 0);
|
||
8 years ago
|
prop.putJSON("navurlBase", "#");
|
||
8 years ago
|
prop.put("feedRunning", Boolean.FALSE.toString());
|
||
14 years ago
|
return prop;
|
||
|
}
|
||
14 years ago
|
|
||
14 years ago
|
// dynamically update count values
|
||
12 years ago
|
final int offset = theSearch.query.neededResults() - theSearch.query.itemsPerPage() + 1;
|
||
14 years ago
|
prop.put("offset", offset);
|
||
12 years ago
|
prop.put("itemscount",Formatter.number(offset + theSearch.query.itemsPerPage >= theSearch.getResultCount() ? offset + theSearch.getResultCount() % theSearch.query.itemsPerPage - 1 : offset + theSearch.query.itemsPerPage - 1));
|
||
12 years ago
|
prop.put("itemsperpage", theSearch.query.itemsPerPage);
|
||
12 years ago
|
prop.put("totalcount", Formatter.number(theSearch.getResultCount(), true));
|
||
12 years ago
|
prop.put("localResourceSize", Formatter.number(theSearch.local_rwi_stored.get() + theSearch.local_solr_stored.get(), true));
|
||
7 years ago
|
prop.put("localIndexCount", Formatter.number(theSearch.local_rwi_available.get() + theSearch.local_solr_stored.get() - theSearch.local_solr_evicted.get(), true));
|
||
12 years ago
|
prop.put("remoteResourceSize", Formatter.number(theSearch.remote_rwi_stored.get() + theSearch.remote_solr_stored.get(), true));
|
||
|
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));
|
||
7 years ago
|
prop.putJSON("navurlBase", QueryParams.navurlBase(RequestHeader.FileType.HTML, theSearch.query, null, false, authenticated).toString());
|
||
8 years ago
|
prop.put("feedRunning", Boolean.toString(!theSearch.isFeedingFinished()));
|
||
14 years ago
|
|
||
14 years ago
|
return prop;
|
||
|
}
|
||
14 years ago
|
|
||
14 years ago
|
}
|