Subversion Repositories SmartDukaan

Rev

Rev 6975 | Rev 6998 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6975 Rev 6976
Line 7... Line 7...
7
import in.shop2020.serving.cache.SnippetCacheWrapper;
7
import in.shop2020.serving.cache.SnippetCacheWrapper;
8
import in.shop2020.serving.services.SolrSearchService;
8
import in.shop2020.serving.services.SolrSearchService;
9
import in.shop2020.serving.utils.Utils;
9
import in.shop2020.serving.utils.Utils;
10
import in.shop2020.utils.CategoryManager;
10
import in.shop2020.utils.CategoryManager;
11
 
11
 
12
import java.io.IOException;
-
 
13
import java.net.URLEncoder;
12
import java.net.URLEncoder;
14
import java.util.ArrayList;
13
import java.util.ArrayList;
15
import java.util.Arrays;
14
import java.util.Arrays;
16
import java.util.HashMap;
15
import java.util.HashMap;
17
import java.util.LinkedHashMap;
16
import java.util.LinkedHashMap;
18
import java.util.List;
17
import java.util.List;
19
import java.util.Map;
18
import java.util.Map;
20
import java.util.Map.Entry;
19
import java.util.Map.Entry;
21
import java.util.StringTokenizer;
20
import java.util.StringTokenizer;
22
 
21
 
23
import org.apache.commons.lang.ArrayUtils;
-
 
24
import org.apache.commons.lang.StringUtils;
22
import org.apache.commons.lang.StringUtils;
25
import org.apache.log4j.Logger;
23
import org.apache.log4j.Logger;
26
import org.apache.struts2.convention.annotation.Action;
24
import org.apache.struts2.convention.annotation.Action;
27
import org.apache.struts2.convention.annotation.Actions;
25
import org.apache.struts2.convention.annotation.Actions;
28
import org.apache.struts2.convention.annotation.Result;
26
import org.apache.struts2.convention.annotation.Result;
Line 57... Line 55...
57
	 */
55
	 */
58
	private String id;
56
	private String id;
59
	
57
	
60
	private String categoryName;
58
	private String categoryName;
61
	private String redirectUrl;
59
	private String redirectUrl;
-
 
60
	
-
 
61
	private String sortOrder = "F_50030+desc";
-
 
62
	private String sortUrl = "?";
62
 
63
 
63
	public String getRedirectUrl() {
64
	public String getRedirectUrl() {
64
		return redirectUrl;
65
		return redirectUrl;
65
	}
66
	}
66
 
67
 
Line 79... Line 80...
79
	private long totalResults;
80
	private long totalResults;
80
	private long beginIndex = 0;
81
	private long beginIndex = 0;
81
	private String url;
82
	private String url;
82
	private String priceUrl = "?";
83
	private String priceUrl = "?";
83
 
84
 
-
 
85
	private String contextName;
-
 
86
 
-
 
87
 
84
	/**
88
	/**
85
	 * GET /abc/10004
89
	 * GET /abc/10004
86
	 * @throws Exception 
90
	 * @throws Exception 
87
	 * 
91
	 * 
88
	 */
92
	 */
Line 122... Line 126...
122
		
126
		
123
		@Action("/category")
127
		@Action("/category")
124
	})
128
	})
125
	 
129
	 
