--- android/MarketStats/src/dk/thoerup/marketstats/ShowStats.java 2010/04/26 07:57:45 669 +++ android/MarketStats/src/dk/thoerup/marketstats/ShowStats.java 2010/05/27 09:45:44 760 @@ -4,7 +4,6 @@ import java.io.PrintWriter; import java.net.InetSocketAddress; import java.util.ArrayList; -import java.util.Collections; import java.util.Date; import java.util.Locale; import java.util.logging.Logger; @@ -48,14 +47,14 @@ } } - protected String doLookup(String appId) throws IOException { + protected String doLookup(String query) throws IOException { - String key = "marketstats:" + appId; + String key = "marketstats:" + query.replace(' ', '_'); String response = (String) memcache.get(key); if (response == null) { - response = doLookupWorker(appId); + response = doLookupWorker(query); memcache.set(key, TIMEOUT, response); response += ""; } else { @@ -64,12 +63,12 @@ return response; } - private void loadComments(String appId, MarketSession session, String locale, ArrayList commentBeans) { + private void loadComments(String appId, MarketSession session, ArrayList commentBeans) { CommentCallback commentsCb = new CommentCallback(); commentsCb.setList( commentBeans ); - commentsCb.setLocale( locale ); - session.setLocale( new Locale(locale) ); + session.setLocale( Locale.ROOT ); + int start = 0; @@ -78,7 +77,7 @@ if (start > 0) count = Math.min(10, commentsCb.getEntryCount() ); - //log.warning("count=" + count + " start=" + start + " " + locale); + //log.warning("count=" + count + " start=" + start + " entryCount=" + commentsCb.getEntryCount() ); CommentsRequest commentsRequest = CommentsRequest.newBuilder() .setAppId(appId) .setStartIndex(start) @@ -89,14 +88,14 @@ session.flush(); start +=10; - if (start >= 20) + if (start >= 200) break; //emergency brake } while ( start < commentsCb.getEntryCount() ); } - protected String doLookupWorker(String appId) { + protected String doLookupWorker(String query) { final StringBuilder sb = new StringBuilder(); @@ -105,7 +104,7 @@ AppsRequest appsRequest = AppsRequest.newBuilder() - .setAppId(appId) + .setQuery(query) .setStartIndex(0).setEntriesCount(10) .setWithExtendedInfo(true) .build(); @@ -120,34 +119,36 @@ 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, commentBeans); + + sb.append("-----------------------------------------------------------------\n"); + for (CommentBean c : commentBeans) { + sb.append("User: " + c.author + "\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) + "
" ); } }