Subversion Repositories SmartDukaan

Rev

Rev 536 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 536 Rev 545
Line 58... Line 58...
58
	private String query;
58
	private String query;
59
	
59
	
60
	private Double minPrice;
60
	private Double minPrice;
61
	private Double maxPrice;
61
	private Double maxPrice;
62
	
62
	
-
 
63
	
-
 
64
	private long windowSize = 20;
-
 
65
	private long page = 1;
-
 
66
	private long totalResults;
-
 
67
	private long beginIndex = 0;
-
 
68
	private String url;
-
 
69
	private String priceUrl;
-
 
70
 
63
	/**
71
	/**
64
	 * GET /category/10004
72
	 * GET /category/10004
65
	 * 
73
	 * 
66
	 */
74
	 */
67
    public HttpHeaders show() throws SecurityException, IOException {
75
    public HttpHeaders show() throws SecurityException, IOException {
Line 81... Line 89...
81
		
89
		
82
		htmlSnippets.put("CATEGORY_HEADER", pageLoader.getCategoryHeaderSnippet());
90
		htmlSnippets.put("CATEGORY_HEADER", pageLoader.getCategoryHeaderSnippet());
83
		htmlSnippets.put("MAIN_BANNER", "");
91
		htmlSnippets.put("MAIN_BANNER", "");
84
		htmlSnippets.put("SIDE_BANNER", "");
92
		htmlSnippets.put("SIDE_BANNER", "");
85
		htmlSnippets.put("TAB_BUTTONS", "");
93
		htmlSnippets.put("TAB_BUTTONS", "");
86
		htmlSnippets.put("FOOTER", "");
94
		
87
 
95
 
88
 
96
 
89
		
97
		
90
		String[] facetDefIDs = new String[] {"Category","F_50002","F_50001",  "F_50006", "F_50007" };
98
		String[] facetDefIDs = new String[] {"Category","F_50002","F_50001",  "F_50006", "F_50007" };
91
    	
99
    	
92
    	String[] facetLabels = new String[] {"Category","Price", "Brand", "Data Connectivity", "Camera Resolution" 	};
100
    	String[] facetLabels = new String[] {"Category","Price", "Brand", "Data Connectivity", "Camera Resolution" 	};
93
 
101
 
94
    	String[] fqrys = this.request.getParameterValues("fq");
102
    	String[] fqrys = this.request.getParameterValues("fq");
-
 
103
 
-
 
104
    	url = "?";
95
    	
105
    	
-
 
106
    	
-
 
107
    	    	
96
    	query = "*";
108
    	query = "*";
97
    	
109
    	
98
    	int length = 1;
110
    	int length = 1;
99
    	
111
    	
100
    	if(fqrys!= null){
112
    	if(fqrys!= null){
101
    		length += fqrys.length;
113
    		length += fqrys.length;
102
    	}
114
    	}
103
    	
115
    	
104
    	String[] newfqrys = new String[length];
116
    	String[] newfqrys = new String[length];
105
    	newfqrys[0] = "F_50001:"+categoryName;
117
    	newfqrys[0] = "Category:"+categoryName;
-
 
118
    	String urlCrumb = url;
106
    	
119
    	
107
    	for(int i=1; i<length; i++) {
120
    	for(int i=1; i<length; i++) {
108
    		newfqrys[i] = fqrys[i-1];
121
    		newfqrys[i] = fqrys[i-1];
-
 
122
    		urlCrumb += "&fq=" + URLEncoder.encode(fqrys[i-1], "UTF-8");
-
 
123
    		priceUrl += "&fq=" + URLEncoder.encode(fqrys[i-1], "UTF-8");
109
    	}
124
    	}
-
 
125
		url = urlCrumb;
-
 
126
    	    	
-
 
127
    	if(this.request.getParameter("page") != null){
-
 
128
    		this.page = Long.parseLong(this.request.getParameter("page"));
-
 
129
    		this.beginIndex = this.windowSize * (this.page-1);
-
 
130
    	}
-
 
131
    	if(this.request.getParameter("min-price") != null){
-
 
132
    		this.minPrice = (new Double(this.request.getParameter("min-price")));
-
 
133
    		url= url + "&min-price=" + this.request.getParameter("min-price");
-
 
134
    	}
-
 
135
    	if(this.request.getParameter("max-price") != null){
-
 
136
    		this.maxPrice = (new Double(this.request.getParameter("max-price")));
-
 
137
    		url= url + "&max-price=" + this.request.getParameter("max-price");
-
 
138
    	}    	
110
    	
139
    	
111
    	
-
 
112
    	SolrSearchService search = new SolrSearchService(query, newfqrys, facetDefIDs);
140
    	SolrSearchService search = new SolrSearchService(query, newfqrys, facetDefIDs, (page-1)*windowSize, windowSize, minPrice, maxPrice);
113
    	this.results = new LinkedHashMap<String, String[]>();
141
    	this.results = new LinkedHashMap<String, String[]>();
114
    	this.results =  search.getResultMap(); 
142
    	this.results =  search.getResultMap(); 
115
 
143
 
116
    	
144
    	
117
    	
-
 
118
    	
-
 
119
    	this.facets = new LinkedHashMap<String, List<String[]>>();
145
    	this.facets = new LinkedHashMap<String, List<String[]>>();
120
    	String qryString = this.request.getQueryString();
146
    	String qryString = this.request.getQueryString();
121
    	log.info("qryString=" + qryString);
147
    	log.info("qryString=" + qryString);
122
    	
148
    	
123
    	for (int i=0; i<facetDefIDs.length; i++) {
149
    	for (int i=0; i<facetDefIDs.length; i++) {
Line 125... Line 151...
125
    		String facetLabel = facetLabels[i];
151
    		String facetLabel = facetLabels[i];
126
    		HashMap<String, Integer> facetDetailMap = search.getFacetDetails(facetDefID);
152
    		HashMap<String, Integer> facetDetailMap = search.getFacetDetails(facetDefID);
127
    		if(facetDetailMap==null)
153
    		if(facetDetailMap==null)
128
    			continue;
154
    			continue;
129
    		List<String[]> values = new ArrayList<String[]>();
155
    		List<String[]> values = new ArrayList<String[]>();
-
 
156
    		String drilldownURL = new String();
130
    		for(String facet: facetDetailMap.keySet()){
157
    		for(String facet: facetDetailMap.keySet()){
131
    			String drilldownURL = new String();
-
 
132
    			
158
    			
-
 
159
    			/*
133
    			if(qryString != null){
160
    			if(qryString != null){
134
    				drilldownURL = qryString;
161
    				drilldownURL = qryString;
-
 
162
    				
135
    			}
163
    			}
-
 
164
    			*/
-
 
165
        		drilldownURL = url;
136
    			
166
    			
-
 
167
    			
137
    			drilldownURL = "fq=" + facetDefID + ":" + 
168
    			drilldownURL = drilldownURL + "&fq=" + facetDefID + ":" + 
138
    				URLEncoder.encode(facet, "UTF-8"); 
169
    				URLEncoder.encode(facet, "UTF-8");
139
      			String[] afacet = new String[] { facet, 
170
      			String[] afacet = new String[] { facet, 
140
      					facetDetailMap.get(facet).toString(), drilldownURL  };
171
      					facetDetailMap.get(facet).toString(), drilldownURL  };
141
      			values.add(afacet);    
172
      			values.add(afacet);    
142
      		  
173
      			
143
    		}
174
    		}
144
    		
175
    		
145
    		this.facets.put(facetLabel, values);
176
    		this.facets.put(facetLabel, values);
146
    	}
177
    	}
147
    	
178
    	
148
    	
179
    	
-
 
180
    	
149
    	Map<String, Double> priceMap = search.getPriceStatsMap();
181
    	Map<String, Double> priceMap = search.getPriceStatsMap();
150
    	if(priceMap != null){
182
    	if(priceMap != null){
151
    		this.minPrice = priceMap.get("min");
183
    		this.minPrice = priceMap.get("min");
152
    		this.maxPrice = priceMap.get("max");
184
    		this.maxPrice = priceMap.get("max");
153
    	}else{
185
    	}else{
154
    		this.minPrice = 0.0;
186
    		this.minPrice = 0.0;
155
    		this.maxPrice = 0.0;
187
    		this.maxPrice = 0.0;
156
    	}
188
    	}
157
 
-
 
-
 
189
    	this.totalResults = search.getTotalResults();
158
        return new DefaultHttpHeaders("show");
190
        return new DefaultHttpHeaders("show");
159
    }
191
    }
