Subversion Repositories SmartDukaan

Rev

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

Rev 790 Rev 820
Line 17... Line 17...
17
import java.util.Map;
17
import java.util.Map;
18
 
18
 
19
import org.apache.commons.lang.StringUtils;
19
import org.apache.commons.lang.StringUtils;
20
import org.apache.juli.logging.Log;
20
import org.apache.juli.logging.Log;
21
import org.apache.juli.logging.LogFactory;
21
import org.apache.juli.logging.LogFactory;
-
 
22
import org.apache.struts2.convention.annotation.Result;
-
 
23
import org.apache.struts2.convention.annotation.Results;
22
import org.apache.struts2.rest.DefaultHttpHeaders;
24
import org.apache.struts2.rest.DefaultHttpHeaders;
23
import org.apache.struts2.rest.HttpHeaders;
25
import org.apache.struts2.rest.HttpHeaders;
24
 
26
 
25
/**
27
/**
26
 * @author rajveer
28
 * @author rajveer
27
 *
29
 *
28
 */
30
 */
-
 
31
@Result(name="redirect", location="${location}", type="redirect")
29
public class SearchController extends BaseController {
32
public class SearchController extends BaseController {
30
 
33
 
31
	/**
34
	/**
32
	 * 
35
	 * 
33
	 */
36
	 */
Line 61... Line 64...
61
	private long beginIndex = 0;
64
	private long beginIndex = 0;
62
	private String url;
65
	private String url;
63
	private String priceUrl;
66
	private String priceUrl;
64
	private long categoryId=10000;
67
	private long categoryId=10000;
65
	private String sortUrl;
68
	private String sortUrl;
-
 
69
	private String location;
66
	/**
70
	/**
67
	 * 
71
	 * 
68
	 * @return
72
	 * @return
69
	 * @throws UnsupportedEncodingException
73
	 * @throws UnsupportedEncodingException
70
	 */
74
	 */
71
    // GET /query
75
    // GET /query
-
 
76
 
72
    public HttpHeaders index() throws UnsupportedEncodingException {
77
    public String index() throws UnsupportedEncodingException {
73
    	
78
    	
74
    	log.info("this.request=" + this.request);
79
    	log.info("this.request=" + this.request);
75
    	
80
    	
76
    	//url = this.request.getRequestURL();
81
    	//url = this.request.getRequestURL();
77
		query = this.request.getParameter("q");
82
		query = this.request.getParameter("q");
Line 80... Line 85...
80
 
85
 
81
		if(this.request.getParameter("category") != null){
86
		if(this.request.getParameter("category") != null){
82
    		this.categoryId = Long.parseLong(this.request.getParameter("category"));
87
    		this.categoryId = Long.parseLong(this.request.getParameter("category"));
83
    		url= url + "&category=" + this.request.getParameter("category");
88
    		url= url + "&category=" + this.request.getParameter("category");
84
    	}
89
    	}
-
 
90
		if(query.trim().isEmpty()){
-
 
91
			if(categoryId != 10000){
-
 
92
				location = "/category/" + categoryId;
-
 
93
				return "redirect";
-
 
94
			}else{
-
 
95
				return "index";
-
 
96
			}
-
 
97
		}
85
		sortUrl = url;
98
		sortUrl = url;
86
		if(this.request.getParameter("sort") != null){
99
		if(this.request.getParameter("sort") != null){
87
    		url= url + "&sort=" + this.request.getParameter("sort");
100
    		url= url + "&sort=" + this.request.getParameter("sort");
88
    		sortOrder = this.request.getParameter("sort");
101
    		sortOrder = this.request.getParameter("sort");
89
    	}
102
    	}
Line 182... Line 195...
182
    		this.minPrice = 0.0;
195
    		this.minPrice = 0.0;
183
    		this.maxPrice = 0.0;
196
    		this.maxPrice = 0.0;
184
    	}
197
    	}
185
    	
198
    	
186
    	this.totalResults = search.getTotalResults();
199
    	this.totalResults = search.getTotalResults();
187
    	return new DefaultHttpHeaders("index")
200
    	return "index";
188
            .disableCaching();
-
 
189
    }
201
    }
190
 
202
 
191
 
203
 
192
    public Map<String, String> getSnippets() throws Exception {
204
    public Map<String, String> getSnippets() throws Exception {
193
    	if(results != null){
205
    	if(results != null){
Line 267... Line 279...
267
    }
279
    }
268
 
280
 
269
    public String getSortOrder(){
281
    public String getSortOrder(){
270
    	return this.sortOrder;
282
    	return this.sortOrder;
271
    }
283
    }
-
 
284
    
-
 
285
    public String getLocation(){
-
 
286
    	return this.location;
-
 
287
    }
272
}
288
}