Subversion Repositories SmartDukaan

Rev

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

Rev 339 Rev 354
Line 7... Line 7...
7
 
7
 
8
import java.io.UnsupportedEncodingException;
8
import java.io.UnsupportedEncodingException;
9
import java.net.URLEncoder;
9
import java.net.URLEncoder;
10
import java.util.ArrayList;
10
import java.util.ArrayList;
11
import java.util.Arrays;
11
import java.util.Arrays;
-
 
12
import java.util.HashMap;
12
import java.util.LinkedHashMap;
13
import java.util.LinkedHashMap;
13
import java.util.List;
14
import java.util.List;
14
import java.util.Map;
15
import java.util.Map;
15
 
16
 
16
import javax.servlet.http.HttpServletRequest;
17
import javax.servlet.http.HttpServletRequest;
Line 52... Line 53...
52
	/**
53
	/**
53
	 * 
54
	 * 
54
	 */
55
	 */
55
	private List<String[]> crumbs;
56
	private List<String[]> crumbs;
56
	
57
	
-
 
58
	private Double minPrice;
-
 
59
	private Double maxPrice;
-
 
60
 
57
	/**
61
	/**
58
	 * 
62
	 * 
59
	 * @return
63
	 * @return
60
	 * @throws UnsupportedEncodingException
64
	 * @throws UnsupportedEncodingException
61
	 */
65
	 */
Line 76... Line 80...
76
	    	strCrumb = qry;
80
	    	strCrumb = qry;
77
	    	urlCrumb = "q=" + URLEncoder.encode(qry, "UTF-8"); 
81
	    	urlCrumb = "q=" + URLEncoder.encode(qry, "UTF-8"); 
78
	    	this.crumbs.add(new String[] { strCrumb, urlCrumb } );
82
	    	this.crumbs.add(new String[] { strCrumb, urlCrumb } );
79
			log.info("acrumb=" + 
83
			log.info("acrumb=" + 
80
					Arrays.toString(new String[] { strCrumb, urlCrumb }));
84
					Arrays.toString(new String[] { strCrumb, urlCrumb }));
-
 
85
    	}else {
-
 
86
    		/**
-
 
87
    		 * FIXME to handle if qry is null
-
 
88
    		 */
81
    	}
89
    	}
82
    	
90
    	
-
 
91
//    	HashMap<String,String> facetqueries = new HashMap<String, String>();
-
 
92
    	
83
    	if(fqrys != null) {
93
    	if(fqrys != null) {
84
	    	log.info("fqrys=" + Arrays.toString(fqrys));
94
	    	log.info("fqrys=" + Arrays.toString(fqrys));
85
    	
95
    	
86
	    	for(int i=0; i<fqrys.length; i++) {
96
	    	for(int i=0; i<fqrys.length; i++) {
87
	    		String facetValue = StringUtils.split(fqrys[i], ":")[1];
97
	    		String facetValue = StringUtils.split(fqrys[i], ":")[1];
-
 
98
	//    		facetqueries.put(StringUtils.split(fqrys[i], ":")[0], StringUtils.split(fqrys[i], ":")[1]);
88
	    		strCrumb += " " + facetValue;
99
	    		//strCrumb += " " + facetValue;
89
	    		
100
	    		strCrumb =  facetValue;
90
	    		urlCrumb += "&fq=" + URLEncoder.encode(fqrys[i], "UTF-8");
101
	    		urlCrumb += "&fq=" + URLEncoder.encode(fqrys[i], "UTF-8");
91
	    		String[] acrumb = new String[] { strCrumb, urlCrumb };
102
	    		String[] acrumb = new String[] { strCrumb, urlCrumb };
92
	    		log.info("acrumb=" + Arrays.toString(acrumb));
103
	    		log.info("acrumb=" + Arrays.toString(acrumb));
93
	    		
104
	    		
94
	    		this.crumbs.add(acrumb);
105
	    		this.crumbs.add(acrumb);
95
	    	}
106
	    	}
96
    	}
107
    	}
