Subversion Repositories SmartDukaan

Rev

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

Rev 6949 Rev 6998
Line 66... Line 66...
66
	private String url;
66
	private String url;
67
	private String priceUrl = "?";
67
	private String priceUrl = "?";
68
	private String sortUrl;
68
	private String sortUrl;
69
	private String location;
69
	private String location;
70
	private static HashMap<String, List<String>> categoriesChildren = null;
70
	private static HashMap<String, List<String>> categoriesChildren = null;
-
 
71
	private static Map<Long, String> categoryLabelMap = null;
71
	
72
	
72
	/**
73
	/**
73
	 * 
74
	 * 
74
	 * @return
75
	 * @return
75
	 * @throws UnsupportedEncodingException
76
	 * @throws UnsupportedEncodingException
Line 111... Line 112...
111
    	
112
    	
112
    	String[] fqrys = this.request.getParameterValues("fq");
113
    	String[] fqrys = this.request.getParameterValues("fq");
113
    	
114
    	
114
    	this.crumbs = new HashMap<String, List<List<String>>>();
115
    	this.crumbs = new HashMap<String, List<List<String>>>();
115
    	
116
    	
116
    	String[] facetDefIDs = Utils.facetDefIDs;
-
 
117
    	String[] facetLabels = Utils.facetLabels;
-
 
118
    	
117
    	    	
119
    	String urlCrumb = "";
118
    	String urlCrumb = "";
120
    	if(query != null) {
119
    	if(query != null) {
121
	    	urlCrumb = url; 
120
	    	urlCrumb = url; 
122
	    }else {
121
	    }else {
123
    		
122
    		
124
    	}
123
    	}
125
    	
124
    	
126
    	if(fqrys != null) {
125
    	if(fqrys != null) {
127
	    	log.info("fqrys=" + Arrays.toString(fqrys));
126
	    	log.info("fqrys=" + Arrays.toString(fqrys));
128
	    	List<String> arrList = Arrays.asList(facetDefIDs);
-
 
129
	    	String filterUrl = "";
127
	    	String filterUrl = "";
130
	    	for(int i=0; i<fqrys.length; i++){
128
	    	for(int i=0; i<fqrys.length; i++){
131
	    		urlCrumb += "&fq=" + URLEncoder.encode(fqrys[i], "UTF-8");
129
	    		urlCrumb += "&fq=" + URLEncoder.encode(fqrys[i], "UTF-8");
132
	    		priceUrl += "&fq=" + URLEncoder.encode(fqrys[i], "UTF-8");
130
	    		priceUrl += "&fq=" + URLEncoder.encode(fqrys[i], "UTF-8");
133
	    		sortUrl += "&fq=" + URLEncoder.encode(fqrys[i], "UTF-8");
131
	    		sortUrl += "&fq=" + URLEncoder.encode(fqrys[i], "UTF-8");
134
	    		String facetName = StringUtils.split(fqrys[i], ":")[0];
132
	    		String facetName = StringUtils.split(fqrys[i], ":")[0];
135
	    		String facetValue = StringUtils.split(fqrys[i], ":")[1];
133
	    		String facetValue = StringUtils.split(fqrys[i], ":")[1];
136
	    		String facetLabel = facetLabels[arrList.indexOf(facetName)];
134
	    		String facetLabel = Utils.FACET_LABEL_MAP.get(facetName);
137
	    		filterUrl = "&fq=" + URLEncoder.encode(fqrys[i], "UTF-8"); 
135
	    		filterUrl = "&fq=" + URLEncoder.encode(fqrys[i], "UTF-8"); 
138
	    		List<String> acrumb = Arrays.asList(facetValue, filterUrl);
136
	    		List<String> acrumb = Arrays.asList(facetValue, filterUrl);
139
	    		if(!crumbs.containsKey(facetLabel)) {
137
	    		if(!crumbs.containsKey(facetLabel)) {
140
	    			crumbs.put(facetLabel, new ArrayList<List<String>>());
138
	    			crumbs.put(facetLabel, new ArrayList<List<String>>());
141
	    		}
139
	    		}
Line 145... Line 143...
145
    	}
143
    	}
146
    	url = urlCrumb;
144
    	url = urlCrumb;
147
 
145
 
148
    	
146
    	
149
    	
147
    	
150
    	SolrSearchService search = new SolrSearchService(query, fqrys, facetDefIDs, (page-1)*windowSize, windowSize, minPrice, maxPrice, Utils.ROOT_CATEGORY, sortOrder, sourceId);
148
    	SolrSearchService search = new SolrSearchService(query, fqrys, (page-1)*windowSize, windowSize, minPrice, maxPrice, sortOrder, sourceId);
151
 
149
 
152
    	this.results =  search.getResultMap(); 
150
    	this.results =  search.getResultMap(); 
153
    	this.dynamicSearchMap = search.getDynamicPriceMap();
151
    	this.dynamicSearchMap = search.getDynamicPriceMap();
154
    	// Facets
152
    	// Facets
155
    	List<String> fqs = null;
153
    	List<String> fqs = null;
Line 181... Line 179...
181
    	return "index";
179
    	return "index";
182
    }
180
    }
183
 
181
 
184
 
182
 
185
    private void setFacet(List<String> fqs, SolrSearchService search) throws Exception{
183
    private void setFacet(List<String> fqs, SolrSearchService search) throws Exception{
186
    	String[] toshowfacetDefIDs;
-
 
187
    	String[] toshowfacetLabels;
-
 
188
    	
-
 
189
		if (fqs.contains("F_50010:Mobile Phones") || fqs.contains("F_50010:Cameras") || fqs.contains("F_50010:Tablets")){
-
 
190
    		toshowfacetDefIDs = Utils.facetDefIDs;
-
 
191
    		toshowfacetLabels = Utils.facetLabels;
-
 
192
    	}
-
 
193
    	else {
-
 
194
    		toshowfacetDefIDs = Utils.rootfacetDefIDs;
-
 
195
    		toshowfacetLabels = Utils.rootfacetLabels;
-
 
196
    	}
-
 
197
 
184
 
198
    	this.facets = new LinkedHashMap<String, List<String[]>>();
185
    	this.facets = new LinkedHashMap<String, List<String[]>>();
199
    	for (int i=0; i<toshowfacetDefIDs.length; i++) {
-
 
200
    		String facetDefID = toshowfacetDefIDs[i];
186
    	List<String> filtrableFacets = search.getFilterableFacets();
201
    		String facetLabel = toshowfacetLabels[i];
187
    	for (String filtrableFacet : filtrableFacets) {
202
    		
188
    		
203
    		Map<String, Integer> facetDetailMap = search.getFacetDetails(facetDefID);
189
    		Map<String, Integer> facetDetailMap = search.getFacetDetails(filtrableFacet);
204
    		if(facetDetailMap==null)
190
    		if(facetDetailMap==null)
205
    			continue;
191
    			continue;
206
    		List<String[]> values = new ArrayList<String[]>();
192
    		List<String[]> values = new ArrayList<String[]>();
207
    		for(Entry<String, Integer> facetEntry : facetDetailMap.entrySet()){
193
    		for(Entry<String, Integer> facetEntry : facetDetailMap.entrySet()){
208
    			String selected = "";
194
    			String selected = "";
209
    			if(fqs.contains(facetDefID + ":" + facetEntry.getKey())) {
195
    			if(fqs.contains(filtrableFacet + ":" + facetEntry.getKey())) {
210
    				selected = "checked=\"checked\"";
196
    				selected = "checked=\"checked\"";
211
    			}
197
    			}
212
    		    String facet = facetEntry.getKey();
198
    		    String facet = facetEntry.getKey();
213
      			String drilldownURL = "&fq=" +  
199
      			String drilldownURL = "&fq=" +  
214
    				URLEncoder.encode( facetDefID + ":" + facet, "UTF-8"); 
200
    				URLEncoder.encode( filtrableFacet + ":" + facet, "UTF-8"); 
215
      			String[] afacet = new String[] { facet, 
201
      			String[] afacet = new String[] { facet, 
216
      			      facetEntry.getValue().toString(), drilldownURL,  selected};
202
      			      facetEntry.getValue().toString(), drilldownURL,  selected};
217
      			values.add(afacet);    
203
      			values.add(afacet);    
218
    		}
204
    		}
219
    		
205
    		
220
    		this.facets.put(facetLabel, values);
206
    		this.facets.put(Utils.FACET_LABEL_MAP.get(filtrableFacet), values);
221
    	}
207
    	}
222
	}
208
	}
223
 
209
 
224
 
210
 
225
	public Map<String, String> getSnippets() throws Exception {
211
	public Map<String, String> getSnippets() throws Exception {
Line 334... Line 320...
334
    	}
320
    	}
335
    	
321
    	
336
    	return categoriesChildren;
322
    	return categoriesChildren;
337
    }
323
    }
338
    
324
    
-
 
325
    public static String getCategoryLabel(Long id){
-
 
326
    	if(categoryLabelMap == null){
-
 
327
    		Map<Long,String> idLabelMap = new HashMap<Long, String>(); 
-
 
328
    		for (Category category: CategoryManager.getCategoryManager().getCategories().values()){
-
 
329
    			idLabelMap.put(category.getId(), category.getLabel());
-
 
330
    		}
-
 
331
    		categoryLabelMap = idLabelMap;
-
 
332
    	} 
-
 
333
    	return categoryLabelMap.get(id);
-
 
334
    }
-
 
335
    
339
	public String getDynamicSearchMap(){
336
	public String getDynamicSearchMap(){
340
    	if (this.dynamicSearchMap == null) {
337
    	if (this.dynamicSearchMap == null) {
341
    		return "{}";
338
    		return "{}";
342
    	} else {
339
    	} else {
343
    		return new Gson().toJson(this.dynamicSearchMap);
340
    		return new Gson().toJson(this.dynamicSearchMap);