Subversion Repositories SmartDukaan

Rev

Rev 3561 | Rev 5873 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3561 Rev 5729
Line 7... Line 7...
7
import in.shop2020.config.ConfigException;
7
import in.shop2020.config.ConfigException;
8
import in.shop2020.thrift.clients.config.ConfigClient;
8
import in.shop2020.thrift.clients.config.ConfigClient;
9
import in.shop2020.utils.CategoryManager;
9
import in.shop2020.utils.CategoryManager;
10
 
10
 
11
import java.util.Arrays;
11
import java.util.Arrays;
-
 
12
import java.util.Collections;
12
import java.util.HashMap;
13
import java.util.HashMap;
-
 
14
import java.util.Iterator;
-
 
15
import java.util.LinkedHashMap;
13
import java.util.LinkedList;
16
import java.util.LinkedList;
14
import java.util.List;
17
import java.util.List;
-
 
18
import java.util.Map;
15
import java.util.TreeMap;
19
import java.util.TreeMap;
16
 
20
 
17
 
21
 
18
import javax.xml.xpath.XPath;
22
import javax.xml.xpath.XPath;
19
import javax.xml.xpath.XPathConstants;
23
import javax.xml.xpath.XPathConstants;
Line 39... Line 43...
39
	/**
43
	/**
40
	 * 
44
	 * 
41
	 */
45
	 */
42
	public static final String SOLR_URL;
46
	public static final String SOLR_URL;
43
	
47
	
-
 
48
	private static final Map<String, List<String>> SORTED_FACET_VALUE_MAP = Collections.unmodifiableMap(
-
 
49
			new HashMap<String, List<String>>(){
-
 
50
				/**
-
 
51
				 * 
-
 
52
				 */
-
 
53
				private static final long serialVersionUID = 1L;
-
 
54
 
-
 
55
				{
-
 
56
					put("F_50007", Arrays.asList("Upto 2 Mpx", "2 - 5 Mpx", "5 - 10 Mpx", "Above 10 Mpx"));
-
 
57
				}
-
 
58
		});