97
    	
108
    	
-
 
109
    	/**
-
 
110
		 * FIXME facte definition ids
-
 
111
		 */
98
    	// Hard coded for now
112
    	// Hard coded for now
99
    	long[] facetDefIDs = new long[] {50001, 50003, 50004, 50005, 50006, 
113
//    	long[] facetDefIDs = new long[] {50001, 50003, 50004, 50005, 50006, 
100
    			50007, 50008, 50009};
114
//    			50007, 50008, 50009};
101
    	
115
    	
-
 
116
    	String[] facetDefIDs = new String[] {"Category","F_50002","F_50001", "F_50003", "F_50004", "F_50005", "F_50006", 
-
 
117
    			"F_50007", "F_50008", "F_50009"};
-
 
118
    	/**
-
 
119
		 * FIXME facet labels
-
 
120
		 */
102
    	// Hard-coded for now
121
    	// Hard-coded for now
103
    	String[] facetLabels = new String[] {
122
    	String[] facetLabels = new String[] {"Category","Price",
104
	    	"Brand", "Form Factor", "Carry In Pocket", "Cellular Technologies", 
123
	    	"Brand", "Form Factor", "Carry In Pocket", "Cellular Technologies", 
105
	    	"Data Connectivity", "Camera Resolution", "Built-in Memory", 
124
	    	"Data Connectivity", "Camera Resolution", "Built-in Memory", 
106
	    	"Talk time"
125
	    	"Talk time"
107
    	};
126
    	};
108
    	
127
    	
109
    	SolrSearchService search = new SolrSearchService(qry, fqrys,
128
    	SolrSearchService search = new SolrSearchService(qry, fqrys, facetDefIDs);
-
 
129
    	this.results = new LinkedHashMap<String, String[]>();
110
    			facetDefIDs);
130
    	this.results =  search.getResultMap(); 
111
    	
131
    	
-
 
132
    /*	
112
    	long[] entityIDs = search.getResultEntityIDs();
133
    	long[] entityIDs = search.getResultEntityIDs();
113
    	log.info("entityIDs=" + Arrays.toString(entityIDs));
134
    	log.info("entityIDs=" + Arrays.toString(entityIDs));
114
    	
135
    	
115
    	String[] entityNames = search.getResultEntityNames();
136
    	String[] entityNames = search.getResultEntityNames();
116
    	log.info("entityNames=" + Arrays.toString(entityNames));
137
    	log.info("entityNames=" + Arrays.toString(entityNames));
Line 124... Line 145...
124
	    		String[] values = new String[] {entityNames[i]};
145
	    		String[] values = new String[] {entityNames[i]};
125
	    		
146
	    		
126
	    		this.results.put(key, values);
147
	    		this.results.put(key, values);
127
	    	}
148
	    	}
128
    	}
149
    	}
-
 
150
    	*/
129
    	//log.info("this.results=" + this.results);
151
    	//log.info("this.results=" + this.results);
130
    	
152
    	
131
    	// Facets
153
    	// Facets
132
    	this.facets = new LinkedHashMap<String, List<String[]>>();
154
    	this.facets = new LinkedHashMap<String, List<String[]>>();
133
    	String qryString = this.request.getQueryString();
155
    	String qryString = this.request.getQueryString();
134
    	log.info("qryString=" + qryString);
156
    	log.info("qryString=" + qryString);
135
    	
157
    	
-
 
158
    	
-
 
