Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

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