| 4638 |
amar.kumar |
1 |
<%@page import="java.util.Arrays"%>
|
|
|
2 |
<%@page import="java.util.Set"%>
|
|
|
3 |
<%@page import="java.util.Hashtable"%>
|
|
|
4 |
<%@ page import="java.util.Calendar"%>
|
|
|
5 |
<%@ page import="java.util.Map.Entry"%>
|
|
|
6 |
<%@ page import="java.util.Map"%>
|
|
|
7 |
<%@ page import="java.text.ParseException"%>
|
|
|
8 |
<%@ page import="java.util.TimeZone"%>
|
|
|
9 |
<%@ page import="java.text.SimpleDateFormat"%>
|
|
|
10 |
<%@ page import="java.util.Date"%>
|
|
|
11 |
<%@ page import="java.util.List" %>
|
|
|
12 |
<%@ page import="com.google.appengine.api.datastore.Query.SortDirection"%>
|
|
|
13 |
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
|
|
14 |
<%@ page import="com.google.appengine.api.datastore.DatastoreServiceFactory" %>
|
|
|
15 |
<%@ page import="com.google.appengine.api.datastore.DatastoreService" %>
|
|
|
16 |
<%@ page import="com.google.appengine.api.datastore.Query" %>
|
|
|
17 |
<%@ page import="com.google.appengine.api.datastore.Entity" %>
|
|
|
18 |
<%@ page import="com.google.appengine.api.datastore.PreparedQuery" %>
|
|
|
19 |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
|
20 |
<html>
|
|
|
21 |
<head>
|
|
|
22 |
<link rel="stylesheet" href="/DataTables/media/css/demo_table.css" type="text/css" />
|
|
|
23 |
<link rel="stylesheet" href="/DataTables/extras/TableTools/media/css/TableTools.css" type="text/css" />
|
|
|
24 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
|
|
25 |
<title>Product Search</title>
|
|
|
26 |
</head>
|
|
|
27 |
|
|
|
28 |
<%
|
|
|
29 |
Date toDate = new Date();
|
|
|
30 |
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("IST"));
|
|
|
31 |
cal.add(Calendar.DAY_OF_MONTH, -2);
|
|
|
32 |
Date fromDate = cal.getTime();
|
|
|
33 |
SimpleDateFormat iSdf = new SimpleDateFormat("yyyyMMdd");
|
|
|
34 |
String toDateStr = request.getParameter("toDate");
|
|
|
35 |
String fromDateStr = request.getParameter("fromDate");
|
|
|
36 |
if (fromDateStr == null || fromDateStr.isEmpty()) {
|
|
|
37 |
fromDateStr = iSdf.format(fromDate);
|
|
|
38 |
}
|
|
|
39 |
if (toDateStr == null || toDateStr.isEmpty()) {
|
|
|
40 |
toDateStr = iSdf.format(toDate);
|
|
|
41 |
}
|
|
|
42 |
%>
|
|
|
43 |
<body>
|
|
|
44 |
<form id="searchfilter" name="searchfilter" method="post" action="/jsp/productSearchFrequency.jsp">
|
|
|
45 |
<label>From Date(YYYYMMDD) : </label> <input type="text" name="fromDate" id="fromDate" value="<%= fromDateStr %>"/>
|
|
|
46 |
<label>To Date(YYYYMMDD) : </label> <input type="text" name="toDate" id="toDate" value="<%= toDateStr %>"/>
|
|
|
47 |
<input type="Submit" id="Submit" name="Submit" value="Submit" />
|
|
|
48 |
</form>
|
|
|
49 |
|
|
|
50 |
<%
|
|
|
51 |
try {
|
|
|
52 |
if (fromDateStr != null) {
|
|
|
53 |
fromDate = iSdf.parse(fromDateStr);
|
|
|
54 |
}
|
|
|
55 |
if (toDateStr != null) {
|
|
|
56 |
toDate = iSdf.parse(toDateStr);
|
|
|
57 |
}
|
|
|
58 |
}
|
|
|
59 |
catch (ParseException pe) {
|
|
|
60 |
%>
|
|
|
61 |
<span>Invalid Date Format</span>
|
|
|
62 |
<%
|
|
|
63 |
}
|
|
|
64 |
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
65 |
sdf.setTimeZone(TimeZone.getTimeZone("IST"));
|
|
|
66 |
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
|
|
|
67 |
Query query = new Query("DataLog");
|
|
|
68 |
query.addFilter("eventType", Query.FilterOperator.IN,Arrays.asList("PRODUCT_SEARCH","PRODUCT_VIEW"));
|
|
|
69 |
query.addFilter("date", Query.FilterOperator.GREATER_THAN_OR_EQUAL, fromDate);
|
|
|
70 |
query.addFilter("date", Query.FilterOperator.LESS_THAN_OR_EQUAL, toDate);
|
|
|
71 |
PreparedQuery pq = datastore.prepare(query);
|
|
|
72 |
Map<String,Double> productSearchFreq = new Hashtable<String,Double>();
|
|
|
73 |
Map<String,Double> searchClickMap = new Hashtable<String,Double>();
|
|
|
74 |
|
|
|
75 |
for (Entity result : pq.asIterable()) {
|
|
|
76 |
if(result.getProperty("eventType").equals("PRODUCT_SEARCH")){
|
|
|
77 |
String searchString = (String)result.getProperty("query");
|
|
|
78 |
|
|
|
79 |
if(productSearchFreq.containsKey(searchString)){
|
|
|
80 |
productSearchFreq.put(searchString, productSearchFreq.get(searchString)+1);
|
|
|
81 |
}else{
|
|
|
82 |
productSearchFreq.put(searchString,Double.parseDouble("1"));
|
|
|
83 |
}
|
|
|
84 |
}else{
|
|
|
85 |
String refererUrl = (String)result.getProperty("refererUrl");
|
|
|
86 |
if(refererUrl!=null){
|
|
|
87 |
if(refererUrl.contains("search?")){
|
|
|
88 |
String clickQuery = refererUrl.split("q=")[1].split("&")[0];
|
|
|
89 |
if(searchClickMap.containsKey(clickQuery)){
|
|
|
90 |
searchClickMap.put(clickQuery, searchClickMap.get(clickQuery)+1);
|
|
|
91 |
}else{
|
|
|
92 |
searchClickMap.put(clickQuery, Double.parseDouble("1"));
|
|
|
93 |
}
|
|
|
94 |
}
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
}
|
|
|
98 |
}
|
|
|
99 |
%>
|
|
|
100 |
|
|
|
101 |
<table cellpadding="0" cellspacing="0" border="0" class="display" id="productSearch">
|
|
|
102 |
<thead>
|
|
|
103 |
<tr>
|
|
|
104 |
<th>Query String</th>
|
|
|
105 |
<th>Frequency</th>
|
|
|
106 |
<th>Search Result Clicked</th>
|
|
|
107 |
<th>Search Conversion </th>
|
|
|
108 |
</tr>
|
|
|
109 |
</thead>
|
|
|
110 |
<tbody>
|
|
|
111 |
<% Set<String> querySet= productSearchFreq.keySet();
|
|
|
112 |
for (String productQuery:querySet){
|
|
|
113 |
%>
|
|
|
114 |
<tr>
|
|
|
115 |
<td><a href="/jsp/productSearch.jsp?productQuery=<%=productQuery.toString()%>&toDate=<%=toDateStr%>&fromDate=<%=fromDateStr%>"><%=productQuery%></a></td>
|
|
|
116 |
<td><%=productSearchFreq.get(productQuery).intValue()%></td>
|
|
|
117 |
<td><%=(searchClickMap.get(productQuery))==null ? 0 : searchClickMap.get(productQuery).intValue() %></td>
|
|
|
118 |
<td><%=(((searchClickMap.get(productQuery))==null ? 0 : searchClickMap.get(productQuery))*100/productSearchFreq.get(productQuery)) +"%"%></td>
|
|
|
119 |
</tr>
|
|
|
120 |
<%}%>
|
|
|
121 |
</tbody>
|
|
|
122 |
</table>
|
|
|
123 |
<script type="text/javascript" language="javascript" src="/DataTables/media/js/jquery.js"></script>
|
|
|
124 |
<script type="text/javascript" language="javascript" src="/DataTables/media/js/jquery.dataTables.min.js"></script>
|
|
|
125 |
<script type="text/javascript" charset="utf-8" src="/DataTables/extras/TableTools/media/js/ZeroClipboard.js"></script>
|
|
|
126 |
<script type="text/javascript" charset="utf-8" src="/DataTables/extras/TableTools/media/js/TableTools.js"></script>
|
|
|
127 |
<script type="text/javascript" charset="utf-8">
|
|
|
128 |
$(document).ready(function() {
|
|
|
129 |
$('#productSearch').dataTable({
|
|
|
130 |
"sPaginationType": "full_numbers",
|
|
|
131 |
"aaSorting" : [ [ 1, 'desc' ] ],
|
|
|
132 |
"bProcessing": true,
|
|
|
133 |
"bStateSave": true,
|
|
|
134 |
"sDom": 'T<"clear">lfrtip',
|
|
|
135 |
"oTableTools": {
|
|
|
136 |
"sSwfPath": "/DataTables/extras/TableTools/media/swf/copy_cvs_xls_pdf.swf"
|
|
|
137 |
},
|
|
|
138 |
"aoColumns": [
|
|
|
139 |
{ "bSearchable": true },
|
|
|
140 |
null,
|
|
|
141 |
null,
|
|
|
142 |
null
|
|
|
143 |
]
|
|
|
144 |
});
|
|
|
145 |
} );
|
|
|
146 |
</script>
|
|
|
147 |
</body>
|
|
|
148 |
</html>
|