159
    	for (int i=0; i<facetDefIDs.length; i++) {
-
 
160
    		String facetDefID = facetDefIDs[i];
-
 
161
    		String facetLabel = facetLabels[i];
-
 
162
    		HashMap<String, Integer> facetDetailMap = search.getFacetDetails(facetDefID);
-
 
163
    		if(facetDetailMap==null)
-
 
164
    			continue;
-
 
165
    		List<String[]> values = new ArrayList<String[]>();
-
 
166
    		for(String facet: facetDetailMap.keySet()){
-
 
167
//    			String extraInfo = "LINK";
-
 
168
//    			if(facetqueries.containsKey(facet)){
-
 
169
//    				extraInfo = "NO_LINK";
-
 
170
//    			}
-
 
171
      			String drilldownURL = qryString;
-
 
172
    			drilldownURL += "&fq=" + facetDefID + ":" + 
-
 
173
    				URLEncoder.encode(facet, "UTF-8"); 
-
 
174
      			String[] afacet = new String[] { facet, 
-
 
175
      					facetDetailMap.get(facet).toString(), drilldownURL  };
-
 
176
      			values.add(afacet);    
-
 
177
      		  
-
 
178
    		}
-
 
179
    		
-
 
180
    		this.facets.put(facetLabel, values);
-
 
181
    	}
-
 
182
    	
-
 
183
    	Map<String, Double> priceMap = search.getPriceStatsMap();
-
 
184
    	this.minPrice = priceMap.get("min");
-
 
185
    	this.maxPrice = priceMap.get("max");
-
 
186
    	/*
136
    	for (int i=0; i<facetDefIDs.length; i++) {
187
    	for (int i=0; i<facetDefIDs.length; i++) {
137
    		long facetDefID = facetDefIDs[i];
188
    		long facetDefID = facetDefIDs[i];
138
    		String facetLabel = facetLabels[i];
189
    		String facetLabel = facetLabels[i];
139
    		//log.info("facetLabel=" + facetLabel);
190
    		//log.info("facetLabel=" + facetLabel);
140
    		
191
    		
141
    		String[] facetValues = search.getFacetValues(facetDefID);
192
    		String[] facetValues = search.getFacetValues(facetDefID);
142
    		String[] facetCounts = search.getFacetCounts(facetDefID);
193
    		String[] facetCounts = search.getFacetCounts(facetDefID);
143
    		
194
    		
-
 
195
    		
144
    		List<String[]> values = new ArrayList<String[]>();
196
    		List<String[]> values = new ArrayList<String[]>();
-
 
197
    	
-
 
198
    		
145
    		for(int j=0; j<facetValues.length; j++) {
199
    		for(int j=0; j<facetValues.length; j++) {
146
    			
200
    			
147
    			if(facetCounts[j].equals("0")) {
201
    			if(facetCounts[j].equals("0")) {
148
    				continue;
202
    				continue;
149
    			}
203
    			}
Line 160... Line 214...
160
    			values.add(afacet);    
214
    			values.add(afacet);    
161
    		}
215
    		}
162
    		//log.info("values=" + values);
216
    		//log.info("values=" + values);
163
    		
217
    		
164
    		this.facets.put(facetLabel, values);
218
    		this.facets.put(facetLabel, values);
-
 
219
    		
165
    	}
220
    	}
166
    	//log.info("this.facets=" + this.facets);
221
    	//log.info("this.facets=" + this.facets);
167
    	
222
    	*/
168
    	
223
    	
169
        return new DefaultHttpHeaders("index")
224
        return new DefaultHttpHeaders("index")
170
            .disableCaching();
225
            .disableCaching();
171
    }
226
    }
172
    
227
    
Line 184... Line 239...
184
     */
239
     */
185
    public Map<String, List<String[]>> getFacets() {
240
    public Map<String, List<String[]>> getFacets() {
186
    	return this.facets;
241
    	return this.facets;
187
    }
242
    }
188
    
243
    
-
 
244
    public Double getMinPrice() {
-
 
245
    	return this.minPrice;
-
 
246
    }
-
 
247
    
-
 
248
    public Double getMaxPrice() {
-
 
249
    	return this.maxPrice;
-
 
250
    }
-
 
251
    
189
    /**
252
    /**
190
     * 
253
     * 
191
     * @return
254
     * @return
192
     */
255
     */
193
    public List<String[]> getCrumbs() {
256
    public List<String[]> getCrumbs() {