Subversion Repositories SmartDukaan

Rev

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

Rev 354 Rev 517
Line 1... Line 1...
1
/**
1
/**
2
 * 
2
 * 
3
 */
3
 */
4
package in.shop2020.serving.controllers;
4
package in.shop2020.serving.controllers;
5
 
5
 
-
 
6
import in.shop2020.serving.pages.PageContentKeys;
-
 
7
import in.shop2020.serving.pages.PageEnum;
-
 
8
import in.shop2020.serving.pages.PageManager;
-
 
9
import in.shop2020.serving.services.PageLoaderHandler;
6
import in.shop2020.serving.services.SolrSearchService;
10
import in.shop2020.serving.services.SolrSearchService;
-
 
11
import in.shop2020.serving.utils.FileUtils;
-
 
12
import in.shop2020.util.Utils;
7
 
13
 
-
 
14
import java.io.File;
8
import java.io.UnsupportedEncodingException;
15
import java.io.UnsupportedEncodingException;
9
import java.net.URLEncoder;
16
import java.net.URLEncoder;
10
import java.util.ArrayList;
17
import java.util.ArrayList;
11
import java.util.Arrays;
18
import java.util.Arrays;
12
import java.util.HashMap;
19
import java.util.HashMap;
Line 25... Line 32...
25
 
32
 
26
/**
33
/**
27
 * @author naveen
34
 * @author naveen
28
 *
35
 *
29
 */
36
 */
