Rev 25380 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.common.solr;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import org.apache.http.client.methods.HttpGet;import org.apache.http.impl.client.HttpClients;import org.springframework.web.util.UriComponentsBuilder;public class SolrService {public static void main(String[] args) throws Throwable {//System.out.println(String.format("{!parent which=\"id:catalog*\"}tagId_i:%s", StringUtils.join(elements)));/*RestClient rc = new RestClient(SchemeType.HTTP, "dtr", 8984);Map<String, String> params = new HashMap<>();Map<String, String> headers = new HashMap<>();params.put("q", "{!parent which=\"id:catalog*\"}tagId_i:4");params.put("fl", "*, [child parentFilter=id:catalog*]");params.put("sort", "rank_i asc");params.put("start", String.valueOf(0));params.put("rows", String.valueOf(10));params.put("wt", "json");String response =rc.get("solr/demo/select", params);JSONObject solrResponseJSONObj = new JSONObject(response);*//*rc.eSolrQuery query = new SolrQuery();query.setQuery("{!parent which=\"id:catalog*\"}tagId_i:4");query.setFields("*, [child parentFilter=id:catalog*]");query.addSort("rank_i", ORDER.asc);query.setStart(0);QueryResponse response = client.query(query);System.out.println(response.toString());SolrDocumentList results = response.getResults();for (int i = 0; i < results.size(); ++i) {System.out.println(results.get(i));}*/UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://dtr:8984/solr/demo/select");builder.queryParam("q", "+brand_s:Samsung +{!parent which=\"id:catalog*\"}");builder.queryParam("fl", "*, [child parentFilter=id:catalog*]");builder.queryParam("wt", "json");HttpGet request = new HttpGet(builder.build().encode().toUri());System.out.println(toString(HttpClients.createDefault().execute(request).getEntity().getContent()));}private static String toString(InputStream inputStream){BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));StringBuilder responseString = new StringBuilder();String line = null;try {while((line = reader.readLine()) != null){responseString.append(line);}inputStream.close();} catch (IOException e) {throw new RuntimeException();}return responseString.toString();}}