44
	static {
59
	static {
45
		String solr_url = null;
60
		String solr_url = null;
46
		try {
61
		try {
47
			solr_url = ConfigClient.getClient().get("solr_url");
62
			solr_url = ConfigClient.getClient().get("solr_url");
48
		}catch(ConfigException cex){
63
		}catch(ConfigException cex){
Line 60... Line 75...
60
	/**
75
	/**
61
	 * 
76
	 * 
62
	 */
77
	 */
63
	private InputSource inputSource;
78
	private InputSource inputSource;
64
	
79
	
65
	TreeMap<String,HashMap<String,Integer>> facetMap;
80
	Map<String,Map<String,Integer>> facetMap;
66
	
81
	
67
	List<String> resultMap;
82
	List<String> resultMap;
68
	
83
	
69
	long numberOfResults=0;
84
	long numberOfResults=0;
70
	
85
	
Line 134... Line 149...
134
		this.inputSource = new InputSource(uri);
149
		this.inputSource = new InputSource(uri);
135
 
150
 
136
		this.facetMap = getFacetMap();
151
		this.facetMap = getFacetMap();
137
	}
152
	}
138
 
153
 
139
	public TreeMap<String,HashMap<String,Integer>> removeUnwantedFacets(TreeMap<String,HashMap<String,Integer>> facetMap, long numberOfResults){
154
	public Map<String,Map<String,Integer>> removeUnwantedFacets(Map<String,Map<String,Integer>> facetMap, long numberOfResults){
140
		TreeMap<String,HashMap<String,Integer>> tempFacets = new TreeMap<String, HashMap<String,Integer>>(); 
155
		Map<String,Map<String,Integer>> tempFacets = new TreeMap<String, Map<String,Integer>>(); 
141
		for(String facet : facetMap.keySet()){
156
		for(String facet : facetMap.keySet()){
142
			if(facetMap.get(facet).size() > 1){
157
			if(facetMap.get(facet).size() > 1){
143
				HashMap<String,Integer> tempMap = new HashMap<String, Integer>();
158
				Map<String,Integer> tempMap = new LinkedHashMap<String, Integer>();
144
				
159
				
145
				for(String facetValueName : facetMap.get(facet).keySet()){
160
				for(String facetValueName : facetMap.get(facet).keySet()){
146
					if(facetMap.get(facet).get(facetValueName) != 0 && facetMap.get(facet).get(facetValueName) != numberOfResults){
161
					if(facetMap.get(facet).get(facetValueName) != 0 && facetMap.get(facet).get(facetValueName) != numberOfResults){
147
						tempMap.put(facetValueName, facetMap.get(facet).get(facetValueName));
162
						tempMap.put(facetValueName, facetMap.get(facet).get(facetValueName));
148
					}
163
					}
Line 157... Line 172...
157
		}
172
		}
158
 
173
 
159
		return tempFacets;
174
		return tempFacets;
160
	}
175
	}
161
	
176
	
162
	public HashMap<String,Integer> getFacetDetails(String facetName){
177
	public Map<String,Integer> getFacetDetails(String facetName){
163
		if(facetMap != null){
178
		if(facetMap != null){
164
			return facetMap.get(facetName);
179
			return facetMap.get(facetName);
165
		}else{
180
		}else{
166
			return null;
181
			return null;
167
		}
182
		}
168
	}
183
	}
169
	
184
	
170
	public TreeMap<String,HashMap<String,Integer>> getFacetMap() {
185
	public Map<String,Map<String,Integer>> getFacetMap() {
171
		facetMap = new TreeMap<String,HashMap<String,Integer>>();
186
		facetMap = new TreeMap<String,Map<String,Integer>>();
172
		
187
		
173
		String facetNamePath = "/response/lst/lst[@name = 'facet_fields']/lst";
188
		String facetNamePath = "/response/lst/lst[@name = 'facet_fields']/lst";
174
		
189
		
175
		NodeList nodes = null;
190
		NodeList nodes = null;
176
		try {
191
		try {
Line 188... Line 203...
188
		
203
		
189
		for(int i=0; i<nodes.getLength(); i++) {
204
		for(int i=0; i<nodes.getLength(); i++) {
190
			Node node = nodes.item(i);
205
			Node node = nodes.item(i);
191
			String facetName = node.getAttributes().getNamedItem("name").getNodeValue();
206
			String facetName = node.getAttributes().getNamedItem("name").getNodeValue();
192
			subNodes = node.getChildNodes();
207
			subNodes = node.getChildNodes();
193
			HashMap<String,Integer> facetValueCountMap = new HashMap<String,Integer>();
208
			Map<String,Integer> facetValueCountMap = new LinkedHashMap<String,Integer>();
194
			for(int j=0; j<subNodes.getLength(); j++) {
209
			for(int j=0; j<subNodes.getLength(); j++) {
195
				Node subNode = subNodes.item(j);
210
				Node subNode = subNodes.item(j);
196
				if(Integer.parseInt(subNode.getTextContent())==0)
211
				if(Integer.parseInt(subNode.getTextContent())==0)
197
						continue;
212
						continue;
198
				facetValueCountMap.put(subNode.getAttributes().getNamedItem("name").getNodeValue(), Integer.parseInt(subNode.getTextContent()));
213
				facetValueCountMap.put(subNode.getAttributes().getNamedItem("name").getNodeValue(), Integer.parseInt(subNode.getTextContent()));
199
			}
214
			}
-
 
215
			if(SORTED_FACET_VALUE_MAP.containsKey(facetName)){
-
 
216
				List<String> orderedValues = SORTED_FACET_VALUE_MAP.get(facetName);
-
 
217
				Map<String, Integer> sortedMap = new LinkedHashMap<String, Integer>();
-
 
218
			    for (Iterator<String> it = orderedValues.iterator(); it.hasNext();) {
-
 
219
			    	String val = it.next();
-
 
220
			        if(facetValueCountMap.containsKey(val)) {
-
 
221
			        	sortedMap.put(val, facetValueCountMap.get(val));
-
 
222
			        }
-
 
223
			    }
-
 
224
			    facetMap.put(facetName, sortedMap);
-
 
225
			} else {
200
			facetMap.put(facetName, facetValueCountMap);
226
				facetMap.put(facetName, facetValueCountMap);
201
			}
227
			}
-
 
228
		}
202
		this.numberOfResults  = this.getTotalResults();
229
		this.numberOfResults  = this.getTotalResults();
203
		
230
		
204
		facetMap = removeUnwantedFacets(facetMap, numberOfResults);
231
		facetMap = removeUnwantedFacets(facetMap, numberOfResults);
205
		return facetMap;
232
		return facetMap;
206
		}
233
	}
207
	
234
	
208
	public List<String> getResultMap() {
235
	public List<String> getResultMap() {
209
		resultMap = new LinkedList<String>();
236
		resultMap = new LinkedList<String>();
210
 
237
 
211
		String resultDocsPath = "/response/result/doc";
238
		String resultDocsPath = "/response/result/doc";