Subversion Repositories SmartDukaan

Rev

Rev 9406 | Rev 9421 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
9103 anupam.sin 1
/**
2
 * 
3
 */
9269 amit.gupta 4
package in.shop2020.mobileapi.serving.services;
9103 anupam.sin 5
 
6
 
7
import in.shop2020.config.ConfigException;
9269 amit.gupta 8
import in.shop2020.mobileapi.serving.controllers.SearchController;
9
import in.shop2020.mobileapi.serving.utils.Utils;
9103 anupam.sin 10
import in.shop2020.thrift.clients.config.ConfigClient;
11
 
12
import java.io.UnsupportedEncodingException;
13
import java.net.URLEncoder;
14
import java.util.ArrayList;
15
import java.util.Arrays;
16
import java.util.Collections;
17
import java.util.HashMap;
18
import java.util.HashSet;
19
import java.util.Iterator;
20
import java.util.LinkedHashMap;
21
import java.util.LinkedList;
22
import java.util.List;
23
import java.util.Map;
24
import java.util.Set;
25
import java.util.TreeMap;
26
import java.util.regex.Matcher;
27
import java.util.regex.Pattern;
28
 
29
import javax.xml.xpath.XPath;
30
import javax.xml.xpath.XPathConstants;
31
import javax.xml.xpath.XPathExpressionException;
32
import javax.xml.xpath.XPathFactory;
33
 
34
import org.apache.log4j.Logger;
35
import org.w3c.dom.Node;
36
import org.w3c.dom.NodeList;
37
import org.xml.sax.InputSource;
38
 
39
 
40
/**
41
 * @author rajveer
42
 *
43
 */
