Subversion Repositories SmartDukaan

Rev

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

Rev 3263 Rev 3561
Line 65... Line 65...
65
	TreeMap<String,HashMap<String,Integer>> facetMap;
65
	TreeMap<String,HashMap<String,Integer>> facetMap;
66
	
66
	
67
	List<String> resultMap;
67
	List<String> resultMap;
68
	
68
	
69
	long numberOfResults=0;
69
	long numberOfResults=0;
-
 
70
	
-
 
71
	String priceFacetName = "F_50002";
-
 
72
	
70
	/**
73
	/**
71
	 * 
74
	 * 
72
	 * @param query
75
	 * @param query
73
	 * @param facetDefinitionIDs
76
	 * @param facetDefinitionIDs
74
	 */
77
	 */
75
	public SolrSearchService(String query, String[] facetqueries, String[] facetDefinitionIDs, long start, long rows,  Double minPrice, Double maxPrice, long categoryId, String sortOrder) {
78
	public SolrSearchService(String query, String[] facetqueries, String[] facetDefinitionIDs, long start, long rows,  Double minPrice, Double maxPrice, long categoryId, String sortOrder, long sourceId) {
-
 
79
		
-
 
80
		if(sourceId != -1){
-
 
81
			priceFacetName = priceFacetName + "_" + sourceId;
-
 
82
		}
76
		
83
		
77
		this.xpath = XPathFactory.newInstance().newXPath();
84
		this.xpath = XPathFactory.newInstance().newXPath();
78
		
85
		
79
		query = query.trim().replaceAll("\\s+", " ");
86
		query = query.trim().replaceAll("\\s+", " ");
80
    	log.info("query=" + query);
87
    	log.info("query=" + query);
81
    	
88
    	
82
		String uri = SOLR_URL + "?wt=xml&q=" + query;
89
		String uri = SOLR_URL + "?wt=xml&q=" + query;
83
		
90
		
84
		uri += "&stats=on&stats.field=F_50002";
91
		uri += "&stats=on&stats.field=" + priceFacetName;
85
 
92
 
86
 
93
 
87
		if(minPrice != null || maxPrice != null){
94
		if(minPrice != null || maxPrice != null){
88
			String minString = "0";
95
			String minString = "0";
89
			String maxString = "*";  
96
			String maxString = "*";  
Line 91... Line 98...
91
				minString = minPrice.toString();
98
				minString = minPrice.toString();
92
			}
99
			}
93
			if(maxPrice != null){
100
			if(maxPrice != null){
94
				maxString = maxPrice.toString();
101
				maxString = maxPrice.toString();
95
			}
102
			}
96
			uri += "&fq=F_50002:["+  minString + " " + maxString + "]";
103
			uri += "&fq=" + priceFacetName + ":["+  minString + " " + maxString + "]";
97
		}
104
		}
98
		
105
		
99
		if(categoryId != 10000){
106
		if(categoryId != 10000){
100
			uri += "&fq=F_50010:\"" + CategoryManager.getCategoryManager().getCategoryLabel(categoryId) + "\"";
107
			uri += "&fq=F_50010:\"" + CategoryManager.getCategoryManager().getCategoryLabel(categoryId) + "\"";
101
		}
108
		}
102
		
109
		
103
		if(sortOrder != null){
110
		if(sortOrder != null){
-
 
111
			//replace the price facet name, so that it can pick price for the source.
-
 
112
			sortOrder = sortOrder.replace("F_50002", priceFacetName);
104
			uri += "&sort=" + sortOrder;
113
			uri += "&sort=" + sortOrder;
105
		}
114
		}
106
		
115
		
107
		if(facetqueries != null) {
116
		if(facetqueries != null) {
108
			for(int i=0; i<facetqueries.length; i++) {
117
			for(int i=0; i<facetqueries.length; i++) {
Line 223... Line 232...
223
	}
232
	}
224
 
233
 
225
	public HashMap<String, Double> getPriceStatsMap() {
234
	public HashMap<String, Double> getPriceStatsMap() {
226
		HashMap<String, Double> priceStatsMap = new HashMap<String, Double>();
235
		HashMap<String, Double> priceStatsMap = new HashMap<String, Double>();
227
 
236
 
228
		String resultDocsPath = "/response/lst[@name = 'stats']/lst[@name = 'stats_fields']/lst[@name = 'F_50002']";
237
		String resultDocsPath = "/response/lst[@name = 'stats']/lst[@name = 'stats_fields']/lst[@name = '" + priceFacetName + "']";
229
		
238
		
230
		
239
		
231
		NodeList nodes = null;
240
		NodeList nodes = null;
232
		try {
241
		try {
233
			nodes = (NodeList) this.xpath.evaluate(resultDocsPath, this.inputSource, XPathConstants.NODESET);
242
			nodes = (NodeList) this.xpath.evaluate(resultDocsPath, this.inputSource, XPathConstants.NODESET);
Line 499... Line 508...
499
    	String[] facetDefIDs = new String[] {"Category","F_50002","F_50001",  "F_50006", "F_50007" };
508
    	String[] facetDefIDs = new String[] {"Category","F_50002","F_50001",  "F_50006", "F_50007" };
500
    	//String[] facetLabels = new String[] {"Category","Price", "Brand", "Data Connectivity", "Camera Resolution"	};
509
    	//String[] facetLabels = new String[] {"Category","Price", "Brand", "Data Connectivity", "Camera Resolution"	};
501
 
510
 
502
    	
511
    	
503
    	String[] fqrys = {};
512
    	String[] fqrys = {};
504
		SolrSearchService search = new SolrSearchService("nokia", fqrys, facetDefIDs, 0 , 20, null, null, 10000, null);
513
		SolrSearchService search = new SolrSearchService("nokia", fqrys, facetDefIDs, 0 , 20, null, null, 10000, null, -1);
505
    	
514
    	
506
    	long[] entityIDs = search.getResultEntityIDs();
515
    	long[] entityIDs = search.getResultEntityIDs();
507
    	log.info("entityIDs=" + Arrays.toString(entityIDs));
516
    	log.info("entityIDs=" + Arrays.toString(entityIDs));
508
    	
517
    	
509
    	String[] entityNames = search.getResultEntityNames();
518
    	String[] entityNames = search.getResultEntityNames();