30
public class SearchController extends BaseController 
37
public class SearchController extends BaseController {
31
	implements ServletRequestAware {
-
 
32
 
38
 
33
	/**
39
	/**
34
	 * 
40
	 * 
35
	 */
41
	 */
36
	private static Log log = LogFactory.getLog(SearchController.class);
42
	private static Log log = LogFactory.getLog(SearchController.class);
37
	
43
	
-
 
44
	private Map<String,String> htmlSnippets = new HashMap<String, String>();
38
	/**
45
	/**
39
	 * 
46
	 * 
40
	 */
47
	 */
41
	private HttpServletRequest request;
48
	private Map<String, String[]> results;
42
	
49
 
43
	/**
50
	/**
44
	 * 
51
	 * 
45
	 */
52
	 */
46
	private Map<String, String[]> results;
53
	private Map<String, String> snippets;
47
	
54
	
48
	/**
55
	/**
49
	 * 
56
	 * 
50
	 */
57
	 */
51
	private Map<String, List<String[]>> facets;
58
	private Map<String, List<String[]>> facets;
Line 53... Line 60...
53
	/**
60
	/**
54
	 * 
61
	 * 
55
	 */
62
	 */
56
	private List<String[]> crumbs;
63
	private List<String[]> crumbs;
57
	
64
	
-
 
65
	private String  query;
-
 
66
	
58
	private Double minPrice;
67
	private Double minPrice;
59
	private Double maxPrice;
68
	private Double maxPrice;
60
 
69
 
61
	/**
70
	/**
62
	 * 
71
	 * 
63
	 * @return
72
	 * @return
64
	 * @throws UnsupportedEncodingException
73
	 * @throws UnsupportedEncodingException
65
	 */
74
	 */
66
    // GET /query
75
    // GET /query
67
    public HttpHeaders index() throws UnsupportedEncodingException {
76
    public HttpHeaders index() throws UnsupportedEncodingException {
-
 
77
    	
-
 
78
    	PageLoaderHandler pageLoader = new PageLoaderHandler();
-
 
79
		
-
 
80
		htmlSnippets.put("HEADER", pageLoader.getHeaderHtml(userinfo.getUserId(), userinfo.isSessionId(), userinfo.getNameOfUser()));
-
 
81
		htmlSnippets.put("MAIN_MENU", pageLoader.getMainMenuHtml());
-
 
82
		htmlSnippets.put("SEARCH_BAR", pageLoader.getSearchBarHtml(userinfo.getTotalItems(), 10000));
-
 
83
		htmlSnippets.put("CUSTOMER_SERVICE", pageLoader.getCustomerServiceHtml());
-
 
84
		htmlSnippets.put("MY_RESEARCH", pageLoader.getMyResearchHtml(userinfo.getUserId(), userinfo.isSessionId()));
-
 
85
		htmlSnippets.put("FOOTER",pageLoader.getFooterHtml());
-
 
86
		htmlSnippets.put("FOOTER",pageLoader.getFooterHtml());
-
 
87
		htmlSnippets.put("SEARCH_HEADER","");
-
 
88
		htmlSnippets.put("SEARCH_DETAILS","");
-
 
89
		
68
    	log.info("this.request=" + this.request);
90
    	log.info("this.request=" + this.request);
69
    	
91
    	
70
    	String qry = this.request.getParameter("q");
92
    	query = this.request.getParameter("q");
71
    	log.info("qry=" + qry);
93
    	log.info("query=" + query);
72
    	
94
    	
73
    	String[] fqrys = this.request.getParameterValues("fq");
95
    	String[] fqrys = this.request.getParameterValues("fq");
74
 
96
 
75
    	this.crumbs = new ArrayList<String[]>();
97
    	this.crumbs = new ArrayList<String[]>();
76
    	
98
    	
77
    	String strCrumb = "";
99
    	String strCrumb = "";
78
    	String urlCrumb = "";
100
    	String urlCrumb = "";
79
    	if(qry != null) {
101
    	if(query != null) {
80
	    	strCrumb = qry;
102
	    	strCrumb = query;
81
	    	urlCrumb = "q=" + URLEncoder.encode(qry, "UTF-8"); 
103
	    	urlCrumb = "q=" + URLEncoder.encode(query, "UTF-8"); 
82
	    	this.crumbs.add(new String[] { strCrumb, urlCrumb } );
104
	    	this.crumbs.add(new String[] { strCrumb, urlCrumb } );
83
			log.info("acrumb=" + 
105
			log.info("acrumb=" + 
84
					Arrays.toString(new String[] { strCrumb, urlCrumb }));
106
					Arrays.toString(new String[] { strCrumb, urlCrumb }));
85
    	}else {
107
    	}else {
86
    		/**
108
    		/**
Line 111... Line 133...
111
		 */
133
		 */
112
    	// Hard coded for now
134
    	// Hard coded for now
113
//    	long[] facetDefIDs = new long[] {50001, 50003, 50004, 50005, 50006, 
135
//    	long[] facetDefIDs = new long[] {50001, 50003, 50004, 50005, 50006, 
114
//    			50007, 50008, 50009};
136
//    			50007, 50008, 50009};
115
    	
137
    	
-
 
138
    	String[] facetDefIDs = new String[] {"Category","F_50002","F_50001",  "F_50006", "F_50007" };
-
 
139
    	
-
 
140
    	/* All facets. Removing 5 of them
116
    	String[] facetDefIDs = new String[] {"Category","F_50002","F_50001", "F_50003", "F_50004", "F_50005", "F_50006", 
141
    	String[] facetDefIDs = new String[] {"Category","F_50002","F_50001", "F_50003", "F_50004", "F_50005", "F_50006", 
117
    			"F_50007", "F_50008", "F_50009"};
142
    			"F_50007", "F_50008", "F_50009"};
-
 
143
    	*/		
-
 
144
 
-
 
145
    	
118
    	/**
146
    	/**
119
		 * FIXME facet labels
147
		 * FIXME facet labels
120
		 */
148
		 */
121
    	// Hard-coded for now
149
    	// Hard-coded for now
-
 
150
    	/*
122
    	String[] facetLabels = new String[] {"Category","Price",
151
    	String[] facetLabels = new String[] {"Category","Price",
123
	    	"Brand", "Form Factor", "Carry In Pocket", "Cellular Technologies", 
152
    	    	"Brand", "Form Factor", "Carry In Pocket", "Cellular Technologies", 
124
	    	"Data Connectivity", "Camera Resolution", "Built-in Memory", 
153
    	    	"Data Connectivity", "Camera Resolution", "Built-in Memory", 
125
	    	"Talk time"
154
    	    	"Talk time"
-
 
155
        	};
126
    	};
156
    	*/
127
    	
157
    	
-
 
158
    	String[] facetLabels = new String[] {"Category","Price",
-
 
159
    	    	"Brand", "Data Connectivity", "Camera Resolution"
-
 
160
        	};
-
 
161
    	
128
    	SolrSearchService search = new SolrSearchService(qry, fqrys, facetDefIDs);
162
    	SolrSearchService search = new SolrSearchService(query, fqrys, facetDefIDs);
129
    	this.results = new LinkedHashMap<String, String[]>();
163
    	this.results = new LinkedHashMap<String, String[]>();
130
    	this.results =  search.getResultMap(); 
164
    	this.results =  search.getResultMap(); 
131
    	
165
    	
132
    /*	
166
    /*	
133
    	long[] entityIDs = search.getResultEntityIDs();
167
    	long[] entityIDs = search.getResultEntityIDs();
Line 179... Line 213...
179
    		
213
    		
180
    		this.facets.put(facetLabel, values);
214
    		this.facets.put(facetLabel, values);
181
    	}
215
    	}
182
    	
216
    	
183
    	Map<String, Double> priceMap = search.getPriceStatsMap();
217
    	Map<String, Double> priceMap = search.getPriceStatsMap();
-
 
218
    	if(priceMap != null){
184
    	this.minPrice = priceMap.get("min");
219
    		this.minPrice = priceMap.get("min");
185
    	this.maxPrice = priceMap.get("max");
220
    		this.maxPrice = priceMap.get("max");
-
 
221
    	}else{
-
 
222
    		this.minPrice = 0.0;
-
 
223
    		this.maxPrice = 0.0;
-
 
224
    	}
186
    	/*
225
    	/*
187
    	for (int i=0; i<facetDefIDs.length; i++) {
226
    	for (int i=0; i<facetDefIDs.length; i++) {
188
    		long facetDefID = facetDefIDs[i];
227
    		long facetDefID = facetDefIDs[i];
189
    		String facetLabel = facetLabels[i];
228
    		String facetLabel = facetLabels[i];
190
    		//log.info("facetLabel=" + facetLabel);
229
    		//log.info("facetLabel=" + facetLabel);
Line 219... Line 258...
219
    		
258
    		
220
    	}
259
    	}
221
    	//log.info("this.facets=" + this.facets);
260
    	//log.info("this.facets=" + this.facets);
222
    	*/
261
    	*/
223
    	
262
    	
224
        return new DefaultHttpHeaders("index")
263
    	return new DefaultHttpHeaders("index")
225
            .disableCaching();
264
            .disableCaching();
226
    }
265
    }
-
 
266
 
-
 
267
 
-
 
268
    public Map<String, String> getSnippets() throws Exception {
-
 
269
    	if(results != null){
-
 
270
    		snippets = new HashMap<String, String>();	
-
 
271
	    	for(String docId: results.keySet()){
-
 
272
				snippets.put(docId, FileUtils.read( Utils.EXPORT_ENTITIES_PATH + docId + File.separator +"SearchSnippet.html"));
-
 
273
			}
-
 
274
    	}
-
 
275
		return snippets;
-
 
276
    }
-
 
277
	
-
 
278
    /**
-
 
279
     * 
-
 
280
     * @return
-
 
281
     */
-
 
282
    public String getQuery() {
-
 
283
    	return this.query;
-
 
284
    }
-
 
285
    
227
    
286
    
228
    /**
287
    /**
229
     * 
288
     * 
230
     * @return
289
     * @return
231
     */
290
     */
Line 258... Line 317...
258
    }
317
    }
259
    
318
    
260
    /**
319
    /**
261
     * 
320
     * 
262
     */
321
     */
263
    @Override
322
    
-
 
323
    public String getHeaderSnippet(){
-
 
324
		return htmlSnippets.get("HEADER");
-
 
325
	}
-
 
326
	
-
 
327
	public String getMainMenuSnippet(){
-
 
328
		return htmlSnippets.get("MAIN_MENU");
-
 
329
	}
-
 
330
	
-
 
331
	public String getSearchBarSnippet(){
-
 
332
		return htmlSnippets.get("SEARCH_BAR");
-
 
333
	}
-
 
334
			
264
	public void setServletRequest(HttpServletRequest request) {
335
	public String getCustomerServiceSnippet(){
-
 
336
		return htmlSnippets.get("CUSTOMER_SERVICE");
-
 
337
	}
-
 
338
	
-
 
339
	public String getSearchHeaderSnippet(){
-
 
340
		return htmlSnippets.get("SEARCH_HEADER");
-
 
341
	}
-
 
342
	
-
 
343
	public String getSearchDetailsSnippet(){
-
 
344
		return htmlSnippets.get("SEARCH_DETAILS");
-
 
345
	}
-
 
346
	
-
 
347
	public String getMyResearchSnippet(){
-
 
348
		return htmlSnippets.get("MY_RESEARCH");
-
 
349
	}
-
 
350
				
-
 
351
	public String getFooterSnippet(){
265
		this.request = request;
352
		return htmlSnippets.get("FOOTER");
-
 
353
	}
-
 
354
	
-
 
355
	public String getJsFileSnippet(){
-
 
356
		return htmlSnippets.get("JS_FILES");
-
 
357
	}
-
 
358
	
-
 
359
	public String getCssFileSnippet(){
-
 
360
		return htmlSnippets.get("CSS_FILES");
266
	}
361
	}
267
}
362
}