Subversion Repositories SmartDukaan

Rev

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

Rev 6842 Rev 6866
Line 34... Line 34...
34
})
34
})
35
public class SpecialPageController extends BaseController {
35
public class SpecialPageController extends BaseController {
36
    private static final long serialVersionUID = 1L;
36
    private static final long serialVersionUID = 1L;
37
    private static Logger log = Logger.getLogger(Class.class);
37
    private static Logger log = Logger.getLogger(Class.class);
38
 
38
 
39
/*	private static final String[] facetDefIDs = 
-
 
40
	    new String[] {"F_50010","F_50011","F_50002","F_50001",  "F_50006", "F_50007" };
-
 
41
 
-
 
42
	private static final String[] facetLabels = 
-
 
43
	    new String[] {"Category","Sub Category","Price", "Brand", "Data Connectivity", "Camera Resolution" };
-
 
44
*/
-
 
45
	private List<String> results;
39
	private List<String> results;
46
	private Map<String, String> snippets;
40
	private Map<String, String> snippets;
47
	private Map<String, List<String[]>> facets;
41
	private Map<String, List<String[]>> facets;
48
	private List<String[]> crumbs;
42
	private Map<String, List<List<String>>> crumbs;
49
	private List<String> tagSnippets = new ArrayList<String>();
43
	private List<String> tagSnippets = new ArrayList<String>();
50
	private String specialPageName;
44
	private String specialPageName;
51
	private String specialPageTitle;
45
	private String specialPageTitle;
52
	private String facetSelection = "";
46
	private String facetSelection = "";
-
 
47
	private String categoryName = "";
53
 
48
 
54
	private String query;
49
	private String query;
55
 
50
 
56
	private Double minPrice;
51
	private Double minPrice;
57
	private Double maxPrice;
52
	private Double maxPrice;
Line 63... Line 58...
63
	private long beginIndex = 0;
58
	private long beginIndex = 0;
64
	private String url;
59
	private String url;
65
	private String priceUrl = "?";
60
	private String priceUrl = "?";
66
	private String uri;
61
	private String uri;
67
	
62
	
68
	public String index() throws SecurityException, IOException, JSONException {
63
	public String index() throws Exception {
69
		uri = request.getRequestURI();
64
		uri = request.getRequestURI();
70
		uri = uri.replace("/", "");
65
		uri = uri.replace("/", "");
71
	    log.info("Uri: " + uri);
66
	    log.info("Uri: " + uri);
72
	    specialPageName  = SpecialPageConfigurer.getSpecialPageNameFromUri(uri);
67
	    specialPageName  = SpecialPageConfigurer.getSpecialPageNameFromUri(uri);
73
	    specialPageTitle = SpecialPageConfigurer.getSpecialPageTitleFromUri(uri);
68
	    specialPageTitle = SpecialPageConfigurer.getSpecialPageTitleFromUri(uri);
Line 78... Line 73...
78
 
73
 
79
    	url = "?";
74
    	url = "?";
80
 
75
 
81
    	String urlCrumb = url;
76
    	String urlCrumb = url;
82
    	
77
    	
83
    	this.crumbs = new ArrayList<String[]>();
78
    	this.crumbs = new HashMap<String, List<List<String>>>();
-
 
79
    	
-
 
80
    	String[] facetLabels = Utils.facetLabels;
84
    	List<String> arrList = Arrays.asList(Utils.facetDefIDs);
81
    	List<String> arrList = Arrays.asList(Utils.facetDefIDs);
85
    	
82
    	
86
    	if(fqrys!= null){
83
    	if(fqrys!= null){
-
 
84
    		log.info("fqrys=" + Arrays.toString(fqrys));
-
 
85
	    	String filterUrl = "";
87
    		for(int i=0; i<fqrys.length; i++) {
86
	    	for(int i=0; i<fqrys.length; i++){
88
        		urlCrumb += "&fq=" + URLEncoder.encode(fqrys[i], "UTF-8");
87
	    		urlCrumb += "&fq=" + URLEncoder.encode(fqrys[i], "UTF-8");
89
        		priceUrl += "&fq=" + URLEncoder.encode(fqrys[i], "UTF-8");
88
	    		priceUrl += "&fq=" + URLEncoder.encode(fqrys[i], "UTF-8");
90
        		String filterUrl = url;
-
 
91
        		String facetName = StringUtils.split(fqrys[i], ":")[0];
89
	    		String facetName = StringUtils.split(fqrys[i], ":")[0];
92
        		String facetValue = StringUtils.split(fqrys[i], ":")[1];
90
	    		String facetValue = StringUtils.split(fqrys[i], ":")[1];
93
        		String facetLabel = Utils.facetLabels[arrList.indexOf(facetName)];
91
	    		String facetLabel = facetLabels[arrList.indexOf(facetName)];
94
        		this.specialPageTitle += " | " + facetLabel + " " + facetValue;
92
	    		filterUrl = "&fq=" + URLEncoder.encode(fqrys[i], "UTF-8"); 
95
        		this.facetSelection += facetValue + " ";
93
	    		List<String> acrumb = Arrays.asList(facetValue, filterUrl);
96
        		for(int j=0; j<fqrys.length; j++) {
94
	    		if(!crumbs.containsKey(facetLabel)) {
97
        			if(i==j){
95
	    			crumbs.put(facetLabel, new ArrayList<List<String>>());
98
        				continue;
96
	    		}
99
        			}
97
	    		
100
        			filterUrl += "&fq=" + URLEncoder.encode(fqrys[j], "UTF-8");
98
	    		this.crumbs.get(facetLabel).add(acrumb);
101
    	    	}
99
	    	}
102
        		String[] acrumb = new String[] { facetLabel, facetValue, filterUrl };
-
 
103
        		log.info("acrumb=" + Arrays.toString(acrumb));
-
 
104
        		this.crumbs.add(acrumb);
100
    	} else {
105
        	}
101
    		fqrys = new String[0];
106
    	}
102
    	}
107
    	
103
    	
108
    	
104
    	
109
		url = urlCrumb;
105
		url = urlCrumb;
110
 
106
 
Line 130... Line 126...
130
    	String sortOrder = "F_50002+asc";
126
    	String sortOrder = "F_50002+asc";
131
    	
127
    	
132
    	SolrSearchService search = new SolrSearchService(query, fqrys, Utils.facetDefIDs, (page-1)*windowSize, windowSize, minPrice, maxPrice, 10000, sortOrder, sourceId);
128
    	SolrSearchService search = new SolrSearchService(query, fqrys, Utils.facetDefIDs, (page-1)*windowSize, windowSize, minPrice, maxPrice, 10000, sortOrder, sourceId);
133
    	this.results =  search.getResultMap(); 
129
    	this.results =  search.getResultMap(); 
134
 
130
 
135
    	
-
 
136
    	this.facets = new LinkedHashMap<String, List<String[]>>();
-
 
137
    	String qryString = this.request.getQueryString();
-
 
138
    	log.info("qryString=" + qryString);
131
    	setFacet(Arrays.asList(fqrys), search);
139
    	
-
 
140
    	for (int i=0; i<Utils.facetDefIDs.length; i++) {
-
 
141
    		String facetDefID = Utils.facetDefIDs[i];
-
 
142
    		String facetLabel = Utils.facetLabels[i];
-
 
143
    		Map<String, Integer> facetDetailMap = search.getFacetDetails(facetDefID);
-
 
144
    		if(facetDetailMap==null)
-
 
145
    			continue;
-
 
146
    		List<String[]> values = new ArrayList<String[]>();
-
 
147
    		String drilldownURL = url + "&fq=" + facetDefID + ":";
-
 
148
    		for(Entry<String, Integer> facetEntry: facetDetailMap.entrySet()){
-
 
149
    		    String facet = facetEntry.getKey();
-
 
150
 
-
 
151
    			String[] afacet = new String[] { facet, 
-
 
152
      					facetEntry.getValue().toString(), drilldownURL  + URLEncoder.encode(facet, "UTF-8")  };
-
 
153
 
132
 
154
      			values.add(afacet);
-
 
155
    		}
-
 
156
    		
-
 
157
    		this.facets.put(facetLabel, values);
-
 
158
    	}
-
 
159
 
133
 
160
    	Map<String, Double> priceMap = search.getPriceStatsMap();
134
    	Map<String, Double> priceMap = search.getPriceStatsMap();
161
    	if(priceMap != null){
135
    	if(priceMap != null){
162
    		this.minPrice = priceMap.get("min");
136
    		this.minPrice = priceMap.get("min");
163
    		this.maxPrice = priceMap.get("max");
137
    		this.maxPrice = priceMap.get("max");
Line 215... Line 189...
215
    
189
    
216
    public Double getMaxPrice() {
190
    public Double getMaxPrice() {
217
        return this.maxPrice;
191
        return this.maxPrice;
218
    }
192
    }
219
    
193
    
220
    public List<String[]> getCrumbs() {
194
    public Map<String,List<List<String>>> getCrumbs() {
221
        return this.crumbs;
195
        return this.crumbs;
222
    }
196
    }
223
    public String getSpecialPageTitle() {
197
    public String getSpecialPageTitle() {
224
        return this.specialPageTitle;
198
        return this.specialPageTitle;
225
    }   
199
    }   
Line 273... Line 247...
273
			// TODO Auto-generated catch block
247
			// TODO Auto-generated catch block
274
			e.printStackTrace();
248
			e.printStackTrace();
275
		}
249
		}
276
		return tagSnippets;
250
		return tagSnippets;
277
	}
251
	}
-
 
252
	
-
 
253
    private void setFacet(List<String> fqs, SolrSearchService search) throws Exception{
-
 
254
    	String[] toshowfacetDefIDs;
-
 
255
    	String[] toshowfacetLabels;
-
 
256
    	
-
 
257
		toshowfacetDefIDs = Utils.facetDefIDs;
-
 
258
		toshowfacetLabels = Utils.facetLabels;
-
 
259
 
-
 
260
    	this.facets = new LinkedHashMap<String, List<String[]>>();
-
 
261
    	for (int i=0; i<toshowfacetDefIDs.length; i++) {
-
 
262
    		String facetDefID = toshowfacetDefIDs[i];
-
 
263
    		String facetLabel = toshowfacetLabels[i];
-
 
264
    		
-
 
265
    		Map<String, Integer> facetDetailMap = search.getFacetDetails(facetDefID);
-
 
266
    		if(facetDetailMap==null)
-
 
267
    			continue;
-
 
268
    		List<String[]> values = new ArrayList<String[]>();
-
 
269
    		for(Entry<String, Integer> facetEntry : facetDetailMap.entrySet()){
-
 
270
    			String selected = "";
-
 
271
    			if(fqs.contains(facetDefID + ":" + facetEntry.getKey())) {
-
 
272
    				selected = "checked=\"checked\"";
-
 
273
    			}
-
 
274
    		    String facet = facetEntry.getKey();
-
 
275
      			String drilldownURL = "&fq=" +  
-
 
276
    				URLEncoder.encode( facetDefID + ":" + facet, "UTF-8"); 
-
 
277
      			String[] afacet = new String[] { facet, 
-
 
278
      			      facetEntry.getValue().toString(), drilldownURL,  selected};
-
 
279
      			values.add(afacet);    
-
 
280
    		}
-
 
281
    		
-
 
282
    		this.facets.put(facetLabel, values);
-
 
283
    	}
-
 
284
	}
-
 
285
    
-
 
286
    public List<String> getChildren(String categoryLabel) {
-
 
287
    	return SearchController.getCategoriesChildren().get(categoryLabel);
-
 
288
    }
278
}
289
}