Subversion Repositories SmartDukaan

Rev

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

Rev 517 Rev 536
Line 4... Line 4...
4
package in.shop2020.serving.controllers;
4
package in.shop2020.serving.controllers;
5
 
5
 
6
import in.shop2020.model.v1.widgets.WidgetService.Client;
6
import in.shop2020.model.v1.widgets.WidgetService.Client;
7
import in.shop2020.serving.pages.PageContentKeys;
7
import in.shop2020.serving.pages.PageContentKeys;
8
import in.shop2020.serving.pages.PageEnum;
8
import in.shop2020.serving.pages.PageEnum;
-
 
9
import in.shop2020.serving.services.CategoryManager;
9
import in.shop2020.serving.services.PageLoaderHandler;
10
import in.shop2020.serving.services.PageLoaderHandler;
10
import in.shop2020.serving.services.SolrSearchService;
11
import in.shop2020.serving.services.SolrSearchService;
11
import in.shop2020.serving.utils.FileUtils;
12
import in.shop2020.serving.utils.FileUtils;
12
import in.shop2020.thrift.clients.WidgetServiceClient;
13
import in.shop2020.thrift.clients.WidgetServiceClient;
13
import in.shop2020.util.Utils;
14
import in.shop2020.util.Utils;
Line 19... Line 20...
19
import java.util.Arrays;
20
import java.util.Arrays;
20
import java.util.HashMap;
21
import java.util.HashMap;
21
import java.util.LinkedHashMap;
22
import java.util.LinkedHashMap;
22
import java.util.List;
23
import java.util.List;
23
import java.util.Map;
24
import java.util.Map;
-
 
25
import java.util.StringTokenizer;
24
 
26
 
25
import org.apache.commons.lang.StringUtils;
27
import org.apache.commons.lang.StringUtils;
26
import org.apache.juli.logging.Log;
28
import org.apache.juli.logging.Log;
27
import org.apache.juli.logging.LogFactory;
29
import org.apache.juli.logging.LogFactory;
28
import org.apache.struts2.rest.DefaultHttpHeaders;
30
import org.apache.struts2.rest.DefaultHttpHeaders;
Line 49... Line 51...
49
	/**
51
	/**
50
	 * 
52
	 * 
51
	 */
53
	 */
52
	private String id;
54
	private String id;
53
	
55
	
-
 
56
	private String categoryName;
-
 
57
	
54
	private String query;
58
	private String query;
55
	
59
	
56
	private Double minPrice;
60
	private Double minPrice;
57
	private Double maxPrice;
61
	private Double maxPrice;
58
	
62
	
Line 60... Line 64...
60
	 * GET /category/10004
64
	 * GET /category/10004
61
	 * 
65
	 * 
62
	 */
66
	 */
