Subversion Repositories SmartDukaan

Rev

Rev 1720 | Rev 1733 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1720 varun.gupt 1
package in.shop2020.social.controllers;
2
 
3
import in.shop2020.social.services.SolrSearchService;
4
import in.shop2020.social.utils.FileUtils;
5
import in.shop2020.social.utils.Utils;
6
 
7
import java.io.File;
8
import java.io.UnsupportedEncodingException;
9
import java.net.URLEncoder;
10
import java.util.ArrayList;
11
import java.util.Arrays;
12
import java.util.HashMap;
13
import java.util.LinkedHashMap;
14
import java.util.List;
15
import java.util.Map;
16
 
17
import javax.servlet.http.HttpServletRequest;
18
import javax.servlet.http.HttpServletResponse;
19
 
20
import org.apache.struts2.interceptor.ServletRequestAware;
21
import org.apache.struts2.interceptor.ServletResponseAware;
22
 
23
import org.apache.struts2.convention.annotation.Result;
24
 
25
/**
26
 * @author Varun Gupta
27
 */
28
 
29
public class MyPhonesController implements ServletRequestAware, ServletResponseAware{
30
 
31
	protected HttpServletResponse response;
32
	protected HttpServletRequest request;
33
 
34
	private static final long serialVersionUID = -8392433517042806559L;
35
 
36
	private List<String> results = null;
37
 
38
	private Map<String, String> snippets;
39
 
40
	private String sortOrder = null;
41
	private Double minPrice = null;
42
	private Double maxPrice = null;
43
 
44
	private long windowSize = 10;
45
	private long page = 1;
46
	private long totalResults = 0;
47
	private long categoryId = 10000;
48
 
49
	public MyPhonesController(){
50
		snippets = new HashMap<String, String>();
51
	}
52
 
53
	// GET /Show Form
54
	public String index() {
1726 varun.gupt 55
		return "index";
56
	}
57
 
58
	public String create()	{
1720 varun.gupt 59
		if(this.request.getParameter("q") != null && ! this.request.getParameter("q").trim().isEmpty())	{
60
			String query = this.request.getParameter("q");	//"F_50010:Mobile+Phones"
61
			String[] fqrys = new String[]	{"F_50010:Mobile Phones"};
62
	    	String[] facetDefIDs = new String[]{}; //new String[] {"F_50010"};
63
 
64
			SolrSearchService search = new SolrSearchService(query, fqrys, facetDefIDs, (page - 1) * windowSize, windowSize, minPrice, maxPrice, categoryId, sortOrder);
65
			this.totalResults = search.getTotalResults();
66
			this.results = search.getResultMap();
67
		}
68
		return "index";
69
	}
70
 
71
    public List<String> getResults()	{
72
    	return this.results;
73
    }
74
 
75
    public long getResultCount()	{
76
    	return this.totalResults;
77
    }
78
 
79
    public Map<String, String> getSnippets() throws Exception {
80
    	if(results != null)	{
81
    		snippets = new HashMap<String, String>();
82
//    		snippets.put("1000468", FileUtils.read("/home/varungupta/snippets/SearchSnippet1.html"));
83
//    		snippets.put("1000534", FileUtils.read("/home/varungupta/snippets/SearchSnippet2.html"));
84
//    		snippets.put("1001211", FileUtils.read("/home/varungupta/snippets/SearchSnippet3.html"));
85
//    		snippets.put("1001223", FileUtils.read("/home/varungupta/snippets/SearchSnippet4.html"));
86
 
87
    		for(String docId: results){
88
	    		String html = FileUtils.read(Utils.EXPORT_ENTITIES_PATH + docId + File.separator + "PhonesIOwnSnippet.html");
89
	    		System.out.println(Utils.EXPORT_ENTITIES_PATH + docId + File.separator + "PhonesIOwnSnippet.html");
90
				snippets.put(docId, html);
91
			}
92
    	}
93
		return snippets;
94
    }
95
	@Override
96
	public void setServletResponse(HttpServletResponse response) {
97
		this.response = response;
98
	}
99
 
100
	@Override
101
	public void setServletRequest(HttpServletRequest request) {
102
		this.request = request;
103
	}
104
}