| 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){
|
- |
|
| 27 |
try {
|
26 |
try {
|
| 28 |
SOLR_URL = ConfigClient.getClient().get("dtr_solr_url");
|
27 |
SOLR_URL = ConfigClient.getClient().get("dtr_solr_url");
|
| 29 |
} catch (ConfigException e) {
|
28 |
} catch (ConfigException e) {
|
| 30 |
log.error("Error while gettting dtr_solr_url param from config service", e);
|
29 |
log.error("Error while gettting dtr_solr_url param from config service", e);
|
| 31 |
SOLR_URL = "http://localhost:8983/solr/collection1/select";
|
30 |
SOLR_URL = "http://localhost:8983/solr/collection1/select";
|
| 32 |
}
|
- |
|
| 33 |
try {
|
- |
|
| 34 |
autoSuggestUrl = new URIBuilder(SOLR_URL);
|
- |
|
| 35 |
} catch (URISyntaxException 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("group", "true"); //group data
|
- |
|
| 41 |
autoSuggestUrl.addParameter("group.query", "category_id:3"); //group by category
|
- |
|
| 42 |
autoSuggestUrl.addParameter("group.query", "category_id:5"); //group by category
|
- |
|
| 43 |
autoSuggestUrl.addParameter("group.field", "subCategoryId"); //group by subCategory
|
- |
|
| 44 |
autoSuggestUrl.addParameter("group.limit", "10"); //search limit for each grouped field or query
|
- |
|
| 45 |
}
|
31 |
}
|
| - |
|
32 |
try {
|
| - |
|
33 |
autoSuggestUrl = new URIBuilder(SOLR_URL);
|
| - |
|
34 |
} catch (URISyntaxException e) {
|
| - |
|
35 |
log.error("Error while building solr_url "+e);
|
| - |
|
36 |
}
|
| - |
|
37 |
autoSuggestUrl.addParameter("fl", "title,subCategoryId,category_id,category,subCategory,score"); //Fields to choose
|
| - |
|
38 |
autoSuggestUrl.addParameter("wt", "json"); //Output format
|
| - |
|
39 |
autoSuggestUrl.addParameter("group", "true"); //group data
|
| - |
|
40 |
autoSuggestUrl.addParameter("group.query", "category_id:3"); //group by category
|
| - |
|
41 |
autoSuggestUrl.addParameter("group.query", "category_id:5"); //group by category
|
| - |
|
42 |
autoSuggestUrl.addParameter("group.field", "subCategoryId"); //group by subCategory
|
| - |
|
43 |
autoSuggestUrl.addParameter("group.limit", "10"); //search limit for each grouped field or query
|
| 46 |
}
|
44 |
}
|
| 47 |
|
45 |
|
| 48 |
public String getSuggestions(String search_text) throws URISyntaxException, IOException{
|
46 |
public String getSuggestions(String search_text) throws URISyntaxException, IOException{
|
| 49 |
autoSuggestUrl.addParameter("q", "suggest:("+search_text+")");
|
47 |
autoSuggestUrl.addParameter("q", "suggest:("+search_text+")");
|
| 50 |
URL url = autoSuggestUrl.build().toURL();
|
48 |
URL url = autoSuggestUrl.build().toURL();
|