| 22346 |
amit.gupta |
1 |
package com.spice.profitmandi.common.solr;
|
|
|
2 |
|
|
|
3 |
import java.io.BufferedReader;
|
|
|
4 |
import java.io.IOException;
|
|
|
5 |
import java.io.InputStream;
|
|
|
6 |
import java.io.InputStreamReader;
|
|
|
7 |
|
|
|
8 |
import org.apache.http.client.methods.HttpGet;
|
|
|
9 |
import org.apache.http.impl.client.HttpClients;
|
|
|
10 |
import org.springframework.web.util.UriComponentsBuilder;
|
|
|
11 |
|
|
|
12 |
public class SolrService {
|
|
|
13 |
public static void main(String[] args) throws Throwable {
|
|
|
14 |
//System.out.println(String.format("{!parent which=\"id:catalog*\"}tagId_i:%s", StringUtils.join(elements)));
|
|
|
15 |
/*RestClient rc = new RestClient(SchemeType.HTTP, "dtr", 8984);
|
|
|
16 |
Map<String, String> params = new HashMap<>();
|
|
|
17 |
Map<String, String> headers = new HashMap<>();
|
|
|
18 |
params.put("q", "{!parent which=\"id:catalog*\"}tagId_i:4");
|
|
|
19 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
|
|
20 |
params.put("sort", "rank_i asc");
|
|
|
21 |
params.put("start", String.valueOf(0));
|
|
|
22 |
params.put("rows", String.valueOf(10));
|
|
|
23 |
params.put("wt", "json");
|
|
|
24 |
String response =rc.get("solr/demo/select", params);
|
|
|
25 |
JSONObject solrResponseJSONObj = new JSONObject(response);*/
|
|
|
26 |
|
|
|
27 |
/*rc.e
|
|
|
28 |
SolrQuery query = new SolrQuery();
|
|
|
29 |
query.setQuery("{!parent which=\"id:catalog*\"}tagId_i:4");
|
|
|
30 |
query.setFields("*, [child parentFilter=id:catalog*]");
|
|
|
31 |
query.addSort("rank_i", ORDER.asc);
|
|
|
32 |
query.setStart(0);
|
|
|
33 |
|
|
|
34 |
QueryResponse response = client.query(query);
|
|
|
35 |
System.out.println(response.toString());
|
|
|
36 |
SolrDocumentList results = response.getResults();
|
|
|
37 |
for (int i = 0; i < results.size(); ++i) {
|
|
|
38 |
System.out.println(results.get(i));
|
|
|
39 |
}*/
|
|
|
40 |
|
|
|
41 |
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://dtr:8984/solr/demo/select");
|
|
|
42 |
builder.queryParam("q", "+brand_s:Samsung +{!parent which=\"id:catalog*\"}");
|
|
|
43 |
builder.queryParam("fl", "*, [child parentFilter=id:catalog*]");
|
|
|
44 |
builder.queryParam("wt", "json");
|
|
|
45 |
HttpGet request = new HttpGet(builder.build().encode().toUri());
|
|
|
46 |
System.out.println(toString(HttpClients.createDefault().execute(request).getEntity().getContent()));
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
private static String toString(InputStream inputStream){
|
|
|
50 |
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
|
|
51 |
StringBuilder responseString = new StringBuilder();
|
|
|
52 |
String line = null;
|
|
|
53 |
try {
|
|
|
54 |
while((line = reader.readLine()) != null){
|
|
|
55 |
responseString.append(line);
|
|
|
56 |
}
|
|
|
57 |
inputStream.close();
|
|
|
58 |
} catch (IOException e) {
|
|
|
59 |
throw new RuntimeException();
|
|
|
60 |
}
|
|
|
61 |
return responseString.toString();
|
|
|
62 |
}
|
|
|
63 |
}
|