160
    
192
    
161
    /**
193
    /**
162
     * 
194
     * 
Line 244... Line 276...
244
     */
276
     */
245
    public Map<String, List<String[]>> getFacets() {
277
    public Map<String, List<String[]>> getFacets() {
246
    	return this.facets;
278
    	return this.facets;
247
    }
279
    }
248
    
280
    
-
 
281
    
-
 
282
    public long getTotalResults(){
-
 
283
    	return totalResults;
-
 
284
    }
-
 
285
    
-
 
286
    public String getUrl(){
-
 
287
    	return this.url;
-
 
288
    }
-
 
289
 
-
 
290
    public String getPriceUrl(){
-
 
291
    	return this.priceUrl;
-
 
292
    }
-
 
293
    
-
 
294
	public long getBeginIndex(){
-
 
295
		if(totalResults>0)
-
 
296
			return beginIndex+1;
-
 
297
		return beginIndex;
-
 
298
	}
-
 
299
 
-
 
300
	public long getTotalPages() {
-
 
301
		return 1 + totalResults/windowSize;
-
 
302
	}
-
 
303
 
-
 
304
	public long getCurrentPage() {
-
 
305
		return this.page;
-
 
306
	}
-
 
307
 
249
    public Double getMinPrice() {
308
    public Double getMinPrice() {
250
    	return this.minPrice;
309
    	return this.minPrice;
251
    }
310
    }
252
    
311
    
253
    public Double getMaxPrice() {
312
    public Double getMaxPrice() {