--- android/MarketStats/src/dk/thoerup/marketstats/ShowStats.java 2010/05/03 21:15:52 704 +++ android/MarketStats/src/dk/thoerup/marketstats/ShowStats.java 2010/05/04 03:48:37 705 @@ -48,14 +48,14 @@ } } - protected String doLookup(String appId) throws IOException { + protected String doLookup(String query) throws IOException { - String key = "marketstats:" + appId; + String key = "marketstats:" + query; String response = (String) memcache.get(key); if (response == null) { - response = doLookupWorker(appId); + response = doLookupWorker(query); memcache.set(key, TIMEOUT, response); response += ""; } else { @@ -96,7 +96,7 @@ } - protected String doLookupWorker(String appId) { + protected String doLookupWorker(String query) { final StringBuilder sb = new StringBuilder(); @@ -105,7 +105,7 @@ AppsRequest appsRequest = AppsRequest.newBuilder() - .setAppId(appId) + .setQuery(query) .setStartIndex(0).setEntriesCount(10) .setWithExtendedInfo(true) .build(); @@ -120,34 +120,39 @@ session.append(appsRequest, appsCb); session.flush(); + + String appId = appsCb.getAppId(); + + if (appId != null) { - loadComments(appId, session, "da", commentBeans); - loadComments(appId, session, "en", commentBeans); - - Collections.sort(commentBeans); - - sb.append("-----------------------------------------------------------------\n"); - for (CommentBean c : commentBeans) { - sb.append("User: " + c.author + " (" + c.locale + ")\n"); - sb.append("Rating: " + c.rating + "\n"); - sb.append("Time: " + new Date(c.time).toString() + "\n"); - sb.append( c.text + "\n"); - sb.append("\n"); - + loadComments(appId, session, "da", commentBeans); + loadComments(appId, session, "en", commentBeans); + + Collections.sort(commentBeans); + + sb.append("-----------------------------------------------------------------\n"); + for (CommentBean c : commentBeans) { + sb.append("User: " + c.author + " (" + c.locale + ")\n"); + sb.append("Rating: " + c.rating + "\n"); + sb.append("Time: " + new Date(c.time).toString() + "\n"); + sb.append( c.text + "\n"); + sb.append("\n"); + + } + sb.append("Comments: " + commentBeans.size() + "\n"); } - sb.append("Comments: " + commentBeans.size() + "\n"); - sb.append("Cache.Timeout=" + TIMEOUT/60 + " minutes"); + sb.append("Cache.Timeout=" + TIMEOUT/60 + " minutes"); return sb.toString(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - String appId = request.getParameter("appId"); + String query = request.getParameter("query"); response.setContentType("text/html"); PrintWriter out = response.getWriter(); - out.print( "
" + doLookup(appId) + "
" ); + out.print( "
" + doLookup(query) + "
" ); } }