private String getFieldNameOfUniqueKey() { final SolrQuery solrQuery = new SolrQuery(); try { solrQuery.setRequestHandler("/schema/uniquekey"); final QueryRequest req = new QueryRequest(solrQuery); if (isBasicAuthEnabled()) { req.setBasicAuthCredentials(getUsername(), getPassword()); } return(req.process(getSolrClient()).getResponse().get("uniqueKey").toString()); } catch (SolrServerException | IOException e) { getLogger().error("Solr query to retrieve uniqueKey-field failed due to {}", new Object[]{solrQuery.toString(), e}, e); throw new ProcessException(e); } }
StopWatch timer = new StopWatch(true); final QueryRequest req = new QueryRequest(solrQuery); if (isBasicAuthEnabled()) { req.setBasicAuthCredentials(getUsername(), getPassword());
final QueryRequest req = new QueryRequest(solrQuery); if (isBasicAuthEnabled()) { req.setBasicAuthCredentials(getUsername(), getPassword());
public QueryRequest getListCollectionsRequest() { ModifiableSolrParams params = new ModifiableSolrParams(); params.set(SolrConstants.REQUEST_ACTION, CollectionParams.CollectionAction.LIST.name()); QueryRequest request = new QueryRequest(params); request.setPath(SolrConstants.REQUEST_COLLECTIONS_PATH); return request; } }
public QueryRequest getCreateCollectionsRequest(String name, int numShards, int replicationFactor) { ModifiableSolrParams params = new ModifiableSolrParams(); params.set(SolrConstants.REQUEST_ACTION, CollectionParams.CollectionAction.CREATE.name()); params.set(SolrConstants.REQUEST_NAME, name); params.set(SolrConstants.REQUEST_NUM_SHARDS, numShards); params.set(SolrConstants.REQUEST_REPLICATION_FACTOR, replicationFactor); params.set(SolrConstants.REQUEST_COLLECTION_CONFIG_NAME, name); QueryRequest request = new QueryRequest(params); request.setPath(SolrConstants.REQUEST_COLLECTIONS_PATH); return request; }
QueryResponse query(String collection, SolrParams solrParams) throws IOException, SolrServerException { QueryRequest query = new QueryRequest(solrParams); return process(collection, query); }
public QueryResponse query(SolrParams params) throws SolrServerException { return new QueryRequest( params ).process( this ); }
public QueryResponse query(SolrParams params, METHOD method) throws SolrServerException { return new QueryRequest( params, method ).process( this ); }
/** * Performs a query to the Solr server * * @param collection the Solr collection to query * @param params an object holding all key/value parameters to send along the request * * @return a {@link org.apache.solr.client.solrj.response.QueryResponse} containing the response * from the server * * @throws IOException If there is a low-level I/O error. * @throws SolrServerException if there is an error on the server */ public QueryResponse query(String collection, SolrParams params) throws SolrServerException, IOException { return new QueryRequest(params).process(this, collection); }
/** * Performs a query to the Solr server * * @param collection the Solr collection to query * @param params an object holding all key/value parameters to send along the request * * @return a {@link org.apache.solr.client.solrj.response.QueryResponse} containing the response * from the server * * @throws IOException If there is a low-level I/O error. * @throws SolrServerException if there is an error on the server */ public QueryResponse query(String collection, SolrParams params) throws SolrServerException, IOException { return new QueryRequest(params).process(this, collection); }
/** * Performs a query to the Solr server * * @param collection the Solr collection to query * @param params an object holding all key/value parameters to send along the request * @param method specifies the HTTP method to use for the request, such as GET or POST * * @return a {@link org.apache.solr.client.solrj.response.QueryResponse} containing the response * from the server * * @throws IOException If there is a low-level I/O error. * @throws SolrServerException if there is an error on the server */ public QueryResponse query(String collection, SolrParams params, METHOD method) throws SolrServerException, IOException { return new QueryRequest(params, method).process(this, collection); }
/** * Performs a query to the Solr server * * @param collection the Solr collection to query * @param params an object holding all key/value parameters to send along the request * @param method specifies the HTTP method to use for the request, such as GET or POST * * @return a {@link org.apache.solr.client.solrj.response.QueryResponse} containing the response * from the server * * @throws IOException If there is a low-level I/O error. * @throws SolrServerException if there is an error on the server */ public QueryResponse query(String collection, SolrParams params, METHOD method) throws SolrServerException, IOException { return new QueryRequest(params, method).process(this, collection); }
private static Set<String> fetchLiveNodes(SolrClient client) throws Exception { ModifiableSolrParams params = new ModifiableSolrParams(); params.set("action", "CLUSTERSTATUS"); QueryRequest request = new QueryRequest(params); request.setPath("/admin/collections"); NamedList cluster = (SimpleOrderedMap) client.request(request).get("cluster"); Set<String> liveNodes = new HashSet((List<String>)(cluster.get("live_nodes"))); return liveNodes; }
public NamedList<Double> call() throws Exception { ModifiableSolrParams params = new ModifiableSolrParams(); HttpSolrClient solrClient = cache.getHttpSolrClient(baseUrl); params.add(DISTRIB, "false"); params.add("fq","{!significantTerms}"); for(String key : paramsMap.keySet()) { params.add(key, paramsMap.get(key)); } params.add("minDocFreq", Float.toString(minDocFreq)); params.add("maxDocFreq", Float.toString(maxDocFreq)); params.add("minTermLength", Integer.toString(minTermLength)); params.add("field", field); params.add("numTerms", String.valueOf(numTerms*5)); QueryRequest request= new QueryRequest(params); QueryResponse response = request.process(solrClient); NamedList res = response.getResponse(); return res; } }
public NamedList<Double> call() throws Exception { ModifiableSolrParams params = new ModifiableSolrParams(); HttpSolrClient solrClient = cache.getHttpSolrClient(baseUrl); params.add(DISTRIB, "false"); params.add("fq","{!igain}"); for(String key : paramsMap.keySet()) { params.add(key, paramsMap.get(key)); } params.add("outcome", outcome); params.add("positiveLabel", Integer.toString(positiveLabel)); params.add("field", field); params.add("numTerms", String.valueOf(numTerms)); QueryRequest request= new QueryRequest(params); QueryResponse response = request.process(solrClient); NamedList res = response.getResponse(); return res; } }
public static JSONTupleStream create(SolrClient server, SolrParams requestParams) throws IOException, SolrServerException { String p = requestParams.get("qt"); if(p != null) { ModifiableSolrParams modifiableSolrParams = (ModifiableSolrParams) requestParams; modifiableSolrParams.remove("qt"); } QueryRequest query = new QueryRequest( requestParams ); query.setPath(p); query.setResponseParser(new InputStreamResponseParser("json")); query.setMethod(SolrRequest.METHOD.POST); NamedList<Object> genericResponse = server.request(query); InputStream stream = (InputStream)genericResponse.get("stream"); InputStreamReader reader = new InputStreamReader(stream, "UTF-8"); return new JSONTupleStream(reader); }
public static JSONTupleStream create(SolrClient server, SolrParams requestParams) throws IOException, SolrServerException { String p = requestParams.get("qt"); if(p != null) { ModifiableSolrParams modifiableSolrParams = (ModifiableSolrParams) requestParams; modifiableSolrParams.remove("qt"); } QueryRequest query = new QueryRequest( requestParams ); query.setPath(p); query.setResponseParser(new InputStreamResponseParser("json")); query.setMethod(SolrRequest.METHOD.POST); NamedList<Object> genericResponse = server.request(query); InputStream stream = (InputStream)genericResponse.get("stream"); InputStreamReader reader = new InputStreamReader(stream, "UTF-8"); return new JSONTupleStream(reader); }
@Override public JsonNode executeQueryWithRawResponse(String queryString) throws SiteWhereException { try { LOGGER.debug("About to execute Solr search with query string: " + queryString); NoOpResponseParser rawJsonResponseParser = new NoOpResponseParser(); rawJsonResponseParser.setWriterType("json"); SolrQuery query = new SolrQuery(); query.add(createParamsFromQueryString(queryString)); QueryRequest request = new QueryRequest(query); request.setResponseParser(rawJsonResponseParser); NamedList<?> results = getSolr().getSolrClient().request(request); return MAPPER.readTree((String) results.get("response")); } catch (SolrServerException e) { throw new SiteWhereException("Unable to execute query.", e); } catch (IOException e) { throw new SiteWhereException("Unable to execute query.", e); } }
private String getFieldNameOfUniqueKey() { final SolrQuery solrQuery = new SolrQuery(); try { solrQuery.setRequestHandler("/schema/uniquekey"); final QueryRequest req = new QueryRequest(solrQuery); if (isBasicAuthEnabled()) { req.setBasicAuthCredentials(getUsername(), getPassword()); } return(req.process(getSolrClient()).getResponse().get("uniqueKey").toString()); } catch (SolrServerException | IOException e) { getLogger().error("Solr query to retrieve uniqueKey-field failed due to {}", new Object[]{solrQuery.toString(), e}, e); throw new ProcessException(e); } }
@Override public JsonNode executeQueryWithRawResponse(String queryString) throws SiteWhereException { try { getLogger().debug("About to execute Solr search with query string: " + queryString); NoOpResponseParser rawJsonResponseParser = new NoOpResponseParser(); rawJsonResponseParser.setWriterType("json"); SolrQuery query = new SolrQuery(); query.add(createParamsFromQueryString(queryString)); QueryRequest request = new QueryRequest(query); request.setResponseParser(rawJsonResponseParser); NamedList<?> results = getSolrConnection().getSolrClient().request(request); return MAPPER.readTree((String) results.get("response")); } catch (SolrServerException e) { throw new SiteWhereException("Unable to execute query.", e); } catch (IOException e) { throw new SiteWhereException("Unable to execute query.", e); } }