| Line 21... |
Line 21... |
| 21 |
private static URIBuilder generalSearchUrl;
|
21 |
private static URIBuilder generalSearchUrl;
|
| 22 |
private static String SOLR_URL;
|
22 |
private static String SOLR_URL;
|
| 23 |
private static Logger log = Logger.getLogger(Class.class);
|
23 |
private static Logger log = Logger.getLogger(Class.class);
|
| 24 |
|
24 |
|
| 25 |
static{
|
25 |
static{
|
| - |
|
26 |
synchronized(SolrService.class){
|
| 26 |
try {
|
27 |
try {
|
| 27 |
SOLR_URL = ConfigClient.getClient().get("dtr_solr_url");
|
28 |
SOLR_URL = ConfigClient.getClient().get("dtr_solr_url");
|
| 28 |
} catch (ConfigException e) {
|
29 |
} catch (ConfigException e) {
|
| 29 |
log.error("Error while gettting dtr_solr_url param from config service", e);
|
30 |
log.error("Error while gettting dtr_solr_url param from config service", e);
|
| 30 |
SOLR_URL = "http://localhost:8983/solr/collection1/select";
|
31 |
SOLR_URL = "http://localhost:8983/solr/collection1/select";
|
| 31 |
}
|
32 |
}
|
| 32 |
try {
|
33 |
try {
|
| 33 |
autoSuggestUrl = new URIBuilder(SOLR_URL);
|
34 |
autoSuggestUrl = new URIBuilder(SOLR_URL);
|
| 34 |
} catch (URISyntaxException e) {
|
35 |
} catch (URISyntaxException e) {
|
| 35 |
log.error("Error while building solr_url "+e);
|
36 |
log.error("Error while building solr_url "+e);
|
| - |
|
37 |
}
|
| - |
|
38 |
autoSuggestUrl.addParameter("fl", "title,subCategoryId,category_id,category,subCategory,score"); //Fields to choose
|
| - |
|
39 |
autoSuggestUrl.addParameter("wt", "json"); //Output format
|
| - |
|
40 |
autoSuggestUrl.addParameter("rows", "20"); //search limit for each grouped field or query
|
| - |
|
41 |
|
| - |
|
42 |
generalSearchUrl.addParameter("fl", "title,skuBundleId,id,thumbnail");
|
| - |
|
43 |
generalSearchUrl.addParameter("wt", "json");
|
| - |
|
44 |
autoSuggestUrl.addParameter("rows", "20");
|
| 36 |
}
|
45 |
}
|
| 37 |
autoSuggestUrl.addParameter("fl", "title,subCategoryId,category_id,category,subCategory,score"); //Fields to choose
|
- |
|
| 38 |
autoSuggestUrl.addParameter("wt", "json"); //Output format
|
- |
|
| 39 |
autoSuggestUrl.addParameter("rows", "20"); //search limit for each grouped field or query
|
- |
|
| 40 |
}
|
46 |
}
|
| 41 |
|
47 |
|
| 42 |
public String getSuggestions(String search_text, String offset) throws URISyntaxException, IOException{
|
48 |
public String getSuggestions(String search_text) throws URISyntaxException, IOException{
|
| 43 |
autoSuggestUrl.setParameter("q", "suggest:("+search_text+")");
|
49 |
autoSuggestUrl.setParameter("q", "suggest:("+search_text+")");
|
| - |
|
50 |
URL url = autoSuggestUrl.build().toURL();
|
| - |
|
51 |
log.info("Search Url "+url.toString());
|
| - |
|
52 |
InputStream is = url.openStream();
|
| - |
|
53 |
String jsonString;
|
| - |
|
54 |
try{
|
| - |
|
55 |
jsonString = IOUtils.toString(is, "UTF-8");
|
| - |
|
56 |
}
|
| - |
|
57 |
finally{
|
| - |
|
58 |
is.close();
|
| - |
|
59 |
}
|
| - |
|
60 |
return jsonString;
|
| - |
|
61 |
}
|
| - |
|
62 |
|
| - |
|
63 |
public String getSearchResults(String search_text, String offset) throws URISyntaxException, IOException{
|
| - |
|
64 |
generalSearchUrl.setParameter("q", search_text);
|
| 44 |
if (offset!=null && !offset.isEmpty()){
|
65 |
if (offset!=null && !offset.isEmpty()){
|
| 45 |
try{
|
- |
|
| 46 |
autoSuggestUrl.setParameter("start", offset);
|
66 |
generalSearchUrl.setParameter("start", offset);
|
| 47 |
}
|
- |
|
| 48 |
catch(Exception e){
|
- |
|
| 49 |
;
|
- |
|
| 50 |
}
|
- |
|
| 51 |
}
|
67 |
}
|
| 52 |
URL url = autoSuggestUrl.build().toURL();
|
68 |
URL url = generalSearchUrl.build().toURL();
|
| 53 |
log.info("Search Url "+url.toString());
|
69 |
log.info("Search Url "+url.toString());
|
| 54 |
InputStream is = url.openStream();
|
70 |
InputStream is = url.openStream();
|
| 55 |
String jsonString;
|
71 |
String jsonString;
|
| 56 |
try{
|
72 |
try{
|
| 57 |
jsonString = IOUtils.toString(is, "UTF-8");
|
73 |
jsonString = IOUtils.toString(is, "UTF-8");
|