63
    public HttpHeaders show() throws SecurityException, IOException {
67
    public HttpHeaders show() throws SecurityException, IOException {
64
    	log.info("id=" + id);
68
    	log.info("id=" + id);
-
 
69
    	this.categoryName = CategoryManager.getCategoryManager().getCategoryLabel(Long.parseLong(id));
-
 
70
    	
-
 
71
    	
65
    	htmlSnippets = new HashMap<String, String>();
72
    	htmlSnippets = new HashMap<String, String>();
66
    	PageLoaderHandler pageLoader = new PageLoaderHandler();
73
    	PageLoaderHandler pageLoader = new PageLoaderHandler();
67
		
74
		
68
		htmlSnippets.put("HEADER", pageLoader.getHeaderHtml(userinfo.getUserId(), userinfo.isSessionId(), userinfo.getNameOfUser()));
75
		htmlSnippets.put("HEADER", pageLoader.getHeaderHtml(userinfo.getUserId(), userinfo.isSessionId(), userinfo.getNameOfUser()));
69
		htmlSnippets.put("MAIN_MENU", pageLoader.getMainMenuHtml());
76
		htmlSnippets.put("MAIN_MENU", pageLoader.getMainMenuHtml());
Line 83... Line 90...
83
		String[] facetDefIDs = new String[] {"Category","F_50002","F_50001",  "F_50006", "F_50007" };
90
		String[] facetDefIDs = new String[] {"Category","F_50002","F_50001",  "F_50006", "F_50007" };
84
    	
91
    	
85
    	String[] facetLabels = new String[] {"Category","Price", "Brand", "Data Connectivity", "Camera Resolution" 	};
92
    	String[] facetLabels = new String[] {"Category","Price", "Brand", "Data Connectivity", "Camera Resolution" 	};
86
 
93
 
87
    	String[] fqrys = this.request.getParameterValues("fq");
94
    	String[] fqrys = this.request.getParameterValues("fq");
-
 
95
    	
88
    	query = "*";
96
    	query = "*";
89
    	
97
    	
-
 
98
    	int length = 1;
-
 
99
    	
-
 
100
    	if(fqrys!= null){
-
 
101
    		length += fqrys.length;
-
 
102
    	}
-
 
103
    	
-
 
104
    	String[] newfqrys = new String[length];
-
 
105
    	newfqrys[0] = "F_50001:"+categoryName;
-
 
106
    	
-
 
107
    	for(int i=1; i<length; i++) {
-
 
108
    		newfqrys[i] = fqrys[i-1];
-
 
109
    	}
-
 
110
    	
-
 
111
    	
90
    	SolrSearchService search = new SolrSearchService(query, fqrys, facetDefIDs);
112
    	SolrSearchService search = new SolrSearchService(query, newfqrys, facetDefIDs);
91
    	this.results = new LinkedHashMap<String, String[]>();
113
    	this.results = new LinkedHashMap<String, String[]>();
92
    	this.results =  search.getResultMap(); 
114
    	this.results =  search.getResultMap(); 
93
 
115
 
94
    	
116
    	
95
    	
117
    	
Line 104... Line 126...
104
    		HashMap<String, Integer> facetDetailMap = search.getFacetDetails(facetDefID);
126
    		HashMap<String, Integer> facetDetailMap = search.getFacetDetails(facetDefID);
105
    		if(facetDetailMap==null)
127
    		if(facetDetailMap==null)
106
    			continue;
128
    			continue;
107
    		List<String[]> values = new ArrayList<String[]>();
129
    		List<String[]> values = new ArrayList<String[]>();
108
    		for(String facet: facetDetailMap.keySet()){
130
    		for(String facet: facetDetailMap.keySet()){
-
 
131
    			String drilldownURL = new String();
-
 
132
    			
-
 
133
    			if(qryString != null){
-
 
134
    				drilldownURL = qryString;
-
 
135
    			}
-
 
136
    			
109
      			String drilldownURL = "fq=" + facetDefID + ":" + 
137
    			drilldownURL = "fq=" + facetDefID + ":" + 
110
    				URLEncoder.encode(facet, "UTF-8"); 
138
    				URLEncoder.encode(facet, "UTF-8"); 
111
      			String[] afacet = new String[] { facet, 
139
      			String[] afacet = new String[] { facet, 
112
      					facetDetailMap.get(facet).toString(), drilldownURL  };
140
      					facetDetailMap.get(facet).toString(), drilldownURL  };
113
      			values.add(afacet);    
141
      			values.add(afacet);    
114
      		  
142
      		  
Line 133... Line 161...
133
    /**
161
    /**
134
     * 
162
     * 
135
     * @param id
163
     * @param id
136
     */
164
     */
137
    public void setId(String id) {
165
    public void setId(String id) {
-
 
166
    	StringTokenizer tokenizer = new StringTokenizer(id,"-");
-
 
167
    	while(tokenizer.hasMoreTokens()){
138
        this.id = id;
168
    		this.id = tokenizer.nextToken();
-
 
169
    	}
139
    }
170
    }
140
    
171
    
141
    /**
172
    /**
142
     * 
173
     * 
143
     */
174
     */
144
    public String getId() {
175
    public String getId() {
145
    	return this.id;
176
    	return this.id;
146
    }
177
    }
147
    
178
    
-
 
179
    public String getCategoryName() {
-
 
180
    	return this.categoryName;
-
 
181
    }
-
 
182
    
-
 
183
    
148
    public String getHeaderSnippet(){
184
    public String getHeaderSnippet(){
149
		return htmlSnippets.get("HEADER");
185
		return htmlSnippets.get("HEADER");
150
	}
186
	}
151
	
187
	
152
	public String getMainMenuSnippet(){
188
	public String getMainMenuSnippet(){
Line 220... Line 256...
220
    
256
    
221
    public Map<String, String> getSnippets() throws Exception {
257
    public Map<String, String> getSnippets() throws Exception {
222
    	if(results != null){
258
    	if(results != null){
223
    		snippets = new HashMap<String, String>();	
259
    		snippets = new HashMap<String, String>();	
224
	    	for(String docId: results.keySet()){
260
	    	for(String docId: results.keySet()){
225
				snippets.put(docId, FileUtils.read( Utils.EXPORT_ENTITIES_PATH + docId + File.separator +"SearchSnippet.html"));
261
				snippets.put(docId, FileUtils.read( Utils.EXPORT_ENTITIES_PATH + docId + File.separator +"CategorySnippet.html"));
226
			}
262
			}
227
    	}
263
    	}
228
		return snippets;
264
		return snippets;
229
    }
265
    }
230
 
266