| Line 6... |
Line 6... |
| 6 |
import java.net.URISyntaxException;
|
6 |
import java.net.URISyntaxException;
|
| 7 |
import java.net.URL;
|
7 |
import java.net.URL;
|
| 8 |
|
8 |
|
| 9 |
import org.apache.commons.io.IOUtils;
|
9 |
import org.apache.commons.io.IOUtils;
|
| 10 |
import org.apache.http.client.utils.URIBuilder;
|
10 |
import org.apache.http.client.utils.URIBuilder;
|
| - |
|
11 |
import org.slf4j.Logger;
|
| - |
|
12 |
import org.slf4j.LoggerFactory;
|
| - |
|
13 |
import org.springframework.beans.factory.annotation.Value;
|
| 11 |
import org.springframework.stereotype.Component;
|
14 |
import org.springframework.stereotype.Component;
|
| 12 |
|
15 |
|
| - |
|
16 |
import com.spice.profitmandi.web.controller.SolrSearchController;
|
| - |
|
17 |
|
| 13 |
|
18 |
|
| 14 |
@Component
|
19 |
@Component
|
| 15 |
public class SolrService{
|
20 |
public class SolrService{
|
| 16 |
|
21 |
|
| - |
|
22 |
private static final Logger logger=LoggerFactory.getLogger(SolrService.class);
|
| 17 |
|
23 |
|
| - |
|
24 |
@Value("${solr.url}")
|
| - |
|
25 |
private String SOLR_URL;
|
| 18 |
private static final String SOLR_URL="http://192.168.158.89:8983/solr/collection1/select";
|
26 |
//private static final String SOLR_URL="http://192.168.158.89:8983/solr/collection1/select";
|
| 19 |
private static final String limit ="20";
|
27 |
private static final String limit ="20";
|
| 20 |
private static final String groupLimit = "10";
|
28 |
private static final String groupLimit = "10";
|
| 21 |
private static final String autoSuggestField = "title,subCategoryId,category_id,category,subCategory,score";
|
29 |
private static final String autoSuggestField = "title,subCategoryId,category_id,category,subCategory,score";
|
| 22 |
private static final String searchResultsField = "title,skuBundleId,id,thumbnail,ids";
|
30 |
private static final String searchResultsField = "title,skuBundleId,id,thumbnail,ids";
|
| 23 |
private static final String outputFormat = "json";
|
31 |
private static final String outputFormat = "json";
|
| 24 |
|
32 |
|
| 25 |
|
33 |
|
| 26 |
|
34 |
|
| 27 |
public String getSuggestions(String search_text) throws URISyntaxException, IOException{
|
35 |
public String getSuggestions(String search_text) throws URISyntaxException, IOException{
|
| - |
|
36 |
|
| - |
|
37 |
logger.info("Solr url "+SOLR_URL);
|
| 28 |
URIBuilder autoSuggestUrl = new URIBuilder(SOLR_URL);
|
38 |
URIBuilder autoSuggestUrl = new URIBuilder(SOLR_URL);
|
| 29 |
autoSuggestUrl.addParameter("fl", autoSuggestField); //Fields to choose
|
39 |
autoSuggestUrl.addParameter("fl", autoSuggestField); //Fields to choose
|
| 30 |
autoSuggestUrl.addParameter("wt", outputFormat); //Output format
|
40 |
autoSuggestUrl.addParameter("wt", outputFormat); //Output format
|
| 31 |
autoSuggestUrl.addParameter("group", "true"); //group data
|
41 |
autoSuggestUrl.addParameter("group", "true"); //group data
|
| 32 |
autoSuggestUrl.addParameter("group.query", "category_id:3"); //group by category
|
42 |
autoSuggestUrl.addParameter("group.query", "category_id:3"); //group by category
|
| Line 46... |
Line 56... |
| 46 |
}
|
56 |
}
|
| 47 |
return jsonString;
|
57 |
return jsonString;
|
| 48 |
}
|
58 |
}
|
| 49 |
|
59 |
|
| 50 |
public String getSearchResults(String search_text, int offset) throws URISyntaxException, IOException{
|
60 |
public String getSearchResults(String search_text, int offset) throws URISyntaxException, IOException{
|
| - |
|
61 |
logger.info("Solr url "+SOLR_URL);
|
| 51 |
URIBuilder generalSearchUrl = new URIBuilder(SOLR_URL);
|
62 |
URIBuilder generalSearchUrl = new URIBuilder(SOLR_URL);
|
| 52 |
generalSearchUrl.addParameter("q", search_text);
|
63 |
generalSearchUrl.addParameter("q", search_text);
|
| 53 |
generalSearchUrl.addParameter("fl", searchResultsField); //Fields to choose
|
64 |
generalSearchUrl.addParameter("fl", searchResultsField); //Fields to choose
|
| 54 |
generalSearchUrl.addParameter("wt", outputFormat); //Output format
|
65 |
generalSearchUrl.addParameter("wt", outputFormat); //Output format
|
| 55 |
generalSearchUrl.addParameter("rows", limit); //limit
|
66 |
generalSearchUrl.addParameter("rows", limit); //limit
|