Subversion Repositories SmartDukaan

Rev

Rev 1726 | Go to most recent revision | Details | 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() {
55
 
56
		if(this.request.getParameter("q") != null && ! this.request.getParameter("q").trim().isEmpty())	{
57
			String query = this.request.getParameter("q");	//"F_50010:Mobile+Phones"
58
			String[] fqrys = new String[]	{"F_50010:Mobile Phones"};
59
	    	String[] facetDefIDs = new String[]{}; //new String[] {"F_50010"};
60
 
61
			SolrSearchService search = new SolrSearchService(query, fqrys, facetDefIDs, (page - 1) * windowSize, windowSize, minPrice, maxPrice, categoryId, sortOrder);
62
			this.totalResults = search.getTotalResults();
63
			this.results = search.getResultMap();
64
		}
65
		return "index";
66
	}
67
 
68
    public List<String> getResults()	{
69
    	return this.results;
70
    }
71
 
72
    public long getResultCount()	{
73
    	return this.totalResults;
74
    }
75
 
76
    public Map<String, String> getSnippets() throws Exception {
77
    	if(results != null)	{
78
    		snippets = new HashMap<String, String>();
79
//    		snippets.put("1000468", FileUtils.read("/home/varungupta/snippets/SearchSnippet1.html"));
80
//    		snippets.put("1000534", FileUtils.read("/home/varungupta/snippets/SearchSnippet2.html"));
81
//    		snippets.put("1001211", FileUtils.read("/home/varungupta/snippets/SearchSnippet3.html"));
82
//    		snippets.put("1001223", FileUtils.read("/home/varungupta/snippets/SearchSnippet4.html"));
83
 
84
    		for(String docId: results){
85
	    		String html = FileUtils.read(Utils.EXPORT_ENTITIES_PATH + docId + File.separator + "PhonesIOwnSnippet.html");
86
	    		System.out.println(Utils.EXPORT_ENTITIES_PATH + docId + File.separator + "PhonesIOwnSnippet.html");
87
				snippets.put(docId, html);
88
			}
89
    	}
90
		return snippets;
91
    }
92
	@Override
93
	public void setServletResponse(HttpServletResponse response) {
94
		this.response = response;
95
	}
96
 
97
	@Override
98
	public void setServletRequest(HttpServletRequest request) {
99
		this.request = request;
100
	}
101
}