Subversion Repositories SmartDukaan

Rev

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

Rev 6708 Rev 6866
Line 46... Line 46...
46
	private static Logger log = Logger.getLogger(Class.class);
46
	private static Logger log = Logger.getLogger(Class.class);
47
 
47
 
48
	private List<String> results;
48
	private List<String> results;
49
	private Map<String, String> snippets;
49
	private Map<String, String> snippets;
50
	private Map<String, List<String[]>> facets;
50
	private Map<String, List<String[]>> facets;
51
	private List<String[]> crumbs;
51
	private Map<String, List<List<String>>> crumbs;
52
	/**
52
	/**
53
	 * 
53
	 * 
54
	 */
54
	 */
55
	private String id;
55
	private String id;
56
	
56
	
Line 78... Line 78...
78
	private String url;
78
	private String url;
79
	private String priceUrl = "?";
79
	private String priceUrl = "?";
80
 
80
 
81
	/**
81
	/**
82
	 * GET /abc/10004
82
	 * GET /abc/10004
-
 
83
	 * @throws Exception 
83
	 * 
84
	 * 
84
	 */
85
	 */
85
	@Actions({
86
	@Actions({
86
		@Action("/all-mobile-phones"),
87
		@Action("/all-mobile-phones"),
87
		@Action("/all-mobile-accessories"),
88
		@Action("/all-mobile-accessories"),
Line 117... Line 118...
117
		@Action("/portable-music-players"),
118
		@Action("/portable-music-players"),
118
		
119
		
119
		@Action("/category")
120
		@Action("/category")
120
	})
121
	})
121
	 
122
	 
122
    public HttpHeaders show() throws SecurityException, IOException {
123
    public HttpHeaders show() throws Exception {
123
		if(ActionContext.getContext().getName().equals("hard-disk-drive")) {
124
		if(ActionContext.getContext().getName().equals("hard-disk-drive")) {
124
			redirectUrl = "/external-hard-disks/10073";
125
			redirectUrl = "/external-hard-disks/10073";
125
	        log.info("301 Redirection to " + redirectUrl);
126
	        log.info("301 Redirection to " + redirectUrl);
126
	        return new DefaultHttpHeaders("redirect");
127
	        return new DefaultHttpHeaders("redirect");
127
		}
128
		}
Line 158... Line 159...
158
    		newfqrys[0] = "F_50011:"+categoryName;
159
    		newfqrys[0] = "F_50011:"+categoryName;
159
    	}
160
    	}
160
    	
161
    	
161
    	String urlCrumb = url;
162
    	String urlCrumb = url;
162
    	
163
    	
163
    	this.crumbs = new ArrayList<String[]>();
164
    	this.crumbs = new HashMap<String, List<List<String>>>();
164
    	List<String> arrList = Arrays.asList(facetDefIDs);
-
 