126
    public HttpHeaders show() throws Exception {
130
    public HttpHeaders show() throws Exception {
127
		if(ActionContext.getContext().getName().equals("hard-disk-drive")) {
131
		contextName = ActionContext.getContext().getName();
128
			redirectUrl = "/external-hard-disks/10073";
-
 
129
	        log.info("301 Redirection to " + redirectUrl);
-
 
130
	        return new DefaultHttpHeaders("redirect");
-
 
131
		}
-
 
132
    	log.info("id=" + id);
132
    	log.info("id=" + id);
133
    	categoryId = Long.parseLong(id);
133
    	categoryId = Long.parseLong(id);
134
    	this.categoryName = CategoryManager.getCategoryManager().getCategoryLabel(categoryId);
134
    	this.categoryName = CategoryManager.getCategoryManager().getCategoryLabel(categoryId);
135
    	
135
    	
136
    	if (categoryId == Utils.MOBILE_PHONES_CATEGORY || categoryId == Utils.MOBILE_ACCESSORIES_CATEGORY || categoryId == Utils.TABLETS_CATEGORY ){
136
    	if (categoryId == Utils.MOBILE_PHONES_CATEGORY || categoryId == Utils.MOBILE_ACCESSORIES_CATEGORY || categoryId == Utils.TABLETS_CATEGORY ){
Line 182... Line 182...
182
	    	String filterUrl = "";
182
	    	String filterUrl = "";
183
	    	for(int i=0; i<fqrys.length; i++){
183
	    	for(int i=0; i<fqrys.length; i++){
184
	    		newfqrys[i+1] = fqrys[i];
184
	    		newfqrys[i+1] = fqrys[i];
185
	    		urlCrumb += "&fq=" + URLEncoder.encode(fqrys[i], "UTF-8");
185
	    		urlCrumb += "&fq=" + URLEncoder.encode(fqrys[i], "UTF-8");
186
	    		priceUrl += "&fq=" + URLEncoder.encode(fqrys[i], "UTF-8");
186
	    		priceUrl += "&fq=" + URLEncoder.encode(fqrys[i], "UTF-8");
-
 
187
	    		sortUrl += "&fq=" + URLEncoder.encode(fqrys[i], "UTF-8");
187
	    		String facetName = StringUtils.split(fqrys[i], ":")[0];
188
	    		String facetName = StringUtils.split(fqrys[i], ":")[0];
188
	    		String facetValue = StringUtils.split(fqrys[i], ":")[1];
189
	    		String facetValue = StringUtils.split(fqrys[i], ":")[1];
189
	    		String facetLabel = facetLabels[arrList.indexOf(facetName)];
190
	    		String facetLabel = facetLabels[arrList.indexOf(facetName)];
190
	    		filterUrl = "&fq=" + URLEncoder.encode(fqrys[i], "UTF-8"); 
191
	    		filterUrl = "&fq=" + URLEncoder.encode(fqrys[i], "UTF-8"); 
191
	    		List<String> acrumb = Arrays.asList(facetValue, filterUrl);
192
	    		List<String> acrumb = Arrays.asList(facetValue, filterUrl);
Line 195... Line 196...
195
	    		
196
	    		
196
	    		this.crumbs.get(facetLabel).add(acrumb);
197
	    		this.crumbs.get(facetLabel).add(acrumb);
197
	    	}
198
	    	}
198
    	}
199
    	}
199
		url = urlCrumb;
200
		url = urlCrumb;
-
 
201
		if(this.request.getParameter("minPrice") != null){
-
 
202
			this.minPrice = (new Double(this.request.getParameter("minPrice")));
-
 
203
			url= url + "&minPrice=" + this.request.getParameter("minPrice");
-
 
204
		}
-
 
205
		if(this.request.getParameter("maxPrice") != null){
-
 
206
			this.maxPrice = (new Double(this.request.getParameter("maxPrice")));
-
 
207
			url= url + "&maxPrice=" + this.request.getParameter("maxPrice");
-
 
208
		}
-
 
209
		
-
 
210
		sortUrl = url;
200
    	    	
211
    	    	
201
    	if(this.request.getParameter("page") != null){
212
    	if(this.request.getParameter("page") != null){
202
    		this.page = Long.parseLong(this.request.getParameter("page"));
213
    		this.page = Long.parseLong(this.request.getParameter("page"));
203
    		this.beginIndex = this.windowSize * (this.page-1);
214
    		this.beginIndex = this.windowSize * (this.page-1);
204
    	}
215
    	}
205
    	if(this.request.getParameter("minPrice") != null){
-
 
206
    		this.minPrice = (new Double(this.request.getParameter("minPrice")));
-
 
207
    		url= url + "&minPrice=" + this.request.getParameter("minPrice");
-
 
208
    	}
-
 
209
    	if(this.request.getParameter("maxPrice") != null){
-
 
210
    		this.maxPrice = (new Double(this.request.getParameter("maxPrice")));
-
 
211
    		url= url + "&maxPrice=" + this.request.getParameter("maxPrice");
-
 
212
    	}    	
-
 
213
 
216
 
-
 
217
    	if(request.getParameter("sort")!=null){
-
 
218
    		url= url + "&sort=" + this.request.getParameter("sort");
214
    	String sortOrder = "F_50028+asc,F_50030+desc";
219
    		sortOrder = this.request.getParameter("sort");
-
 
220
    	}
215
    	
221
    	
216
    	SolrSearchService search = new SolrSearchService(query, newfqrys, facetDefIDs, (page-1)*windowSize, windowSize, minPrice, maxPrice, Utils.ROOT_CATEGORY, sortOrder, sourceId);
222
    	SolrSearchService search = new SolrSearchService(query, newfqrys, facetDefIDs, (page-1)*windowSize, windowSize, minPrice, maxPrice, Utils.ROOT_CATEGORY, "F_50028+asc," + sortOrder, sourceId);
217
    	this.results =  search.getResultMap(); 
223
    	this.results =  search.getResultMap(); 
218
    	this.dynamicSearchMap =  search.getDynamicPriceMap();
224
    	this.dynamicSearchMap =  search.getDynamicPriceMap();
219
 
225
 
220
    	setFacet(Arrays.asList(newfqrys), search);
226
    	setFacet(Arrays.asList(newfqrys), search);
221
 
227
 
Line 315... Line 321...
315
    
321
    
316
    public Double getMaxPrice() {
322
    public Double getMaxPrice() {
317
    	return this.maxPrice;
323
    	return this.maxPrice;
318
    }
324
    }
319
    
325
    
-
 
326
    public String getContextName() {
-
 
327
    	return contextName;
-
 
328
    }
-
 
329
    
320
    public String getPriceUrl() {
330
    public String getPriceUrl() {
321
        return this.priceUrl;
331
        return this.priceUrl;
322
    }
332
    }
323
    
333
    
324
    public Map<String, List<List<String>>> getCrumbs() {
334
    public Map<String, List<List<String>>> getCrumbs() {
Line 397... Line 407...
397
    		return "{}";
407
    		return "{}";
398
    	} else {
408
    	} else {
399
    		return new Gson().toJson(this.dynamicSearchMap);
409
    		return new Gson().toJson(this.dynamicSearchMap);
400
    	}
410
    	}
401
    }
411
    }
-
 
412
	
-
 
413
	public String getSortOrder(){
-
 
414
		return this.sortOrder;
-
 
415
	}
-
 
416
	
-
 
417
	public String getSortUrl(){
-
 
418
		return this.sortUrl;
-
 
419
	}
-
 
420
 
402
}
421
}
403
422