44
public class SolrSearchService {
45
	/**
46
	 * 
47
	 */
48
	private static Logger log = Logger.getLogger(Class.class);
49
	private HashMap<String, Double> dynamicPriceMap = null;
50
 
51
	/**
52
	 * 
53
	 */
54
	public static final String SOLR_URL;
55
 
56
	private static final Pattern FACET_PATTERN = Pattern.compile("(?=(F_\\d{5}))");
57
 
58
	private static final Map<String, List<String>> SORTED_FACET_VALUE_MAP = Collections.unmodifiableMap(
59
			new HashMap<String, List<String>>(){
60
				/**
61
				 * 
62
				 */
63
				private static final long serialVersionUID = 1L;
64
				{
9406 amit.gupta 65
					put("F_50007", Arrays.asList("Upto 2 Mpx", "2 - 5 Mpx", "5 - 10 Mpx", "Above 10 Mpx"));
66
					put("F_50024", Arrays.asList("Upto 10 Mpx", "10 - 12 Mpx", "12 - 15 Mpx", "15 - 18 Mpx", "Above 18 Mpx"));
67
					put("F_50025", Arrays.asList("Upto 4x", "4 - 6x", "6 - 10x", "10 - 14x", "14 - 18x", "Above 18x"));
68
					put("F_50026", Arrays.asList("Below 2 in.", "2 to 2.9 in.", "3 to 3.9 in.", "Above 4 in."));
69
					put("F_50032", Arrays.asList("Below 3 in.", "3 to 3.9 in.", "4 to 4.9 in.", "Above 5 in."));
70
					put("F_50027", Arrays.asList("Upto 10 Mpx", "10 - 15 Mpx", "15 - 20 Mpx", "Above 20 Mpx"));
9103 anupam.sin 71
				}
72
		});
73
	public static final Map<String, List<String>> CATEGORY_FACET_MAP = Collections.unmodifiableMap(
74
			new HashMap<String, List<String>>(){
75
				/**
76
				 * 
77
				 */
78
				private static final long serialVersionUID = 1L;
79
				//Data Connectivity, Camera Resolution,Operating System,Screen Size
9406 amit.gupta 80
				List<String> mobileFacets = Arrays.asList("F_50038", "F_50006", "F_50007", "F_50031", "F_50032");
9103 anupam.sin 81
				//Camera Resolution,Operating System,Screen Size
9406 amit.gupta 82
				List<String> tabletFacets = Arrays.asList("F_50037","F_50036", "F_50035", "F_50034");
9103 anupam.sin 83
				//Operating System, Processor, Storage, RAM, Screen Size
84
				List<String> laptopFacets = Arrays.asList("F_50013", "F_50014", "F_50015","F_50017", "F_50033");
85
				//Resolution, Optical Zoon, Display Size
86
				List<String> compactCameras = Arrays.asList("F_50024", "F_50025", "F_50026");
87
				//Display Size
88
				List<String> dslrCameras = Arrays.asList("F_50026");
89
				//Capacity, Class
90
				List<String> memoryCards = Arrays.asList("F_50018", "F_50019");
91
				//Capacity
92
				List<String> penDrives = Arrays.asList("F_50020");
93
				//Capacity, Type, Interface
94
				List<String> externalHardDisks = Arrays.asList("F_50021", "F_50022", "F_50023");
95
				{					
96
					put(SearchController.getCategoryLabel(10001l), mobileFacets);
97
					put(SearchController.getCategoryLabel(10006l), mobileFacets);
98
					put(SearchController.getCategoryLabel(10009l), tabletFacets);
99
					put(SearchController.getCategoryLabel(10010l), tabletFacets);
100
					put(SearchController.getCategoryLabel(10013l), memoryCards);
101
					put(SearchController.getCategoryLabel(10017l), penDrives);
102
					put(SearchController.getCategoryLabel(10049l), laptopFacets);
103
					put(SearchController.getCategoryLabel(10050l), laptopFacets);
104
					put(SearchController.getCategoryLabel(10073l), externalHardDisks);
105
					put(SearchController.getCategoryLabel(11002l), compactCameras);
106
					put(SearchController.getCategoryLabel(11003l), dslrCameras);
107
				}
108
			});
109
	static {
110
		String solr_url = null;
111
		try {
112
			solr_url = ConfigClient.getClient().get("solr_url");
113
		}catch(ConfigException cex){
114
		    log.error("Unable to get the solr URL from the config server. Setting the default value.", cex);
115
			solr_url = "http://localhost:8983/solr/select/";
116
		}
117
		SOLR_URL = solr_url;
118
	}
119
 
120
	/**
121
	 * 
122
	 */
123
	private XPath xpath;
124
 
125
	/**
126
	 * 
127
	 */
128
	private InputSource inputSource;
129
 
130
	Map<String,Map<String,Integer>> facetMap;
131
 
132
	private String 	query;
133
 
134
	List<String> resultMap;
135
 
136
	long numberOfResults=0;
137
 
138
	String priceFacetName = "F_50002";
139
 
9406 amit.gupta 140
	List<String> filtrableFacets = new ArrayList<String>(Utils.rootfacetDefIDs);
9103 anupam.sin 141
 
142
	/**
143
	 * 
144
	 * @param query
145
	 * @param facetDefinitionIDs
146
	 */
147
	public SolrSearchService(String query, String[] facetqueries, long start, long rows,  Double minPrice, Double maxPrice, String sortOrder, long sourceId) {
148
 
149
		this.query = query;
150
 
151
		List<String> facetsQueried = new ArrayList<String>();
152
		if(sourceId != -1){
153
			priceFacetName = priceFacetName + "_" + sourceId;
154
		}
155
 
156
		setFilterableFacets(facetqueries);
9406 amit.gupta 157
		this.filtrableFacets.remove(Utils.availabilityFacet);
158
		this.filtrableFacets.add(Utils.availabilityFacet);
9103 anupam.sin 159
 
160
 
161
		this.xpath = XPathFactory.newInstance().newXPath();
162
 
163
		query = query.trim().replaceAll("\\s+", " ");
164
    	log.info("query=" + query);
165
 
166
		String uri = SOLR_URL + "?wt=xml&q=" + this.query;
167
 
168
		uri += "&stats=on&stats.field=" + priceFacetName;
169
 
170
		if(sortOrder != null){
171
			//replace the price facet name, so that it can pick price for the source.
172
			sortOrder = sortOrder.replace("F_50002", priceFacetName);
173
			uri += "&sort=" + sortOrder;
174
		}
175
 
176
		if(facetqueries != null) {
177
			//sorting will guarantee all similar facets together so that we can assume or between all similar items without fail.
178
			Arrays.sort(facetqueries);
179
			String fq="";
180
			for(int i=0; i<facetqueries.length; i++) {
181
				String value = "";
182
				String[] tokens = facetqueries[i].split(":");
183
				try {
184
					value = URLEncoder.encode(tokens[1], "UTF-8");
185
				} catch (UnsupportedEncodingException e) {
186
					// TODO Auto-generated catch block
187
					e.printStackTrace();
188
				}
189
				if(facetsQueried.contains(tokens[0])) {
190
					uri += " OR  " + tokens[0] + ":\"" + value + "\"";
191
 
192
				} else {
193
					fq = "{!tag=dt" + facetsQueried.size() + "}";
194
					facetsQueried.add(tokens[0]);
195
					fq +=  tokens[0] + ":\"" + value + "\"";
196
					uri += "&fq=" + fq;
197
				}
198
			}
199
		}
200
		String minString = "0";
201
		String maxString = "*";  
202
		if(minPrice != null || maxPrice != null){
203
			try {
204
				dynamicPriceMap = getPriceStatsMap(new InputSource(uri)); 
205
			} catch (Exception e){
206
				e.printStackTrace();
207
			}
208
			if(minPrice != null){
209
				minString = minPrice.toString();
210
			}
211
			if(maxPrice != null){
212
				maxString = maxPrice.toString();
213
			}
214
		}
9269 amit.gupta 215
		uri += "&fq=" + priceFacetName + ":["+  minString + "%20" + maxString + "]";
9103 anupam.sin 216
		uri += "&fl=ID,Name&facet=true&start=" + start + "&rows=" + rows + "&facet.mincount=1";
217
		for(String facetDefinitionID : filtrableFacets) {
218
				if(facetsQueried.contains(facetDefinitionID)){
219
					uri += "&facet.field={!ex=dt" + facetsQueried.indexOf(facetDefinitionID)+ "}"+ facetDefinitionID; 
220
				} else {
221
					uri += "&facet.field=" + facetDefinitionID;
222
				}
223
		}
224
		log.info("uri=" + uri);
225
 
226
		this.inputSource = new InputSource(uri);
227
 
228
		this.facetMap = getFacetMap();
229
	}
230
 
231
	@SuppressWarnings("unchecked")
232
	private void setFilterableFacets(String[] facetqueries) {
233
		List<String> queriedFacets = getAllMatches(this.query);
9406 amit.gupta 234
		if(facetqueries != null && facetqueries.length!=0) {
9103 anupam.sin 235
			String facetString = Arrays.toString(facetqueries);
236
			List<String> filteredFacets = getAllMatches(facetString);
237
			if(filteredFacets.contains("F_50011")){
238
				for(String facetQuery : facetqueries) {
239
					if(facetQuery.contains("F_50011")){
240
						String facetVal = facetQuery.split(":")[1];
241
						if(CATEGORY_FACET_MAP.containsKey(facetVal)){
9406 amit.gupta 242
							this.filtrableFacets.addAll(CATEGORY_FACET_MAP.get(facetVal));
9103 anupam.sin 243
							return;
244
						} else {
245
							break;
246
						}
247
					}
248
				}
249
			}
250
			if(filteredFacets.contains("F_50010")){
251
				for(String facetQuery : facetqueries) {
252
					if(facetQuery.contains("F_50010")){
253
						String facetVal = facetQuery.split(":")[1];
254
						if(CATEGORY_FACET_MAP.containsKey(facetVal)){
255
							return;
256
						} else {
257
							break;
258
						}
259
					}
260
				}
261
			}
262
		}
263
		if(queriedFacets.contains("F_50011")) {
9406 amit.gupta 264
			String facetVal = this.query.split("F_50011:")[1].split("&")[0].replaceAll("[\"()]", "");
9103 anupam.sin 265
			if (facetVal.contains(" OR ")) {
266
				return;
267
			} else if(CATEGORY_FACET_MAP.containsKey(facetVal)){
9406 amit.gupta 268
				//facetVal = facetVal.split("&")[0].replaceAll("[\"()]", "");
269
					this.filtrableFacets.addAll(CATEGORY_FACET_MAP.get(facetVal));
9103 anupam.sin 270
					return;
9406 amit.gupta 271
			} else {
272
				return;
273
			}
9103 anupam.sin 274
		}
275
		if(queriedFacets.contains("F_50010")){
9406 amit.gupta 276
			String facetVal = this.query.split("F_50010:")[1].split("&")[0].replaceAll("[\"()]", "");
9103 anupam.sin 277
			if (facetVal.contains(" OR ")) {
278
				return;
279
			} else if(CATEGORY_FACET_MAP.containsKey(facetVal)){
9406 amit.gupta 280
					this.filtrableFacets.addAll(CATEGORY_FACET_MAP.get(facetVal));
9103 anupam.sin 281
					return;
9406 amit.gupta 282
			} else {
283
				return;
9103 anupam.sin 284
			}
285
		}
286
	}
287
 
288
	public List<String> getFilterableFacets() {
289
		return this.filtrableFacets; 
290
	}
291
 
292
	public Map<String,Map<String,Integer>> removeUnwantedFacets(Map<String,Map<String,Integer>> facetMap, long numberOfResults){
293
 
294
		Set<String> facetsInQuery = new HashSet<String>(getAllMatches(this.query));
295
		Map<String,Map<String,Integer>> tempFacets = new TreeMap<String, Map<String,Integer>>(); 
296
		for(String facet : facetMap.keySet()){
297
			if(facetMap.get(facet).size() > 0 && !facetsInQuery.contains(facet)){
298
				Map<String,Integer> tempMap = new LinkedHashMap<String, Integer>();
299
 
300
				for(String facetValueName : facetMap.get(facet).keySet()){
301
					//if(facetMap.get(facet).get(facetValueName) != 0 && facetMap.get(facet).get(facetValueName) != numberOfResults){
302
						tempMap.put(facetValueName, facetMap.get(facet).get(facetValueName));
303
					//}
304
				}
305
				if(!tempMap.isEmpty()){
306
					tempFacets.put(facet, tempMap);
307
				}
308
			}	
309
		}
310
		/*if(tempFacets.containsKey("F_50010")){
311
			tempFacets.remove("F_50011");
312
		}*/
313
 
314
		return tempFacets;
315
	}
316
 
317
	public Map<String,Integer> getFacetDetails(String facetName){
318
		if(facetMap != null){
319
			return facetMap.get(facetName);
320
		}else{
321
			return null;
322
		}
323
	}
324
 
325
	public Map<String,Map<String,Integer>> getFacetMap() {
326
		facetMap = new TreeMap<String,Map<String,Integer>>();
327
 
328
		String facetNamePath = "/response/lst/lst[@name = 'facet_fields']/lst";
329
 
330
		NodeList nodes = null;
331
		try {
332
			nodes = (NodeList) this.xpath.evaluate(facetNamePath, this.inputSource, XPathConstants.NODESET);
333
		}
334
		catch (XPathExpressionException xpee) {
335
			return null;
336
		}
337
 
338
		if(nodes.getLength() == 0) {
339
			return null;
340
		}
341
 
342
		NodeList subNodes = null;
343
 
344
		for(int i=0; i<nodes.getLength(); i++) {
345
			Node node = nodes.item(i);
346
			String facetName = node.getAttributes().getNamedItem("name").getNodeValue();
347
			subNodes = node.getChildNodes();
348
			Map<String,Integer> facetValueCountMap = new LinkedHashMap<String,Integer>();
349
			for(int j=0; j<subNodes.getLength(); j++) {
350
				Node subNode = subNodes.item(j);
351
				facetValueCountMap.put(subNode.getAttributes().getNamedItem("name").getNodeValue(), Integer.parseInt(subNode.getTextContent()));
352
			}
353
			if(SORTED_FACET_VALUE_MAP.containsKey(facetName)){
354
				List<String> orderedValues = SORTED_FACET_VALUE_MAP.get(facetName);
355
				Map<String, Integer> sortedMap = new LinkedHashMap<String, Integer>();
356
			    for (Iterator<String> it = orderedValues.iterator(); it.hasNext();) {
357
			    	String val = it.next();
358
			        if(facetValueCountMap.containsKey(val)) {
359
			        	sortedMap.put(val, facetValueCountMap.get(val));
360
			        }
361
			    }
362
			    facetMap.put(facetName, sortedMap);
363
			} else {
364
				facetMap.put(facetName, facetValueCountMap);
365
			}
366
		}
367
		this.numberOfResults  = this.getTotalResults();
368
 
369
		facetMap = removeUnwantedFacets(facetMap, numberOfResults);
370
		return facetMap;
371
	}
372
 
373
	public List<String> getResultMap() {
374
		resultMap = new LinkedList<String>();
375
 
376
		String resultDocsPath = "/response/result/doc";
377
 
378
 
379
		NodeList nodes = null;
380
		try {
381
			nodes = (NodeList) this.xpath.evaluate(resultDocsPath, this.inputSource, XPathConstants.NODESET);
382
		}
383
		catch (XPathExpressionException xpee) {
384
			return null;
385
		}
386
 
387
		if(nodes.getLength() == 0) {
388
			return null;
389
		}
390
 
391
		for(int i=0; i<nodes.getLength(); i++) {
392
			Node node = nodes.item(i);
393
			String docID = node.getFirstChild().getTextContent();
394
			resultMap.add(docID);	
395
 		}
396
		return resultMap;
397
	}
398
 
399
	public HashMap<String, Double> getPriceStatsMap() {
400
		return this.getPriceStatsMap(this.inputSource);
401
	}
402
 
403
	public HashMap<String, Double> getPriceStatsMap(InputSource inputSource) {
404
		HashMap<String, Double> priceStatsMap = new HashMap<String, Double>();
405
 
406
		String resultDocsPath = "/response/lst[@name = 'stats']/lst[@name = 'stats_fields']/lst[@name = '" + priceFacetName + "']";
407
 
408
 
409
		NodeList nodes = null;
410
		try {
411
			nodes = (NodeList) this.xpath.evaluate(resultDocsPath, inputSource, XPathConstants.NODESET);
412
		}
413
		catch (XPathExpressionException xpee) {
414
			return null;
415
		}
416
 
417
		if(nodes.getLength() == 0) {
418
			return null;
419
		}
420
 
421
		NodeList subNodes = nodes.item(0).getChildNodes();
422
 
423
		for(int i=0; i<subNodes.getLength(); i++) {
424
			Node node = subNodes.item(i);
425
 
426
			String parameter = node.getAttributes().getNamedItem("name").getNodeValue();
427
			String value = node.getTextContent();
428
			priceStatsMap.put(parameter, Double.parseDouble(value));	
429
 		}
430
		return priceStatsMap;
431
	}
432
 
433
	public HashMap<String,Integer> getRangeQueryResultMap() {
434
		HashMap<String, Integer> rangeQueryResultMap = new HashMap<String,Integer>();
435
 
436
		String resultDocsPath = "/response/lst[@name = 'facet_counts']/lst[@name = 'facet_queries']/int";
437
 
438
 
439
		NodeList nodes = null;
440
		try {
441
			nodes = (NodeList) this.xpath.evaluate(resultDocsPath, this.inputSource, XPathConstants.NODESET);
442
		}
443
		catch (XPathExpressionException xpee) {
444
			return null;
445
		}
446
 
447
		if(nodes.getLength() == 0) {
448
			return null;
449
		}
450
 
451
 
452
		for(int i=0; i<nodes.getLength(); i++) {
453
			Node node = nodes.item(i);
454
 
455
			String query = node.getAttributes().getNamedItem("name").getNodeValue();
456
			String docCount = node.getTextContent();
457
 
458
			rangeQueryResultMap.put(query,Integer.parseInt(docCount));	
459
 		}
460
		return rangeQueryResultMap;
461
 
462
	}
463
 
464
	/**
465
	 * 
466
	 */
467
	public long getTotalResults(){
468
		String resultDocsPath = "/response/result";
469
		NodeList nodes = null;
470
		try {
471
			nodes = (NodeList) this.xpath.evaluate(resultDocsPath, this.inputSource, XPathConstants.NODESET);
472
		}
473
		catch (XPathExpressionException xpee) {
474
			return 0;
475
		}
476
 
477
		Node node = nodes.item(0);
478
 
479
		return Long.parseLong(node.getAttributes().getNamedItem("numFound").getNodeValue());
480
 
481
	}
482
		/**
483
	 * 
484
	 * @return
485
	 */
486
	public long[] getResultEntityIDs() {
487
		String expression = "/response/result/doc/long";
488
 
489
		NodeList nodes = null;
490
		try {
491
			nodes = (NodeList) this.xpath.evaluate(expression, this.inputSource,
492
					XPathConstants.NODESET);
493
		} 
494
		catch(XPathExpressionException xpee) {
495
			return null;
496
		}
497
 
498
		if(nodes.getLength() == 0) {
499
			return null;
500
		}
501
 
502
		long[] values = new long[nodes.getLength()];
503
		for(int i=0; i<nodes.getLength(); i++) {
504
			Node node = nodes.item(i);
505
			String value = node.getTextContent();
506
			values[i] = Long.parseLong(value);
507
 		}
508
 
509
		return values;
510
	}
511
 
512
	/**
513
	 * 
514
	 * @return
515
	 */
516
	public String[] getResultCategoryNames() {
517
		String expression = "/response/lst/lst[@name = 'facet_fields']/";
518
		expression += "lst[@name = 'Category']/int/@name";
519
 
520
		NodeList nodes = null;
521
		try {
522
			nodes = (NodeList) this.xpath.evaluate(expression, 
523
				this.inputSource, XPathConstants.NODESET);
524
		}
525
		catch (XPathExpressionException xpee) {
526
			return null;
527
		}
528
 
529
		if(nodes.getLength() == 0) {
530
			return null;
531
		}
532
 
533
		String[] values = new String[nodes.getLength()];
534
		for(int i=0; i<nodes.getLength(); i++) {
535
			Node node = nodes.item(i);
536
			values[i] = node.getTextContent();
537
 		}
538
 
539
		return values;
540
	}
541
 
542
	/**
543
	 * 
544
	 * @return
545
	 */
546
	public int[] getResultCategoryCounts() {
547
		String expression = "/response/lst/lst[@name = 'facet_fields']/";
548
		expression += "lst[@name = 'Category']/int";
549
 
550
		NodeList nodes = null;
551
		try {
552
			nodes = (NodeList) this.xpath.evaluate(expression, 
553
				this.inputSource, XPathConstants.NODESET);
554
		}
555
		catch (XPathExpressionException xpee) {
556
			return null;
557
		}
558
 
559
		if(nodes.getLength() == 0) {
560
			return null;
561
		}
562
 
563
		int[] values = new int[nodes.getLength()];
564
		for(int i=0; i<nodes.getLength(); i++) {
565
			Node node = nodes.item(i);
566
			values[i] = Integer.parseInt(node.getTextContent());
567
 		}
568
 
569
		return values;
570
	}
571
 
572
	/**
573
	 * 
574
	 * @return
575
	 */
576
	public String[]  getResultEntityNames() {
577
		String expression = "/response/result/doc/str";
578
 
579
		NodeList nodes = null;
580
		try {
581
			nodes = (NodeList) this.xpath.evaluate(expression, this.inputSource,
582
					XPathConstants.NODESET);
583
		} 
584
		catch(XPathExpressionException xpee) {
585
			return null;
586
		}
587
 
588
		if(nodes.getLength() == 0) {
589
			return null;
590
		}
591
 
592
		String[] values = new String[nodes.getLength()];
593
		for(int i=0; i<nodes.getLength(); i++) {
594
			Node node = nodes.item(i);
595
			String value = node.getTextContent();
596
			values[i] = value;
597
 		}
598
 
599
		return values;
600
	}
601
 
602
	/**
603
	 * 
604
	 * @param facetDefinitionID
605
	 * @return
606
	 */
607
	public String[] getFacetValues(String facetDefinitionID) {
608
		String expression = "/response/lst/lst[@name = 'facet_fields']/";
609
		expression += "lst[@name = '"+ facetDefinitionID +"']/int/@name";
610
 
611
		NodeList nodes = null;
612
		try {
613
			nodes = (NodeList) this.xpath.evaluate(expression, 
614
				this.inputSource, XPathConstants.NODESET);
615
		}
616
		catch (XPathExpressionException xpee) {
617
			return null;
618
		}
619
 
620
		if(nodes.getLength() == 0) {
621
			return null;
622
		}
623
 
624
		String[] values = new String[nodes.getLength()];
625
		for(int i=0; i<nodes.getLength(); i++) {
626
			Node node = nodes.item(i);
627
			values[i] = node.getTextContent();
628
		}
629
 
630
		return values;
631
	}
632
 
633
	/**
634
	 * 
635
	 * @param facetDefinitionID
636
	 * @return
637
	 */
638
	public String[] getFacetCounts(String facetDefinitionID) {
639
		String expression = "/response/lst/lst[@name = 'facet_fields']/";
640
		expression += "lst[@name = '" + facetDefinitionID + "']/int";
641
 
642
		NodeList nodes = null;
643
		try {
644
			nodes = (NodeList) this.xpath.evaluate(expression, 
645
				this.inputSource, XPathConstants.NODESET);
646
		}
647
		catch (XPathExpressionException xpee) {
648
			return null;
649
		}
650
 
651
		if(nodes.getLength() == 0) {
652
			return null;
653
		}
654
 
655
		String[] values = new String[nodes.getLength()];
656
		for(int i=0; i<nodes.getLength(); i++) {
657
			Node node = nodes.item(i);
658
			values[i] = node.getTextContent();
659
 		}
660
 
661
		return values;
662
	}
663
 
664
	public static void main(String[] args){
665
		/*
666
    	// Hard coded for now
667
    	String[] facetDefIDs = new String[] {"F_50001", "F_50002", "F_50003", "F_50004", "F_50005", "F_50006", "F_50007", "F_50008", "F_50009"};
668
 
669
    	// Hard-coded for now
670
    	String[] facetLabels = new String[] {
671
	    	"Brand", "Price","Form Factor", "Carry In Pocket", "Cellular Technologies", 
672
	    	"Data Connectivity", "Camera Resolution", "Built-in Memory", 
673
	    	"Talk time"
674
    	};
675
 
676
		 */
677
    	String[] facetDefIDs = new String[] {"Category","F_50002","F_50001",  "F_50006", "F_50007" };
678
    	//String[] facetLabels = new String[] {"Category","Price", "Brand", "Data Connectivity", "Camera Resolution"	};
679
 
680
 
681
    	String[] fqrys = {};
682
		SolrSearchService search = new SolrSearchService("nokia", fqrys, 0 , 20, null, null, null, -1);
683
 
684
    	long[] entityIDs = search.getResultEntityIDs();
685
    	log.info("entityIDs=" + Arrays.toString(entityIDs));
686
 
687
    	String[] entityNames = search.getResultEntityNames();
688
    	log.info("entityNames=" + Arrays.toString(entityNames));
689
    	search.getFacetMap();
690
 
691
    	search.getResultMap();
692
    	search.getRangeQueryResultMap();
693
    	search.getPriceStatsMap(new InputSource());
694
    	search.getTotalResults();
695
       	for (int i=0; i<facetDefIDs.length; i++) {
696
       		search.getFacetCounts(facetDefIDs[i]);
697
       		search.getFacetValues(facetDefIDs[i]);
698
       	}
699
 
700
	}
701
 
702
 
703
    public static List<String> getAllMatches(String text) {
704
        List<String> matches = new ArrayList<String>();
705
        Matcher m = FACET_PATTERN.matcher(text);
706
        while(m.find()) {
707
            matches.add(m.group(1));
708
        }
709
        return matches;
710
    }
711
 
712
    public Map<String, Double> getDynamicPriceMap() {
713
    	return this.dynamicPriceMap;
714
    }
715
 
716
}