165
    	for(int i=1; i<length; i++) {
-
 
166
    		newfqrys[i] = fqrys[i-1];
-
 
167
    		urlCrumb += "&fq=" + URLEncoder.encode(fqrys[i-1], "UTF-8");
-
 
168
    		priceUrl += "&fq=" + URLEncoder.encode(fqrys[i-1], "UTF-8");
-
 
169
    		StringBuilder filterUrl = new StringBuilder(url);
-
 
170
 
165
 
171
    		String facetName = StringUtils.split(fqrys[i-1], ":")[0];
166
    	if(query != null) {
172
    		String facetValue = StringUtils.split(fqrys[i-1], ":")[1];
167
	    	urlCrumb = url; 
-
 
168
	    }else {
173
    		
169
    		
174
    		try {
170
    	}
-
 
171
    	
-
 
172
    	if(fqrys != null) {
175
        		String facetLabel = facetLabels[arrList.indexOf(facetName)];
173
	    	log.info("fqrys=" + Arrays.toString(fqrys));
176
        		this.categoryTitle += " | " + facetLabel + " " + facetValue;
174
	    	List<String> arrList = Arrays.asList(facetDefIDs);
177
        		this.facetSelection += facetValue + " ";
175
	    	String filterUrl = "";
178
        		for(int j=1; j<length; j++) {
176
	    	for(int i=0; i<fqrys.length; i++){
179
        			if(i==j){
177
	    		newfqrys[i+1] = fqrys[i];
180
        				continue;
178
	    		urlCrumb += "&fq=" + URLEncoder.encode(fqrys[i], "UTF-8");
181
        			}
-
 
182
        			filterUrl.append("&fq=" + URLEncoder.encode(fqrys[j-1], "UTF-8"));
179
	    		priceUrl += "&fq=" + URLEncoder.encode(fqrys[i], "UTF-8");
183
    	    	}
180
	    		String facetName = StringUtils.split(fqrys[i], ":")[0];
-
 
181
	    		String facetValue = StringUtils.split(fqrys[i], ":")[1];
184
        		String[] acrumb = new String[] { facetLabel, facetValue, filterUrl.toString() };
182
	    		String facetLabel = facetLabels[arrList.indexOf(facetName)];
-
 
183
	    		filterUrl = "&fq=" + URLEncoder.encode(fqrys[i], "UTF-8"); 
185
        		log.info("acrumb=" + Arrays.toString(acrumb));
184
	    		List<String> acrumb = Arrays.asList(facetValue, filterUrl);
186
        		this.crumbs.add(acrumb);
185
	    		if(!crumbs.containsKey(facetLabel)) {
-
 
186
	    			crumbs.put(facetLabel, new ArrayList<List<String>>());
-
 
187
	    		}
187
				
188
	    		
188
			} catch (ArrayIndexOutOfBoundsException e) {
189
	    		this.crumbs.get(facetLabel).add(acrumb);
189
				log.error("CategoryControllerArrayIndexOutOfBoundsException " + arrList + " " + facetName + " " + facetLabels);
-
 
190
			}
190
	    	}
191
    	}
191
    	}
192
		url = urlCrumb;
192
		url = urlCrumb;
193
    	    	
193
    	    	
