| Line -... |
Line 1... |
| - |
|
1 |
<%@ page import="java.util.ArrayList"%>
|
| - |
|
2 |
<%@ page import="in.shop2020.server.SearchMetadata"%>
|
| 1 |
<%@page import="java.util.Arrays"%>
|
3 |
<%@ page import="java.util.Arrays"%>
|
| 2 |
<%@page import="java.util.Set"%>
|
4 |
<%@ page import="java.util.Set"%>
|
| 3 |
<%@page import="java.util.Hashtable"%>
|
5 |
<%@ page import="java.util.Hashtable"%>
|
| 4 |
<%@ page import="java.util.Calendar"%>
|
6 |
<%@ page import="java.util.Calendar"%>
|
| 5 |
<%@ page import="java.util.Map.Entry"%>
|
7 |
<%@ page import="java.util.Map.Entry"%>
|
| 6 |
<%@ page import="java.util.Map"%>
|
8 |
<%@ page import="java.util.Map"%>
|
| 7 |
<%@ page import="java.text.ParseException"%>
|
9 |
<%@ page import="java.text.ParseException"%>
|
| 8 |
<%@ page import="java.util.TimeZone"%>
|
10 |
<%@ page import="java.util.TimeZone"%>
|
| 9 |
<%@ page import="java.text.SimpleDateFormat"%>
|
11 |
<%@ page import="java.text.SimpleDateFormat"%>
|
| 10 |
<%@ page import="java.util.Date"%>
|
12 |
<%@ page import="java.util.Date"%>
|
| 11 |
<%@ page import="java.util.List" %>
|
13 |
<%@ page import="java.util.List" %>
|
| - |
|
14 |
<%@ page import="java.net.URLDecoder" %>
|
| 12 |
<%@ page import="com.google.appengine.api.datastore.Query.SortDirection"%>
|
15 |
<%@ page import="com.google.appengine.api.datastore.Query.SortDirection"%>
|
| 13 |
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
16 |
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
| 14 |
<%@ page import="com.google.appengine.api.datastore.DatastoreServiceFactory" %>
|
17 |
<%@ page import="com.google.appengine.api.datastore.DatastoreServiceFactory" %>
|
| 15 |
<%@ page import="com.google.appengine.api.datastore.DatastoreService" %>
|
18 |
<%@ page import="com.google.appengine.api.datastore.DatastoreService" %>
|
| 16 |
<%@ page import="com.google.appengine.api.datastore.Query" %>
|
19 |
<%@ page import="com.google.appengine.api.datastore.Query" %>
|
| 17 |
<%@ page import="com.google.appengine.api.datastore.Entity" %>
|
20 |
<%@ page import="com.google.appengine.api.datastore.Entity" %>
|
| 18 |
<%@ page import="com.google.appengine.api.datastore.PreparedQuery" %>
|
21 |
<%@ page import="com.google.appengine.api.datastore.PreparedQuery" %>
|
| - |
|
22 |
<%@ page import="in.shop2020.model.Category"%>
|
| - |
|
23 |
|
| 19 |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
24 |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
| 20 |
<html>
|
25 |
<html>
|
| 21 |
<head>
|
26 |
<head>
|
| 22 |
<link rel="stylesheet" href="/DataTables/media/css/demo_table.css" type="text/css" />
|
27 |
<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" />
|
28 |
<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">
|
29 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
| 25 |
<title>Product Search</title>
|
30 |
<title>Product Search</title>
|
| 26 |
</head>
|
31 |
</head>
|
| 27 |
|
32 |
|
| - |
|
33 |
|
| - |
|
34 |
|
| 28 |
<%
|
35 |
<%!
|
| - |
|
36 |
public Map<String,SearchMetadata> populateSearchDataMap(Map<String,SearchMetadata> productSearchFreq, Entity result){
|
| - |
|
37 |
String searchString = (String)result.getProperty("query");
|
| - |
|
38 |
|
| - |
|
39 |
if(productSearchFreq.containsKey(searchString)){
|
| - |
|
40 |
SearchMetadata searchObject = productSearchFreq.get(searchString);
|
| - |
|
41 |
|
| - |
|
42 |
//Setting number of searches
|
| - |
|
43 |
searchObject.setTotalSearches(searchObject.getTotalSearches()+1);
|
| - |
|
44 |
|
| - |
|
45 |
//setting number of search results
|
| - |
|
46 |
List<Long> numSearchResults =searchObject.getSearchResults();
|
| - |
|
47 |
numSearchResults.add((Long)result.getProperty("totalResults"));
|
| - |
|
48 |
searchObject.setSearchResults(numSearchResults);
|
| - |
|
49 |
|
| - |
|
50 |
//Setting frequency by category
|
| - |
|
51 |
String categoryId = Category.findByValue(Integer.parseInt(result.getProperty("categoryId").toString())).toString();
|
| - |
|
52 |
if(searchObject.getcategoryFrequency().containsKey(categoryId)) {
|
| - |
|
53 |
searchObject.getcategoryFrequency().put(categoryId, (searchObject.getcategoryFrequency().get(categoryId))+1);
|
| - |
|
54 |
}else {
|
| - |
|
55 |
searchObject.getcategoryFrequency().put(categoryId,Long.parseLong("1"));
|
| - |
|
56 |
}
|
| - |
|
57 |
|
| - |
|
58 |
//Storing session Id of query
|
| - |
|
59 |
if(!searchObject.getSessionIds().contains(result.getProperty("sessionId"))){
|
| - |
|
60 |
searchObject.getSessionIds().add(result.getProperty("sessionId"));
|
| - |
|
61 |
}
|
| - |
|
62 |
|
| - |
|
63 |
productSearchFreq.put(searchString, searchObject);
|
| - |
|
64 |
}else{
|
| - |
|
65 |
SearchMetadata searchObject = new SearchMetadata();
|
| - |
|
66 |
|
| - |
|
67 |
//Setting frequency by category
|
| - |
|
68 |
String categoryId = Category.findByValue(Integer.parseInt(result.getProperty("categoryId").toString())).toString();
|
| - |
|
69 |
Map<String, Long> categoryFrequency = new Hashtable<String, Long>();
|
| - |
|
70 |
categoryFrequency.put(categoryId,Long.parseLong("1"));
|
| - |
|
71 |
searchObject.setcategoryFrequency(categoryFrequency);
|
| - |
|
72 |
|
| - |
|
73 |
//Setting number of searches
|
| - |
|
74 |
searchObject.setTotalSearches(Long.parseLong("1"));
|
| - |
|
75 |
|
| - |
|
76 |
//setting number of search results
|
| - |
|
77 |
List<Long> numSearchResults = new ArrayList<Long>();
|
| - |
|
78 |
numSearchResults.add((Long)result.getProperty("totalResults"));
|
| - |
|
79 |
searchObject.setSearchResults(numSearchResults);
|
| - |
|
80 |
|
| - |
|
81 |
//Storing session Id of query
|
| - |
|
82 |
List<Object> sessionList = new ArrayList<Object>();
|
| - |
|
83 |
sessionList.add(result.getProperty("sessionId"));
|
| - |
|
84 |
searchObject.setSessionIds(sessionList);
|
| - |
|
85 |
|
| - |
|
86 |
productSearchFreq.put(searchString,searchObject);
|
| - |
|
87 |
}
|
| - |
|
88 |
return productSearchFreq;
|
| - |
|
89 |
}
|
| - |
|
90 |
|
| - |
|
91 |
public Map<String,Double> populateSearchClickMap(Map<String,Double> searchClickMap, Entity result){
|
| - |
|
92 |
String refererUrl = (String)result.getProperty("refererUrl");
|
| - |
|
93 |
if(refererUrl!=null){
|
| - |
|
94 |
if(refererUrl.contains("search?")){
|
| - |
|
95 |
String clickQuery = "";
|
| - |
|
96 |
refererUrl = URLDecoder.decode(refererUrl);
|
| - |
|
97 |
clickQuery = refererUrl.split("q=")[1].split("&")[0];
|
| - |
|
98 |
if(searchClickMap.containsKey(clickQuery)){
|
| - |
|
99 |
searchClickMap.put(clickQuery, searchClickMap.get(clickQuery)+1);
|
| - |
|
100 |
}else{
|
| - |
|
101 |
searchClickMap.put(clickQuery, Double.parseDouble("1"));
|
| - |
|
102 |
}
|
| - |
|
103 |
}
|
| - |
|
104 |
}
|
| - |
|
105 |
return searchClickMap;
|
| - |
|
106 |
}
|
| - |
|
107 |
|
| - |
|
108 |
%>
|
| - |
|
109 |
|
| 29 |
Date toDate = new Date();
|
110 |
<% Date toDate = new Date();
|
| 30 |
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("IST"));
|
111 |
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("IST"));
|
| 31 |
cal.add(Calendar.DAY_OF_MONTH, -2);
|
112 |
cal.add(Calendar.DAY_OF_MONTH, -2);
|
| 32 |
Date fromDate = cal.getTime();
|
113 |
Date fromDate = cal.getTime();
|
| 33 |
SimpleDateFormat iSdf = new SimpleDateFormat("yyyyMMdd");
|
114 |
SimpleDateFormat iSdf = new SimpleDateFormat("yyyyMMdd");
|
| 34 |
String toDateStr = request.getParameter("toDate");
|
115 |
String toDateStr = request.getParameter("toDate");
|
| Line 61... |
Line 142... |
| 61 |
<span>Invalid Date Format</span>
|
142 |
<span>Invalid Date Format</span>
|
| 62 |
<%
|
143 |
<%
|
| 63 |
}
|
144 |
}
|
| 64 |
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
145 |
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
| 65 |
sdf.setTimeZone(TimeZone.getTimeZone("IST"));
|
146 |
sdf.setTimeZone(TimeZone.getTimeZone("IST"));
|
| - |
|
147 |
|
| 66 |
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
|
148 |
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
|
| 67 |
Query query = new Query("DataLog");
|
149 |
Query query = new Query("DataLog");
|
| 68 |
query.addFilter("eventType", Query.FilterOperator.IN,Arrays.asList("PRODUCT_SEARCH","PRODUCT_VIEW"));
|
150 |
query.addFilter("eventType", Query.FilterOperator.IN,Arrays.asList("PRODUCT_SEARCH","PRODUCT_VIEW"));
|
| 69 |
query.addFilter("date", Query.FilterOperator.GREATER_THAN_OR_EQUAL, fromDate);
|
151 |
query.addFilter("date", Query.FilterOperator.GREATER_THAN_OR_EQUAL, fromDate);
|
| 70 |
query.addFilter("date", Query.FilterOperator.LESS_THAN_OR_EQUAL, toDate);
|
152 |
query.addFilter("date", Query.FilterOperator.LESS_THAN_OR_EQUAL, toDate);
|
| 71 |
PreparedQuery pq = datastore.prepare(query);
|
153 |
PreparedQuery pq = datastore.prepare(query);
|
| - |
|
154 |
|
| - |
|
155 |
|
| 72 |
Map<String,Double> productSearchFreq = new Hashtable<String,Double>();
|
156 |
Map<String,SearchMetadata> productSearchFreq = new Hashtable<String,SearchMetadata>();
|
| 73 |
Map<String,Double> searchClickMap = new Hashtable<String,Double>();
|
157 |
Map<String,Double> searchClickMap = new Hashtable<String,Double>();
|
| 74 |
|
158 |
|
| 75 |
for (Entity result : pq.asIterable()) {
|
159 |
for (Entity result : pq.asIterable()) {
|
| 76 |
if(result.getProperty("eventType").equals("PRODUCT_SEARCH")){
|
160 |
if(result.getProperty("eventType").equals("PRODUCT_SEARCH")){
|
| 77 |
String searchString = (String)result.getProperty("query");
|
161 |
productSearchFreq = populateSearchDataMap(productSearchFreq, result);
|
| 78 |
|
162 |
|
| 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{
|
163 |
}else{
|
| 85 |
String refererUrl = (String)result.getProperty("refererUrl");
|
164 |
//Calculating the frequency of ProductViews originating from ProductSearch
|
| 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);
|
165 |
searchClickMap = populateSearchClickMap(searchClickMap,result);
|
| 91 |
}else{
|
- |
|
| 92 |
searchClickMap.put(clickQuery, Double.parseDouble("1"));
|
- |
|
| 93 |
}
|
- |
|
| 94 |
}
|
- |
|
| 95 |
}
|
- |
|
| 96 |
|
- |
|
| 97 |
}
|
166 |
}
|
| 98 |
}
|
167 |
}
|
| - |
|
168 |
|
| 99 |
%>
|
169 |
%>
|
| 100 |
|
170 |
|
| 101 |
<table cellpadding="0" cellspacing="0" border="0" class="display" id="productSearch">
|
171 |
<table cellpadding="0" cellspacing="0" border="0" class="display" id="productSearch">
|
| 102 |
<thead>
|
172 |
<thead>
|
| 103 |
<tr>
|
173 |
<tr>
|
| 104 |
<th>Query String</th>
|
174 |
<th>Query String</th>
|
| - |
|
175 |
<th>Total Search Count</th>
|
| - |
|
176 |
<th>No Category</th>
|
| - |
|
177 |
<th>Mobile Phones</th>
|
| 105 |
<th>Frequency</th>
|
178 |
<th>Tablets</th>
|
| - |
|
179 |
<th>Laptops</th>
|
| - |
|
180 |
<th>Accessories</th>
|
| - |
|
181 |
<th>Session Count</th>
|
| - |
|
182 |
<th>Average No. of Results</th>
|
| 106 |
<th>Search Result Clicked</th>
|
183 |
<th>Search Result Clicked</th>
|
| 107 |
<th>Search Conversion </th>
|
184 |
<th>Search Conversion (%) </th>
|
| 108 |
</tr>
|
185 |
</tr>
|
| 109 |
</thead>
|
186 |
</thead>
|
| 110 |
<tbody>
|
187 |
<tbody>
|
| 111 |
<% Set<String> querySet= productSearchFreq.keySet();
|
188 |
<% Set<String> querySet= productSearchFreq.keySet();
|
| 112 |
for (String productQuery:querySet){
|
189 |
for (String productQuery:querySet){
|
| - |
|
190 |
Double searchConversionRate = (((searchClickMap.get(productQuery))==null ? 0 : searchClickMap.get(productQuery))*100/(productSearchFreq.get(productQuery).getTotalSearches()));
|
| - |
|
191 |
searchConversionRate = ((double)((long)(searchConversionRate*100)))/100; //Truncating to 2 decimal places
|
| 113 |
%>
|
192 |
%>
|
| 114 |
<tr>
|
193 |
<tr>
|
| 115 |
<td><a href="/jsp/productSearch.jsp?productQuery=<%=productQuery.toString()%>&toDate=<%=toDateStr%>&fromDate=<%=fromDateStr%>"><%=productQuery%></a></td>
|
194 |
<td><a href="/jsp/productSearch.jsp?productQuery=<%=productQuery.toString()%>&toDate=<%=toDateStr%>&fromDate=<%=fromDateStr%>"><%=productQuery%></a></td>
|
| 116 |
<td><%=productSearchFreq.get(productQuery).intValue()%></td>
|
195 |
<td><%=productSearchFreq.get(productQuery).getTotalSearches()%></td>
|
| - |
|
196 |
|
| - |
|
197 |
<%
|
| - |
|
198 |
Set<String> searchCategories = productSearchFreq.get(productQuery).getcategoryFrequency().keySet();
|
| - |
|
199 |
List<String> categories = new ArrayList<String>();
|
| - |
|
200 |
categories.add("NA");
|
| - |
|
201 |
categories.add("Mobile_Phones");
|
| - |
|
202 |
categories.add("Tablets");
|
| - |
|
203 |
categories.add("Laptops");
|
| - |
|
204 |
categories.add("Mobile_Accessories");
|
| - |
|
205 |
for(String category : categories){
|
| - |
|
206 |
Long searchinCategory = productSearchFreq.get(productQuery).getcategoryFrequency().get(category);
|
| - |
|
207 |
%>
|
| - |
|
208 |
<td>
|
| - |
|
209 |
<%=searchinCategory==null ? 0 : searchinCategory %>
|
| - |
|
210 |
</td>
|
| - |
|
211 |
<% }%>
|
| - |
|
212 |
<%
|
| - |
|
213 |
long tempSum = 0;
|
| - |
|
214 |
for(Long numOfSearchResults : productSearchFreq.get(productQuery).getSearchResults()){
|
| - |
|
215 |
tempSum+=numOfSearchResults;
|
| - |
|
216 |
}%>
|
| - |
|
217 |
<td><%=(productSearchFreq.get(productQuery).getSessionIds()==null ? 0 : productSearchFreq.get(productQuery).getSessionIds().size()) %></td>
|
| - |
|
218 |
<td><%=tempSum/productSearchFreq.get(productQuery).getTotalSearches() %></td>
|
| 117 |
<td><%=(searchClickMap.get(productQuery))==null ? 0 : searchClickMap.get(productQuery).intValue() %></td>
|
219 |
<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>
|
220 |
<td><%=searchConversionRate%></td>
|
| 119 |
</tr>
|
221 |
</tr>
|
| 120 |
<%}%>
|
222 |
<%}%>
|
| 121 |
</tbody>
|
223 |
</tbody>
|
| 122 |
</table>
|
224 |
</table>
|
| 123 |
<script type="text/javascript" language="javascript" src="/DataTables/media/js/jquery.js"></script>
|
225 |
<script type="text/javascript" language="javascript" src="/DataTables/media/js/jquery.js"></script>
|
| Line 126... |
Line 228... |
| 126 |
<script type="text/javascript" charset="utf-8" src="/DataTables/extras/TableTools/media/js/TableTools.js"></script>
|
228 |
<script type="text/javascript" charset="utf-8" src="/DataTables/extras/TableTools/media/js/TableTools.js"></script>
|
| 127 |
<script type="text/javascript" charset="utf-8">
|
229 |
<script type="text/javascript" charset="utf-8">
|
| 128 |
$(document).ready(function() {
|
230 |
$(document).ready(function() {
|
| 129 |
$('#productSearch').dataTable({
|
231 |
$('#productSearch').dataTable({
|
| 130 |
"sPaginationType": "full_numbers",
|
232 |
"sPaginationType": "full_numbers",
|
| 131 |
"aaSorting" : [ [ 1, 'desc' ] ],
|
233 |
"aaSorting" : [ [ 2, 'desc' ] ],
|
| 132 |
"bProcessing": true,
|
234 |
"bProcessing": true,
|
| 133 |
"bStateSave": true,
|
235 |
"bStateSave": true,
|
| 134 |
"sDom": 'T<"clear">lfrtip',
|
236 |
"sDom": 'T<"clear">lfrtip',
|
| 135 |
"oTableTools": {
|
237 |
"oTableTools": {
|
| 136 |
"sSwfPath": "/DataTables/extras/TableTools/media/swf/copy_cvs_xls_pdf.swf"
|
238 |
"sSwfPath": "/DataTables/extras/TableTools/media/swf/copy_cvs_xls_pdf.swf"
|
| 137 |
},
|
239 |
},
|
| 138 |
"aoColumns": [
|
240 |
"aoColumns": [
|
| 139 |
{ "bSearchable": true },
|
241 |
{ "bSearchable": true },
|
| 140 |
null,
|
242 |
{ "sSortDataType": "dom-text", "sType": "numeric" },
|
| 141 |
null,
|
243 |
{ "sSortDataType": "dom-text", "sType": "numeric" },
|
| 142 |
null
|
- |
|
| - |
|
244 |
{ "sSortDataType": "dom-text", "sType": "numeric" },
|
| - |
|
245 |
{ "sSortDataType": "dom-text", "sType": "numeric" },
|
| - |
|
246 |
{ "sSortDataType": "dom-text", "sType": "numeric" },
|
| - |
|
247 |
{ "sSortDataType": "dom-text", "sType": "numeric" },
|
| - |
|
248 |
{ "sSortDataType": "dom-text", "sType": "numeric" },
|
| - |
|
249 |
{ "sSortDataType": "dom-text", "sType": "numeric" },
|
| - |
|
250 |
{ "sSortDataType": "dom-text", "sType": "numeric" },
|
| - |
|
251 |
{ "sSortDataType": "dom-text", "sType": "numeric" }
|
| 143 |
]
|
252 |
]
|
| 144 |
});
|
253 |
});
|
| 145 |
} );
|
254 |
} );
|
| 146 |
</script>
|
255 |
</script>
|
| 147 |
</body>
|
256 |
</body>
|