| 2846 |
mandeep.dh |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
| 3561 |
rajveer |
3 |
import in.shop2020.serving.cache.SnippetCacheWrapper;
|
|
|
4 |
import in.shop2020.serving.cache.EhcacheWrapper.CacheKeys;
|
| 2846 |
mandeep.dh |
5 |
import in.shop2020.serving.services.SolrSearchService;
|
| 3303 |
rajveer |
6 |
import in.shop2020.serving.services.SpecialPageConfigurer;
|
| 6430 |
amit.gupta |
7 |
import in.shop2020.serving.utils.Utils;
|
| 2846 |
mandeep.dh |
8 |
|
|
|
9 |
import java.io.IOException;
|
|
|
10 |
import java.net.URLEncoder;
|
|
|
11 |
import java.util.ArrayList;
|
|
|
12 |
import java.util.Arrays;
|
|
|
13 |
import java.util.HashMap;
|
|
|
14 |
import java.util.LinkedHashMap;
|
|
|
15 |
import java.util.List;
|
|
|
16 |
import java.util.Map;
|
| 2948 |
chandransh |
17 |
import java.util.Map.Entry;
|
| 2846 |
mandeep.dh |
18 |
|
|
|
19 |
import org.apache.commons.lang.StringUtils;
|
|
|
20 |
import org.apache.log4j.Logger;
|
|
|
21 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
22 |
import org.json.JSONException;
|
|
|
23 |
|
|
|
24 |
/**
|
|
|
25 |
* @author rajveer
|
|
|
26 |
*
|
|
|
27 |
*/
|
|
|
28 |
@Result(name = "index", location = "special-page-index.vm")
|
|
|
29 |
public class SpecialPageController extends BaseController {
|
|
|
30 |
private static final long serialVersionUID = 1L;
|
|
|
31 |
private static Logger log = Logger.getLogger(Class.class);
|
|
|
32 |
|
| 6430 |
amit.gupta |
33 |
/* private static final String[] facetDefIDs =
|
| 2846 |
mandeep.dh |
34 |
new String[] {"F_50010","F_50011","F_50002","F_50001", "F_50006", "F_50007" };
|
|
|
35 |
|
|
|
36 |
private static final String[] facetLabels =
|
|
|
37 |
new String[] {"Category","Sub Category","Price", "Brand", "Data Connectivity", "Camera Resolution" };
|
| 6430 |
amit.gupta |
38 |
*/
|
| 2846 |
mandeep.dh |
39 |
private List<String> results;
|
|
|
40 |
private Map<String, String> snippets;
|
|
|
41 |
private Map<String, List<String[]>> facets;
|
|
|
42 |
private List<String[]> crumbs;
|
|
|
43 |
|
|
|
44 |
private String specialPageName;
|
|
|
45 |
private String specialPageTitle;
|
|
|
46 |
private String facetSelection = "";
|
|
|
47 |
|
|
|
48 |
private String query;
|
|
|
49 |
|
|
|
50 |
private Double minPrice;
|
|
|
51 |
private Double maxPrice;
|
|
|
52 |
|
|
|
53 |
private long windowSize = 20;
|
|
|
54 |
private long page = 1;
|
|
|
55 |
private long totalResults;
|
|
|
56 |
private long beginIndex = 0;
|
|
|
57 |
private String url;
|
|
|
58 |
private String priceUrl = "?";
|
| 3303 |
rajveer |
59 |
private String uri;
|
|
|
60 |
|
|
|
61 |
public String index() throws SecurityException, IOException, JSONException {
|
|
|
62 |
uri = request.getRequestURI();
|
| 3304 |
rajveer |
63 |
uri = uri.replace("/", "");
|
| 2846 |
mandeep.dh |
64 |
log.info("Uri: " + uri);
|
| 3303 |
rajveer |
65 |
specialPageName = SpecialPageConfigurer.getSpecialPageNameFromUri(uri);
|
|
|
66 |
specialPageTitle = SpecialPageConfigurer.getSpecialPageTitleFromUri(uri);
|
|
|
67 |
query = SpecialPageConfigurer.getQueryFromUri(uri);
|
| 2846 |
mandeep.dh |
68 |
|
|
|
69 |
String[] fqrys = this.request.getParameterValues("fq");
|
|
|
70 |
|
|
|
71 |
url = "?";
|
|
|
72 |
|
| 3320 |
rajveer |
73 |
String urlCrumb = url;
|
| 2846 |
mandeep.dh |
74 |
|
| 3320 |
rajveer |
75 |
this.crumbs = new ArrayList<String[]>();
|
| 6430 |
amit.gupta |
76 |
List<String> arrList = Arrays.asList(Utils.facetDefIDs);
|
| 3320 |
rajveer |
77 |
|
| 2846 |
mandeep.dh |
78 |
if(fqrys!= null){
|
| 3320 |
rajveer |
79 |
for(int i=0; i<fqrys.length; i++) {
|
|
|
80 |
urlCrumb += "&fq=" + URLEncoder.encode(fqrys[i], "UTF-8");
|
|
|
81 |
priceUrl += "&fq=" + URLEncoder.encode(fqrys[i], "UTF-8");
|
|
|
82 |
String filterUrl = url;
|
|
|
83 |
String facetName = StringUtils.split(fqrys[i], ":")[0];
|
|
|
84 |
String facetValue = StringUtils.split(fqrys[i], ":")[1];
|
| 6430 |
amit.gupta |
85 |
String facetLabel = Utils.facetLabels[arrList.indexOf(facetName)];
|
| 3320 |
rajveer |
86 |
this.specialPageTitle += " | " + facetLabel + " " + facetValue;
|
|
|
87 |
this.facetSelection += facetValue + " ";
|
|
|
88 |
for(int j=0; j<fqrys.length; j++) {
|
|
|
89 |
if(i==j){
|
|
|
90 |
continue;
|
|
|
91 |
}
|
|
|
92 |
filterUrl += "&fq=" + URLEncoder.encode(fqrys[j], "UTF-8");
|
|
|
93 |
}
|
|
|
94 |
String[] acrumb = new String[] { facetLabel, facetValue, filterUrl };
|
|
|
95 |
log.info("acrumb=" + Arrays.toString(acrumb));
|
|
|
96 |
this.crumbs.add(acrumb);
|
|
|
97 |
}
|
| 2846 |
mandeep.dh |
98 |
}
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
url = urlCrumb;
|
|
|
102 |
|
|
|
103 |
if(this.request.getParameter("page") != null){
|
|
|
104 |
this.page = Long.parseLong(this.request.getParameter("page"));
|
|
|
105 |
this.beginIndex = this.windowSize * (this.page-1);
|
|
|
106 |
}
|
|
|
107 |
|
| 3173 |
rajveer |
108 |
if(this.request.getParameter("minPrice") != null){
|
|
|
109 |
this.minPrice = (new Double(this.request.getParameter("minPrice")));
|
|
|
110 |
url= url + "&minPrice=" + this.request.getParameter("minPrice");
|
| 2846 |
mandeep.dh |
111 |
}
|
|
|
112 |
|
| 3173 |
rajveer |
113 |
if(this.request.getParameter("maxPrice") != null){
|
|
|
114 |
this.maxPrice = (new Double(this.request.getParameter("maxPrice")));
|
|
|
115 |
url= url + "&maxPrice=" + this.request.getParameter("maxPrice");
|
| 2846 |
mandeep.dh |
116 |
}
|
|
|
117 |
|
| 3561 |
rajveer |
118 |
String sortOrder = "F_50002+asc";
|
|
|
119 |
|
| 6430 |
amit.gupta |
120 |
SolrSearchService search = new SolrSearchService(query, fqrys, Utils.facetDefIDs, (page-1)*windowSize, windowSize, minPrice, maxPrice, 10000, sortOrder, sourceId);
|
| 2846 |
mandeep.dh |
121 |
this.results = search.getResultMap();
|
|
|
122 |
|
|
|
123 |
|
|
|
124 |
this.facets = new LinkedHashMap<String, List<String[]>>();
|
|
|
125 |
String qryString = this.request.getQueryString();
|
|
|
126 |
log.info("qryString=" + qryString);
|
|
|
127 |
|
| 6430 |
amit.gupta |
128 |
for (int i=0; i<Utils.facetDefIDs.length; i++) {
|
|
|
129 |
String facetDefID = Utils.facetDefIDs[i];
|
|
|
130 |
String facetLabel = Utils.facetLabels[i];
|
| 5729 |
amit.gupta |
131 |
Map<String, Integer> facetDetailMap = search.getFacetDetails(facetDefID);
|
| 2846 |
mandeep.dh |
132 |
if(facetDetailMap==null)
|
|
|
133 |
continue;
|
|
|
134 |
List<String[]> values = new ArrayList<String[]>();
|
| 2948 |
chandransh |
135 |
String drilldownURL = url + "&fq=" + facetDefID + ":";
|
|
|
136 |
for(Entry<String, Integer> facetEntry: facetDetailMap.entrySet()){
|
|
|
137 |
String facet = facetEntry.getKey();
|
| 2846 |
mandeep.dh |
138 |
|
|
|
139 |
String[] afacet = new String[] { facet,
|
| 3320 |
rajveer |
140 |
facetEntry.getValue().toString(), drilldownURL + URLEncoder.encode(facet, "UTF-8") };
|
| 2846 |
mandeep.dh |
141 |
|
| 2948 |
chandransh |
142 |
values.add(afacet);
|
| 2846 |
mandeep.dh |
143 |
}
|
|
|
144 |
|
|
|
145 |
this.facets.put(facetLabel, values);
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
Map<String, Double> priceMap = search.getPriceStatsMap();
|
|
|
149 |
if(priceMap != null){
|
|
|
150 |
this.minPrice = priceMap.get("min");
|
|
|
151 |
this.maxPrice = priceMap.get("max");
|
|
|
152 |
}
|
|
|
153 |
else{
|
|
|
154 |
this.minPrice = 0.0;
|
|
|
155 |
this.maxPrice = 0.0;
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
this.totalResults = search.getTotalResults();
|
|
|
159 |
return "index";
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
public String getPageMetaDesc() {
|
|
|
163 |
return "Best price " + this.facetSelection + this.specialPageName.replaceAll("Phones", "mobile phones")
|
|
|
164 |
+ " mobile phones in India. Experience n' buy online. FREE Next Day delivery. Original product - Full manufacturer warranty. Comprehensive reviews.";
|
|
|
165 |
}
|
|
|
166 |
|
| 3303 |
rajveer |
167 |
|
| 2846 |
mandeep.dh |
168 |
public String getPageMetaKeywords() throws JSONException {
|
| 3303 |
rajveer |
169 |
return SpecialPageConfigurer.getPageMetaKeywords(uri);
|
| 2846 |
mandeep.dh |
170 |
}
|
|
|
171 |
|
|
|
172 |
public long getBeginIndex(){
|
|
|
173 |
if(totalResults>0)
|
|
|
174 |
return beginIndex+1;
|
|
|
175 |
return beginIndex;
|
|
|
176 |
}
|
|
|
177 |
|
|
|
178 |
public long getTotalPages() {
|
|
|
179 |
return 1 + (totalResults-1)/windowSize;
|
|
|
180 |
}
|
|
|
181 |
|
| 3329 |
rajveer |
182 |
public Map<String, String> getSnippets(){
|
|
|
183 |
if(results != null){
|
|
|
184 |
snippets = new HashMap<String, String>();
|
|
|
185 |
for(String docId: results){
|
| 3561 |
rajveer |
186 |
String snippet = (String) SnippetCacheWrapper.getSnippet(CacheKeys.CATEGORY_SNIPPET_CACHE_KEY, docId, sourceId);
|
| 3329 |
rajveer |
187 |
if (snippet != null) {
|
|
|
188 |
snippets.put(docId, snippet);
|
|
|
189 |
}
|
|
|
190 |
}
|
|
|
191 |
}
|
|
|
192 |
return snippets;
|
| 2846 |
mandeep.dh |
193 |
}
|
|
|
194 |
|
|
|
195 |
public long getCurrentPage() {
|
|
|
196 |
return this.page;
|
|
|
197 |
}
|
|
|
198 |
|
|
|
199 |
public Double getMinPrice() {
|
|
|
200 |
return this.minPrice;
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
public Double getMaxPrice() {
|
|
|
204 |
return this.maxPrice;
|
|
|
205 |
}
|
|
|
206 |
|
|
|
207 |
public List<String[]> getCrumbs() {
|
|
|
208 |
return this.crumbs;
|
|
|
209 |
}
|
|
|
210 |
public String getSpecialPageTitle() {
|
|
|
211 |
return this.specialPageTitle;
|
|
|
212 |
}
|
|
|
213 |
|
|
|
214 |
public String getQuery() {
|
|
|
215 |
return this.query;
|
|
|
216 |
}
|
|
|
217 |
|
|
|
218 |
public List<String> getResults() {
|
|
|
219 |
return this.results;
|
|
|
220 |
}
|
|
|
221 |
|
|
|
222 |
public Map<String, List<String[]>> getFacets() {
|
|
|
223 |
return this.facets;
|
|
|
224 |
}
|
|
|
225 |
|
|
|
226 |
public long getTotalResults(){
|
|
|
227 |
return totalResults;
|
|
|
228 |
}
|
|
|
229 |
|
|
|
230 |
public String getUrl(){
|
|
|
231 |
return this.url;
|
|
|
232 |
}
|
|
|
233 |
|
|
|
234 |
public String getPriceUrl(){
|
|
|
235 |
return this.priceUrl;
|
|
|
236 |
}
|
|
|
237 |
|
|
|
238 |
public String getSpecialPageName() {
|
|
|
239 |
return this.specialPageName;
|
|
|
240 |
}
|
|
|
241 |
}
|