Java Code Examples for org.apache.solr.client.solrj.request.QueryRequest#setPath()
The following examples show how to use
org.apache.solr.client.solrj.request.QueryRequest#setPath() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestCloudPhrasesIdentificationComponent.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testEmptyInput() throws Exception { // empty input shouldn't error, just produce empty results... for (String input : Arrays.asList("", " ")) { for (SolrParams p : Arrays.asList(params("q", "*:*", "phrases.q", input, "phrases", "true"), params("q", "-*:*", "phrases.q", input, "phrases", "true"))) { final QueryRequest req = new QueryRequest(p); req.setPath("/phrases"); final QueryResponse rsp = req.process(getRandClient(random())); try { @SuppressWarnings({"unchecked"}) NamedList<Object> phrases = (NamedList<Object>) rsp.getResponse().get("phrases"); assertEquals("input", input, phrases.get("input")); assertEquals("summary", input, phrases.get("summary")); @SuppressWarnings({"unchecked"}) final List<NamedList<Object>> details = (List<NamedList<Object>>) phrases.get("details"); assertNotNull("null details", details); assertEquals("num phrases found", 0, details.size()); } catch (AssertionError e) { throw new AssertionError(e.getMessage() + " ==> " + rsp, e); } } } }
Example 2
Source File: EmbeddedSolrNoSerializeTest.java From SolrTextTagger with Apache License 2.0 | 6 votes |
public void doTestAssertTagStreaming(BiFunction<ModifiableSolrParams,String,QueryRequest> newQueryRequest) throws IOException, SolrServerException { ModifiableSolrParams params = params(); String input = "foo boston bar";//just one tag; QueryRequest req = newQueryRequest.apply(params, input); req.setPath("/tag"); final AtomicReference<SolrDocument> refDoc = new AtomicReference<>(); req.setStreamingResponseCallback(new StreamingResponseCallback() { @Override public void streamSolrDocument(SolrDocument doc) { refDoc.set(doc); } @Override public void streamDocListInfo(long numFound, long start, Float maxScore) { } }); QueryResponse rsp = req.process(solrServer); assertNotNull(rsp.getResponse().get("tags")); assertNotNull(refDoc.get()); assertEquals("Boston", ((Field)refDoc.get().getFieldValue("name")).stringValue()); }
Example 3
Source File: EmbeddedSolrNoSerializeTest.java From lucene-solr with Apache License 2.0 | 6 votes |
public void doTestAssertTagStreaming(BiFunction<ModifiableSolrParams,String,QueryRequest> newQueryRequest) throws IOException, SolrServerException { ModifiableSolrParams params = params(); String input = "foo boston bar";//just one tag; QueryRequest req = newQueryRequest.apply(params, input); req.setPath("/tag"); final AtomicReference<SolrDocument> refDoc = new AtomicReference<>(); req.setStreamingResponseCallback(new StreamingResponseCallback() { @Override public void streamSolrDocument(SolrDocument doc) { refDoc.set(doc); } @Override public void streamDocListInfo(long numFound, long start, Float maxScore) { } }); QueryResponse rsp = req.process(solrServer); assertNotNull(rsp.getResponse().get("tags")); assertNotNull(refDoc.get()); assertEquals("Boston", ((Field)refDoc.get().getFieldValue("name")).stringValue()); }
Example 4
Source File: AutoAddReplicasIntegrationTest.java From lucene-solr with Apache License 2.0 | 5 votes |
private void disableAutoAddReplicasInCluster() throws SolrServerException, IOException { @SuppressWarnings({"rawtypes"}) Map m = makeMap( "action", CollectionParams.CollectionAction.CLUSTERPROP.toLower(), "name", ZkStateReader.AUTO_ADD_REPLICAS, "val", "false"); @SuppressWarnings({"unchecked"}) QueryRequest request = new QueryRequest(new MapSolrParams(m)); request.setPath("/admin/collections"); cluster.getSolrClient().request(request); }
Example 5
Source File: TestSolrCloudClusterSupport.java From storm-solr with Apache License 2.0 | 5 votes |
protected static void createCollection(String collectionName, int numShards, int replicationFactor, String confName, File confDir) throws Exception { if (confDir != null) { assertTrue("Specified Solr config directory '" + confDir.getAbsolutePath() + "' not found!", confDir.isDirectory()); // upload the test configs SolrZkClient zkClient = cloudSolrClient.getZkStateReader().getZkClient(); ZkConfigManager zkConfigManager = new ZkConfigManager(zkClient); zkConfigManager.uploadConfigDir(confDir.toPath(), confName); } ModifiableSolrParams modParams = new ModifiableSolrParams(); modParams.set(CoreAdminParams.ACTION, CollectionParams.CollectionAction.CREATE.name()); modParams.set("name", collectionName); modParams.set("numShards", numShards); modParams.set("replicationFactor", replicationFactor); int liveNodes = cloudSolrClient.getZkStateReader().getClusterState().getLiveNodes().size(); int maxShardsPerNode = (int) Math.ceil(((double) numShards * replicationFactor) / liveNodes); modParams.set("maxShardsPerNode", maxShardsPerNode); modParams.set("collection.configName", confName); QueryRequest request = new QueryRequest(modParams); request.setPath("/admin/collections"); cloudSolrClient.request(request); ensureAllReplicasAreActive(collectionName, numShards, replicationFactor, 20); }
Example 6
Source File: SolrTarget04.java From datacollector with Apache License 2.0 | 5 votes |
private void getOptionalFieldNames() throws SolrServerException, IOException { QueryRequest request = new QueryRequest(); request.setPath(SCHEMA_PATH); NamedList queryResponse = solrClient.request(request); SimpleOrderedMap simpleOrderedMap = (SimpleOrderedMap) queryResponse.get("schema"); ArrayList<SimpleOrderedMap> fields = (ArrayList<SimpleOrderedMap>) simpleOrderedMap.get("fields"); for (SimpleOrderedMap field : fields) { if (field.get(REQUIRED) == null || field.get(REQUIRED).equals(false)) { optionalFieldNamesMap.add(field.get(NAME).toString()); } } }
Example 7
Source File: TestRebalanceLeaders.java From lucene-solr with Apache License 2.0 | 5 votes |
private void rebalancePropUsingStandardRequest(String prop) throws IOException, SolrServerException { ModifiableSolrParams params = new ModifiableSolrParams(); params.set("action", CollectionParams.CollectionAction.BALANCESHARDUNIQUE.toString()); params.set("property", prop); params.set("collection", COLLECTION_NAME); if (prop.toLowerCase(Locale.ROOT).contains("preferredleader") == false) { params.set("shardUnique", true); } QueryRequest request = new QueryRequest(params); request.setPath("/admin/collections"); QueryResponse resp = request.process(cluster.getSolrClient()); assertEquals("Call to rebalanceLeaders failed ", 0, resp.getStatus()); }
Example 8
Source File: ReplicaPropertiesBase.java From lucene-solr with Apache License 2.0 | 5 votes |
public static NamedList<Object> doPropertyAction(CloudSolrClient client, String... paramsIn) throws IOException, SolrServerException { assertTrue("paramsIn must be an even multiple of 2, it is: " + paramsIn.length, (paramsIn.length % 2) == 0); ModifiableSolrParams params = new ModifiableSolrParams(); for (int idx = 0; idx < paramsIn.length; idx += 2) { params.set(paramsIn[idx], paramsIn[idx + 1]); } QueryRequest request = new QueryRequest(params); request.setPath("/admin/collections"); return client.request(request); }
Example 9
Source File: TestReplicaProperties.java From lucene-solr with Apache License 2.0 | 5 votes |
private void addProperty(CloudSolrClient client, String... paramsIn) throws IOException, SolrServerException { assertTrue("paramsIn must be an even multiple of 2, it is: " + paramsIn.length, (paramsIn.length % 2) == 0); ModifiableSolrParams params = new ModifiableSolrParams(); for (int idx = 0; idx < paramsIn.length; idx += 2) { params.set(paramsIn[idx], paramsIn[idx + 1]); } QueryRequest request = new QueryRequest(params); request.setPath("/admin/collections"); client.request(request); }
Example 10
Source File: TestCloudPhrasesIdentificationComponent.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testBasicPhrases() throws Exception { final String input = " did a Quick brown FOX perniciously jump over the lazy dog"; final String expected = " did a Quick {brown FOX} perniciously jump over {the lazy dog}"; // based on the documents indexed, these assertions should all pass regardless of // how many shards we have, or wether the request is done via /phrases or /select... for (String path : Arrays.asList("/select", "/phrases")) { // ... or if we muck with "q" and use the alternative phrases.q for the bits we care about... for (SolrParams p : Arrays.asList(params("q", input, "phrases", "true"), params("q", "*:*", "phrases.q", input, "phrases", "true"), params("q", "-*:*", "phrases.q", input, "phrases", "true"))) { final QueryRequest req = new QueryRequest(p); req.setPath(path); final QueryResponse rsp = req.process(getRandClient(random())); try { @SuppressWarnings({"unchecked"}) NamedList<Object> phrases = (NamedList<Object>) rsp.getResponse().get("phrases"); assertEquals("input", input, phrases.get("input")); assertEquals("summary", expected, phrases.get("summary")); @SuppressWarnings({"unchecked"}) final List<NamedList<Object>> details = (List<NamedList<Object>>) phrases.get("details"); assertNotNull("null details", details); assertEquals("num phrases found", 2, details.size()); final NamedList<Object> lazy_dog = details.get(0); assertEquals("dog text", "the lazy dog", lazy_dog.get("text")); assertEquals("dog score", 0.166666D, ((Double)lazy_dog.get("score")).doubleValue(), 0.000001D); final NamedList<Object> brown_fox = details.get(1); assertEquals("fox text", "brown FOX", brown_fox.get("text")); assertEquals("fox score", 0.083333D, ((Double)brown_fox.get("score")).doubleValue(), 0.000001D); } catch (AssertionError e) { throw new AssertionError(e.getMessage() + " ::: " + path + " ==> " + rsp, e); } } } }
Example 11
Source File: EmbeddedSolrNoSerializeTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testTag() throws SolrServerException, IOException { ModifiableSolrParams params = params(); String input = "foo boston bar";//just one tag; QueryRequest req = new SolrTaggerRequest(params, input); req.setPath("/tag"); QueryResponse rsp = req.process(solrServer); SolrDocumentList results= (SolrDocumentList) rsp.getResponse().get("response"); assertNotNull(rsp.getResponse().get("tags")); assertNotNull(results.get(0)); }
Example 12
Source File: MetronSolrClient.java From metron with Apache License 2.0 | 5 votes |
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; }
Example 13
Source File: ShowFileRequestHandlerTest.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testDirList() throws SolrServerException, IOException { SolrClient client = getSolrClient(); //assertQ(req("qt", "/admin/file")); TODO file bug that SolrJettyTestBase extends SolrTestCaseJ4 QueryRequest request = new QueryRequest(); request.setPath("/admin/file"); QueryResponse resp = request.process(client); assertEquals(0,resp.getStatus()); assertTrue(((NamedList) resp.getResponse().get("files")).size() > 0);//some files }
Example 14
Source File: AnalyticsShardRequestManager.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Send the analytics request to the shard. */ @Override public SolrException call() throws Exception { client = new HttpSolrClient.Builder(baseUrl).build(); QueryRequest query = new QueryRequest( params ); query.setPath(AnalyticsHandler.NAME); query.setResponseParser(new AnalyticsShardResponseParser(manager)); query.setMethod(SolrRequest.METHOD.POST); NamedList<Object> exception = client.request(query); if (exception.size() > 0) { return (SolrException)exception.getVal(0); } return null; }
Example 15
Source File: MetronSolrClient.java From metron with Apache License 2.0 | 5 votes |
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; }
Example 16
Source File: AutoAddReplicasIntegrationTest.java From lucene-solr with Apache License 2.0 | 5 votes |
private void enableAutoAddReplicasInCluster() throws SolrServerException, IOException { @SuppressWarnings({"rawtypes"}) Map m = makeMap( "action", CollectionParams.CollectionAction.CLUSTERPROP.toLower(), "name", ZkStateReader.AUTO_ADD_REPLICAS); @SuppressWarnings({"unchecked"}) QueryRequest request = new QueryRequest(new MapSolrParams(m)); request.setPath("/admin/collections"); cluster.getSolrClient().request(request); }
Example 17
Source File: SolrStream.java From lucene-solr with Apache License 2.0 | 5 votes |
public TupleStreamParser constructParser(SolrClient server, SolrParams requestParams) throws IOException, SolrServerException { String p = requestParams.get("qt"); if (p != null) { ModifiableSolrParams modifiableSolrParams = (ModifiableSolrParams) requestParams; modifiableSolrParams.remove("qt"); //performance optimization - remove extra whitespace by default when streaming modifiableSolrParams.set("indent", modifiableSolrParams.get("indent", "off")); } String wt = requestParams.get(CommonParams.WT, "json"); QueryRequest query = new QueryRequest(requestParams); query.setPath(p); query.setResponseParser(new InputStreamResponseParser(wt)); query.setMethod(SolrRequest.METHOD.POST); if(user != null && password != null) { query.setBasicAuthCredentials(user, password); } NamedList<Object> genericResponse = server.request(query); InputStream stream = (InputStream) genericResponse.get("stream"); this.closeableHttpResponse = (CloseableHttpResponse)genericResponse.get("closeableResponse"); if (CommonParams.JAVABIN.equals(wt)) { return new JavabinTupleStreamParser(stream, true); } else { InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8); return new JSONTupleStream(reader); } }
Example 18
Source File: SolrTarget04.java From datacollector with Apache License 2.0 | 5 votes |
private void getRequiredFieldNames() throws SolrServerException, IOException { QueryRequest request = new QueryRequest(); request.setPath(SCHEMA_PATH); NamedList queryResponse = solrClient.request(request); SimpleOrderedMap simpleOrderedMap = (SimpleOrderedMap) queryResponse.get("schema"); ArrayList<SimpleOrderedMap> fields = (ArrayList<SimpleOrderedMap>) simpleOrderedMap.get("fields"); for (SimpleOrderedMap field : fields) { if (field.get(REQUIRED) != null && field.get(REQUIRED).equals(true)) { requiredFieldNamesMap.add(field.get(NAME).toString()); } } }
Example 19
Source File: EmbeddedSolrNoSerializeTest.java From SolrTextTagger with Apache License 2.0 | 5 votes |
@Test public void testTag() throws SolrServerException, IOException { ModifiableSolrParams params = params(); String input = "foo boston bar";//just one tag; QueryRequest req = new SolrTaggerRequest(params, input); req.setPath("/tag"); QueryResponse rsp = req.process(solrServer); SolrDocumentList results= (SolrDocumentList) rsp.getResponse().get("response"); assertNotNull(rsp.getResponse().get("tags")); assertNotNull(results.get(0)); }
Example 20
Source File: MetricsQuery.java From lucene-solr with Apache License 2.0 | 4 votes |
@SuppressWarnings({"unchecked", "rawtypes"}) public static List<MetricsQuery> from(Node node) throws JsonQueryException { List<MetricsQuery> metricsQueries = new ArrayList<>(); NamedList config = DOMUtil.childNodesToNamedList(node); List<NamedList> requests = config.getAll("request"); for (NamedList request : requests) { NamedList query = (NamedList) request.get("query"); NamedList queryParameters = (NamedList) query.get("params"); String path = (String) query.get("path"); String core = (String) query.get("core"); String collection = (String) query.get("collection"); List<String> jsonQueries = (ArrayList<String>) request.get("jsonQueries"); ModifiableSolrParams params = new ModifiableSolrParams(); if (queryParameters != null) { for (Map.Entry<String, String> entrySet : (Set<Map.Entry<String, String>>) queryParameters.asShallowMap().entrySet()) { params.add(entrySet.getKey(), entrySet.getValue()); } } QueryRequest queryRequest = new QueryRequest(params); queryRequest.setPath(path); List<JsonQuery> compiledQueries = new ArrayList<>(); if (jsonQueries != null) { for (String jsonQuery : jsonQueries) { JsonQuery compiledJsonQuery = JsonQuery.compile(jsonQuery); compiledQueries.add(compiledJsonQuery); } } metricsQueries.add(new MetricsQuery( path, params, core, collection, compiledQueries)); } return metricsQueries; }