Rev 4744 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<%@page import="java.util.Arrays"%><%@page import="java.util.Set"%><%@page import="java.util.Hashtable"%><%@ page import="java.util.Calendar"%><%@ page import="java.util.Map.Entry"%><%@ page import="java.util.Map"%><%@ page import="java.text.ParseException"%><%@ page import="java.util.TimeZone"%><%@ page import="java.text.SimpleDateFormat"%><%@ page import="java.util.Date"%><%@ page import="java.util.List" %><%@ page import="com.google.appengine.api.datastore.Query.SortDirection"%><%@ page contentType="text/html;charset=UTF-8" language="java" %><%@ page import="com.google.appengine.api.datastore.DatastoreServiceFactory" %><%@ page import="com.google.appengine.api.datastore.DatastoreService" %><%@ page import="com.google.appengine.api.datastore.Query" %><%@ page import="com.google.appengine.api.datastore.Entity" %><%@ page import="com.google.appengine.api.datastore.PreparedQuery" %><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><link rel="stylesheet" href="/DataTables/media/css/demo_table.css" type="text/css" /><link rel="stylesheet" href="/DataTables/extras/TableTools/media/css/TableTools.css" type="text/css" /><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Product Search</title></head><%Date toDate = new Date();Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("IST"));cal.add(Calendar.DAY_OF_MONTH, -2);Date fromDate = cal.getTime();SimpleDateFormat iSdf = new SimpleDateFormat("yyyyMMdd");String toDateStr = request.getParameter("toDate");String fromDateStr = request.getParameter("fromDate");if (fromDateStr == null || fromDateStr.isEmpty()) {fromDateStr = iSdf.format(fromDate);}if (toDateStr == null || toDateStr.isEmpty()) {toDateStr = iSdf.format(toDate);}%><body><form id="searchfilter" name="searchfilter" method="post" action="/jsp/productSearchFrequency.jsp"><label>From Date(YYYYMMDD) : </label> <input type="text" name="fromDate" id="fromDate" value="<%= fromDateStr %>"/><label>To Date(YYYYMMDD) : </label> <input type="text" name="toDate" id="toDate" value="<%= toDateStr %>"/><input type="Submit" id="Submit" name="Submit" value="Submit" /></form><%try {if (fromDateStr != null) {fromDate = iSdf.parse(fromDateStr);}if (toDateStr != null) {toDate = iSdf.parse(toDateStr);}}catch (ParseException pe) {%><span>Invalid Date Format</span><%}SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");sdf.setTimeZone(TimeZone.getTimeZone("IST"));DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();Query query = new Query("DataLog");query.addFilter("eventType", Query.FilterOperator.IN,Arrays.asList("PRODUCT_SEARCH","PRODUCT_VIEW"));query.addFilter("date", Query.FilterOperator.GREATER_THAN_OR_EQUAL, fromDate);query.addFilter("date", Query.FilterOperator.LESS_THAN_OR_EQUAL, toDate);PreparedQuery pq = datastore.prepare(query);Map<String,Double> productSearchFreq = new Hashtable<String,Double>();Map<String,Double> searchClickMap = new Hashtable<String,Double>();for (Entity result : pq.asIterable()) {if(result.getProperty("eventType").equals("PRODUCT_SEARCH")){String searchString = (String)result.getProperty("query");if(productSearchFreq.containsKey(searchString)){productSearchFreq.put(searchString, productSearchFreq.get(searchString)+1);}else{productSearchFreq.put(searchString,Double.parseDouble("1"));}}else{String refererUrl = (String)result.getProperty("refererUrl");if(refererUrl!=null){if(refererUrl.contains("search?")){String clickQuery = refererUrl.split("q=")[1].split("&")[0];if(searchClickMap.containsKey(clickQuery)){searchClickMap.put(clickQuery, searchClickMap.get(clickQuery)+1);}else{searchClickMap.put(clickQuery, Double.parseDouble("1"));}}}}}%><table cellpadding="0" cellspacing="0" border="0" class="display" id="productSearch"><thead><tr><th>Query String</th><th>Frequency</th><th>Search Result Clicked</th><th>Search Conversion </th></tr></thead><tbody><% Set<String> querySet= productSearchFreq.keySet();for (String productQuery:querySet){%><tr><td><a href="/jsp/productSearch.jsp?productQuery=<%=productQuery.toString()%>&toDate=<%=toDateStr%>&fromDate=<%=fromDateStr%>"><%=productQuery%></a></td><td><%=productSearchFreq.get(productQuery).intValue()%></td><td><%=(searchClickMap.get(productQuery))==null ? 0 : searchClickMap.get(productQuery).intValue() %></td><td><%=(((searchClickMap.get(productQuery))==null ? 0 : searchClickMap.get(productQuery))*100/productSearchFreq.get(productQuery)) +"%"%></td></tr><%}%></tbody></table><script type="text/javascript" language="javascript" src="/DataTables/media/js/jquery.js"></script><script type="text/javascript" language="javascript" src="/DataTables/media/js/jquery.dataTables.min.js"></script><script type="text/javascript" charset="utf-8" src="/DataTables/extras/TableTools/media/js/ZeroClipboard.js"></script><script type="text/javascript" charset="utf-8" src="/DataTables/extras/TableTools/media/js/TableTools.js"></script><script type="text/javascript" charset="utf-8">$(document).ready(function() {$('#productSearch').dataTable({"sPaginationType": "full_numbers","aaSorting" : [ [ 1, 'desc' ] ],"bProcessing": true,"bStateSave": true,"sDom": 'T<"clear">lfrtip',"oTableTools": {"sSwfPath": "/DataTables/extras/TableTools/media/swf/copy_cvs_xls_pdf.swf"},"aoColumns": [{ "bSearchable": true },null,null,null]});} );</script></body></html>