Subversion Repositories SmartDukaan

Rev

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

Rev 6896 Rev 6931
Line 42... Line 42...
42
public class SolrSearchService {
42
public class SolrSearchService {
43
	/**
43
	/**
44
	 * 
44
	 * 
45
	 */
45
	 */
46
	private static Logger log = Logger.getLogger(Class.class);
46
	private static Logger log = Logger.getLogger(Class.class);
-
 
47
	private HashMap<String, Double> dynamicPriceMap = null;
47
	
48
	
48
	/**
49
	/**
49
	 * 
50
	 * 
50
	 */
51
	 */
51
	public static final String SOLR_URL;
52
	public static final String SOLR_URL;
Line 120... Line 121...
120
		String uri = SOLR_URL + "?wt=xml&q=" + query;
121
		String uri = SOLR_URL + "?wt=xml&q=" + query;
121
		
122
		
122
		uri += "&stats=on&stats.field=" + priceFacetName;
123
		uri += "&stats=on&stats.field=" + priceFacetName;
123
 
124
 
124
 
125
 
125
		if(minPrice != null || maxPrice != null){
-
 
126
			String minString = "0";
-
 
127
			String maxString = "*";  
-
 
128
			if(minPrice != null){
-
 
129
				minString = minPrice.toString();
-
 
130
			}
-
 
131
			if(maxPrice != null){
-
 
132
				maxString = maxPrice.toString();
-
 
133
			}
-
 
134
			uri += "&fq=" + priceFacetName + ":["+  minString + " " + maxString + "]";
-
 
135
		}
-
 
136
		
-
 
137
		if(categoryId != 10000){
126
		if(categoryId != 10000){
138
			uri += "&fq=F_50010:\"" + CategoryManager.getCategoryManager().getCategoryLabel(categoryId) + "\"";
127
			uri += "&fq=F_50010:\"" + CategoryManager.getCategoryManager().getCategoryLabel(categoryId) + "\"";
139
		}
128
		}
140
		
129
		
141
		if(sortOrder != null){
130
		if(sortOrder != null){
Line 170... Line 159...
170
					}
159
					}
171
					uri += "&fq=" + fq;
160
					uri += "&fq=" + fq;
172
				}
161
				}
173
			}
162
			}
174
		}
163
		}
-
 
164
		String minString = "0";
-
 
165
		String maxString = "*";  
-
 
166
		if(minPrice != null || maxPrice != null){
-
 
167
			try {
-
 
168
				dynamicPriceMap = getPriceStatsMap(new InputSource(uri)); 
-
 
169
			} catch (Exception e){
-
 
170
				e.printStackTrace();
-
 
171
			}
-
 
172
			if(minPrice != null){
-
 
173
				minString = minPrice.toString();
-
 
174
			}
-
 
175
			if(maxPrice != null){
-
 
176
				maxString = maxPrice.toString();
-
 
177
			}
-
 
178
		}
-
 
179
		uri += "&fq=" + priceFacetName + ":["+  minString + " " + maxString + "]";
175
		uri += "&fl=ID,Name&facet=true&start=" + start + "&rows=" + rows + "&facet.mincount=1";
180
		uri += "&fl=ID,Name&facet=true&start=" + start + "&rows=" + rows + "&facet.mincount=1";
176
		if(facetDefinitionIDs != null){
181
		if(facetDefinitionIDs != null){
177
			for(int i=0; i<facetDefinitionIDs.length; i++) {
182
			for(int i=0; i<facetDefinitionIDs.length; i++) {
178
				if(rootFacetsQueried.contains(facetDefinitionIDs[i])){
183
				if(rootFacetsQueried.contains(facetDefinitionIDs[i])){
179
					uri += "&facet.field={!ex=dt" + rootFacetsQueried.indexOf(facetDefinitionIDs[i])+ "}"+ facetDefinitionIDs[i]; 
184
					uri += "&facet.field={!ex=dt" + rootFacetsQueried.indexOf(facetDefinitionIDs[i])+ "}"+ facetDefinitionIDs[i]; 
Line 295... Line 300...
295
 		}
300
 		}
296
		return resultMap;
301
		return resultMap;
297
	}
302
	}
298
 
303
 
299
	public HashMap<String, Double> getPriceStatsMap() {
304
	public HashMap<String, Double> getPriceStatsMap() {
-
 
305
		return this.getPriceStatsMap(this.inputSource);
-
 
306
	}
-
 
307
	
-
 
308
	public HashMap<String, Double> getPriceStatsMap(InputSource inputSource) {
300
		HashMap<String, Double> priceStatsMap = new HashMap<String, Double>();
309
		HashMap<String, Double> priceStatsMap = new HashMap<String, Double>();
301
 
310
 
302
		String resultDocsPath = "/response/lst[@name = 'stats']/lst[@name = 'stats_fields']/lst[@name = '" + priceFacetName + "']";
311
		String resultDocsPath = "/response/lst[@name = 'stats']/lst[@name = 'stats_fields']/lst[@name = '" + priceFacetName + "']";
303
		
312
		
304
		
313
		
305
		NodeList nodes = null;
314
		NodeList nodes = null;
306
		try {
315
		try {
307
			nodes = (NodeList) this.xpath.evaluate(resultDocsPath, this.inputSource, XPathConstants.NODESET);
316
			nodes = (NodeList) this.xpath.evaluate(resultDocsPath, inputSource, XPathConstants.NODESET);
308
		}
317
		}
309
		catch (XPathExpressionException xpee) {
318
		catch (XPathExpressionException xpee) {
310
			return null;
319
			return null;
311
		}
320
		}
312
		
321
		
Line 584... Line 593...
584
    	log.info("entityNames=" + Arrays.toString(entityNames));
593
    	log.info("entityNames=" + Arrays.toString(entityNames));
585
    	search.getFacetMap();
594
    	search.getFacetMap();
586
    	
595
    	
587
    	search.getResultMap();
596
    	search.getResultMap();
588
    	search.getRangeQueryResultMap();
597
    	search.getRangeQueryResultMap();
589
    	search.getPriceStatsMap();
598
    	search.getPriceStatsMap(new InputSource());
590
    	search.getTotalResults();
599
    	search.getTotalResults();
591
       	for (int i=0; i<facetDefIDs.length; i++) {
600
       	for (int i=0; i<facetDefIDs.length; i++) {
592
       		search.getFacetCounts(facetDefIDs[i]);
601
       		search.getFacetCounts(facetDefIDs[i]);
593
       		search.getFacetValues(facetDefIDs[i]);
602
       		search.getFacetValues(facetDefIDs[i]);
594
       	}
603
       	}
Line 602... Line 611...
602
        while(m.find()) {
611
        while(m.find()) {
603
            matches.add(m.group(1));
612
            matches.add(m.group(1));
604
        }
613
        }
605
        return matches;
614
        return matches;
606
    }
615
    }
-
 
616
    
-
 
617
    public Map<String, Double> getDynamicPriceMap() {
-
 
618
    	return this.dynamicPriceMap;
-
 
619
    }
-
 
620
    
607
}
621
}