194
    	if(this.request.getParameter("page") != null){
194
    	if(this.request.getParameter("page") != null){
195
    		this.page = Long.parseLong(this.request.getParameter("page"));
195
    		this.page = Long.parseLong(this.request.getParameter("page"));
Line 207... Line 207...
207
    	String sortOrder = "F_50002+asc";
207
    	String sortOrder = "F_50002+asc";
208
    	
208
    	
209
    	SolrSearchService search = new SolrSearchService(query, newfqrys, facetDefIDs, (page-1)*windowSize, windowSize, minPrice, maxPrice, Utils.ROOT_CATEGORY, sortOrder, sourceId);
209
    	SolrSearchService search = new SolrSearchService(query, newfqrys, facetDefIDs, (page-1)*windowSize, windowSize, minPrice, maxPrice, Utils.ROOT_CATEGORY, sortOrder, sourceId);
210
    	this.results =  search.getResultMap(); 
210
    	this.results =  search.getResultMap(); 
211
 
211
 
212
    	
-
 
213
    	this.facets = new LinkedHashMap<String, List<String[]>>();
-
 
214
    	String qryString = this.request.getQueryString();
-
 
215
    	log.info("qryString=" + qryString);
212
    	setFacet(Arrays.asList(newfqrys), search);
216
    	
-
 
217
    	String[] toshowfacetDefIDs;
-
 
218
    	String[] toshowfacetLabels;
-
 
219
    	
-
 
220
    	if (categoryId == Utils.ROOT_CATEGORY || categoryId == Utils.MOBILE_ACCESSORIES_CATEGORY ){
-
 
221
    		toshowfacetDefIDs = Utils.rootfacetDefIDs;
-
 
222
        	toshowfacetLabels = Utils.rootfacetLabels;
-
 
223
    	}
-
 
224
    	else {
-
 
225
    		toshowfacetDefIDs = Utils.facetDefIDs;
-
 
226
        	toshowfacetLabels = Utils.facetLabels;
-
 
227
    	}
-
 
228
    	
-
 
229
    	for (int i=0; i<toshowfacetDefIDs.length; i++) {
-
 
230
    		String facetDefID = toshowfacetDefIDs[i];
-
 
231
    		String facetLabel = toshowfacetLabels[i];
-
 
232
    		Map<String, Integer> facetDetailMap = search.getFacetDetails(facetDefID);
-
 
233
    		if(facetDetailMap==null)
-
 
234
    			continue;
-
 
235
    		List<String[]> values = new ArrayList<String[]>();
-
 
236
    		for(Entry<String, Integer> facetEntry: facetDetailMap.entrySet()){
-
 
237
    		    String facet = facetEntry.getKey();
-
 
238
    			String drilldownURL = url + "&fq=" + facetDefID + ":" + 
-
 
239
    				URLEncoder.encode(facet, "UTF-8");
-
 
240
      			String[] afacet = new String[] { facet, 
-
 
241
      			      facetEntry.getValue().toString(), drilldownURL  };
-
 
242
      			values.add(afacet);    
-
 
243
      			
-
 
244
    		}
-
 
245
    		
-
 
246
    		this.facets.put(facetLabel, values);
-
 
247
    	}
-
 
248
    	
-
 
249
    	
213
 
250
    	
214
    	
251
    	Map<String, Double> priceMap = search.getPriceStatsMap();
215
    	Map<String, Double> priceMap = search.getPriceStatsMap();
252
    	if(priceMap != null){
216
    	if(priceMap != null){
253
    		this.minPrice = priceMap.get("min");
217
    		this.minPrice = priceMap.get("min");
254
    		this.maxPrice = priceMap.get("max");
218
    		this.maxPrice = priceMap.get("max");
Line 343... Line 307...
343
    
307
    
344
    public String getPriceUrl() {
308
    public String getPriceUrl() {
345
        return this.priceUrl;
309
        return this.priceUrl;
346
    }
310
    }
347
    
311
    
348
    public List<String[]> getCrumbs() {
312
    public Map<String, List<List<String>>> getCrumbs() {
349
    	return this.crumbs;
313
    	return this.crumbs;
350
    }
314
    }
351
 
315
 
352
    public Map<String, String> getSnippets(){
316
    public Map<String, String> getSnippets(){
353
        if(results != null){
317
        if(results != null){
Line 376... Line 340...
376
	}
340
	}
377
    @Override
341
    @Override
378
	public String getCartWidgetSnippet() {
342
	public String getCartWidgetSnippet() {
379
		return pageLoader.getCartWidgetSnippet(userinfo.getTotalItems(), userinfo.getTotalAmount(),categoryId);
343
		return pageLoader.getCartWidgetSnippet(userinfo.getTotalItems(), userinfo.getTotalAmount(),categoryId);
380
	}
344
	}
-
 
345
    
-
 
346
    private void setFacet(List<String> fqs, SolrSearchService search) throws Exception{
-
 
347
    	String[] toshowfacetDefIDs;
-
 
348
    	String[] toshowfacetLabels;
-
 
349
    	
-
 
350
		toshowfacetDefIDs = Utils.facetDefIDs;
-
 
351
		toshowfacetLabels = Utils.facetLabels;
-
 
352
 
-
 
353
    	this.facets = new LinkedHashMap<String, List<String[]>>();
-
 
354
    	for (int i=0; i<toshowfacetDefIDs.length; i++) {
-
 
355
    		String facetDefID = toshowfacetDefIDs[i];
-
 
356
    		String facetLabel = toshowfacetLabels[i];
-
 
357
    		
-
 
358
    		Map<String, Integer> facetDetailMap = search.getFacetDetails(facetDefID);
-
 
359
    		if(facetDetailMap==null)
-
 
360
    			continue;
-
 
361
    		List<String[]> values = new ArrayList<String[]>();
-
 
362
    		for(Entry<String, Integer> facetEntry : facetDetailMap.entrySet()){
-
 
363
    			String selected = "";
-
 
364
    			if(fqs.contains(facetDefID + ":" + facetEntry.getKey())) {
-
 
365
    				selected = "checked=\"checked\"";
-
 
366
    			}
-
 
367
    		    String facet = facetEntry.getKey();
-
 
368
      			String drilldownURL = "&fq=" +  
-
 
369
    				URLEncoder.encode( facetDefID + ":" + facet, "UTF-8"); 
-
 
370
      			String[] afacet = new String[] { facet, 
-
 
371
      			      facetEntry.getValue().toString(), drilldownURL,  selected};
-
 
372
      			values.add(afacet);    
-
 
373
    		}
-
 
374
    		
-
 
375
    		this.facets.put(facetLabel, values);
-
 
376
    	}
-
 
377
	}
-
 
378
    
-
 
379
    public List<String> getChildren(String categoryLabel) {
-
 
380
    	return SearchController.getCategoriesChildren().get(categoryLabel);
-
 
381
    }
381
}
382
}
382
383