Subversion Repositories SmartDukaan

Rev

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