| Line 1... |
Line 1... |
| 1 |
package in.shop2020.dtrapi.services;
|
1 |
package in.shop2020.dtrapi.services;
|
| 2 |
|
2 |
|
| 3 |
import freemarker.template.utility.DeepUnwrap;
|
- |
|
| 4 |
import in.shop2020.config.ConfigException;
|
3 |
import in.shop2020.config.ConfigException;
|
| 5 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
4 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
| 6 |
|
5 |
|
| 7 |
import java.io.IOException;
|
6 |
import java.io.IOException;
|
| 8 |
import java.io.InputStream;
|
7 |
import java.io.InputStream;
|
| 9 |
import java.net.MalformedURLException;
|
- |
|
| 10 |
import java.net.URISyntaxException;
|
8 |
import java.net.URISyntaxException;
|
| 11 |
import java.net.URL;
|
9 |
import java.net.URL;
|
| 12 |
|
10 |
|
| 13 |
import org.apache.commons.io.IOUtils;
|
11 |
import org.apache.commons.io.IOUtils;
|
| 14 |
import org.apache.http.client.utils.URIBuilder;
|
12 |
import org.apache.http.client.utils.URIBuilder;
|
| Line 18... |
Line 16... |
| 18 |
|
16 |
|
| 19 |
public class SolrService{
|
17 |
public class SolrService{
|
| 20 |
|
18 |
|
| 21 |
private static String SOLR_URL;
|
19 |
private static String SOLR_URL;
|
| 22 |
private static final String limit ="20";
|
20 |
private static final String limit ="20";
|
| - |
|
21 |
private static final String groupLimit = "10";
|
| 23 |
private static final String autoSuggestField = "title,subCategoryId,category_id,category,subCategory,score";
|
22 |
private static final String autoSuggestField = "title,subCategoryId,category_id,category,subCategory,score";
|
| 24 |
private static final String searchResultsField = "fl,title,skuBundleId,id,thumbnail";
|
23 |
private static final String searchResultsField = "fl,title,skuBundleId,id,thumbnail";
|
| 25 |
private static final String outputFormat = "json";
|
24 |
private static final String outputFormat = "json";
|
| 26 |
private static Logger log = Logger.getLogger(Class.class);
|
25 |
private static Logger log = Logger.getLogger(Class.class);
|
| 27 |
|
26 |
|
| Line 38... |
Line 37... |
| 38 |
|
37 |
|
| 39 |
public String getSuggestions(String search_text) throws URISyntaxException, IOException{
|
38 |
public String getSuggestions(String search_text) throws URISyntaxException, IOException{
|
| 40 |
URIBuilder autoSuggestUrl = new URIBuilder(SOLR_URL);
|
39 |
URIBuilder autoSuggestUrl = new URIBuilder(SOLR_URL);
|
| 41 |
autoSuggestUrl.addParameter("fl", autoSuggestField); //Fields to choose
|
40 |
autoSuggestUrl.addParameter("fl", autoSuggestField); //Fields to choose
|
| 42 |
autoSuggestUrl.addParameter("wt", outputFormat); //Output format
|
41 |
autoSuggestUrl.addParameter("wt", outputFormat); //Output format
|
| - |
|
42 |
autoSuggestUrl.addParameter("group", "true"); //group data
|
| - |
|
43 |
autoSuggestUrl.addParameter("group.query", "category_id:3"); //group by category
|
| - |
|
44 |
autoSuggestUrl.addParameter("group.query", "category_id:5"); //group by category
|
| 43 |
autoSuggestUrl.addParameter("rows", limit); //search limit for each grouped field or query
|
45 |
autoSuggestUrl.addParameter("group.field", "subCategoryId"); //group by subCategory
|
| - |
|
46 |
autoSuggestUrl.addParameter("group.limit", groupLimit);
|
| 44 |
autoSuggestUrl.addParameter("q", "suggest:("+search_text+")");
|
47 |
autoSuggestUrl.addParameter("q", "suggest:("+search_text+")");
|
| 45 |
URL url = autoSuggestUrl.build().toURL();
|
48 |
URL url = autoSuggestUrl.build().toURL();
|
| 46 |
log.info("Search Url Autosuggest"+url.toString());
|
49 |
log.info("Search Url Autosuggest"+url.toString());
|
| - |
|
50 |
|
| 47 |
InputStream is = url.openStream();
|
51 |
InputStream is = url.openStream();
|
| 48 |
String jsonString;
|
52 |
String jsonString;
|
| 49 |
try{
|
53 |
try{
|
| 50 |
jsonString = IOUtils.toString(is, "UTF-8");
|
54 |
jsonString = IOUtils.toString(is, "UTF-8");
|
| 51 |
}
|
55 |
}
|