当前位置: 首页>>代码示例>>Java>>正文


Java SolrServer.request方法代码示例

本文整理汇总了Java中org.apache.solr.client.solrj.SolrServer.request方法的典型用法代码示例。如果您正苦于以下问题:Java SolrServer.request方法的具体用法?Java SolrServer.request怎么用?Java SolrServer.request使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.solr.client.solrj.SolrServer的用法示例。


在下文中一共展示了SolrServer.request方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createAlias

import org.apache.solr.client.solrj.SolrServer; //导入方法依赖的package包/类
private void createAlias(String alias, String collections)
    throws SolrServerException, IOException {
  SolrServer server = createNewSolrServer("",
      getBaseUrl((HttpSolrServer) clients.get(0)));
  if (random().nextBoolean()) {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("collections", collections);
    params.set("name", alias);
    params.set("action", CollectionAction.CREATEALIAS.toString());
    QueryRequest request = new QueryRequest(params);
    request.setPath("/admin/collections");
    server.request(request);
  } else {
    CollectionAdminRequest.CreateAlias.createAlias(alias, collections, server);
  }
  server.shutdown();
}
 
开发者ID:europeana,项目名称:search,代码行数:18,代码来源:AliasIntegrationTest.java

示例2: assertVersions

import org.apache.solr.client.solrj.SolrServer; //导入方法依赖的package包/类
private void assertVersions(SolrServer client1, SolrServer client2) throws Exception {
  NamedList<Object> details = getDetails(client1);
  ArrayList<NamedList<Object>> commits = (ArrayList<NamedList<Object>>) details.get("commits");
  Long maxVersionClient1 = getVersion(client1);
  Long maxVersionClient2 = getVersion(client2);

  if (maxVersionClient1 > 0 && maxVersionClient2 > 0) {
    assertEquals(maxVersionClient1, maxVersionClient2);
  }
  
  // check vs /replication?command=indexversion call
  ModifiableSolrParams params = new ModifiableSolrParams();
  params.set("qt", "/replication");
  params.set("_trace", "assertVersions");
  params.set("command", "indexversion");
  QueryRequest req = new QueryRequest(params);
  NamedList<Object> resp = client1.request(req);
  
  Long version = (Long) resp.get("indexversion");
  assertEquals(maxVersionClient1, version);
  
  // check vs /replication?command=indexversion call
  resp = client2.request(req);
  version = (Long) resp.get("indexversion");
  assertEquals(maxVersionClient2, version);
}
 
开发者ID:europeana,项目名称:search,代码行数:27,代码来源:TestReplicationHandler.java

示例3: deleteAlias

import org.apache.solr.client.solrj.SolrServer; //导入方法依赖的package包/类
private void deleteAlias(String alias) throws SolrServerException,
    IOException {
  SolrServer server = createNewSolrServer("",
      getBaseUrl((HttpSolrServer) clients.get(0)));
  if (random().nextBoolean()) {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("name", alias);
    params.set("action", CollectionAction.DELETEALIAS.toString());
    QueryRequest request = new QueryRequest(params);
    request.setPath("/admin/collections");
    server.request(request);
  } else {
    CollectionAdminRequest.deleteAlias(alias,server);
  }
  server.shutdown();
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:AliasIntegrationTest.java

示例4: doRequest

import org.apache.solr.client.solrj.SolrServer; //导入方法依赖的package包/类
private void doRequest(final Req req) {
  try {
    SolrServer solrServer = servers.getSolrServer(req);
    solrServer.request(req.uReq);
  } catch (Exception e) {
    SolrException.log(log, e);
    Error error = new Error();
    error.e = e;
    error.req = req;
    if (e instanceof SolrException) {
      error.statusCode = ((SolrException) e).code();
    }
    errors.add(error);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:16,代码来源:SolrCmdDistributor.java

示例5: testGetRawFile

import org.apache.solr.client.solrj.SolrServer; //导入方法依赖的package包/类
public void testGetRawFile() throws SolrServerException, IOException {
  SolrServer server = getSolrServer();
  //assertQ(req("qt", "/admin/file")); TODO file bug that SolrJettyTestBase extends SolrTestCaseJ4
  QueryRequest request = new QueryRequest(params("file","schema.xml"));
  request.setPath("/admin/file");
  final AtomicBoolean readFile = new AtomicBoolean();
  request.setResponseParser(new ResponseParser() {
    @Override
    public String getWriterType() {
      return "mock";//unfortunately this gets put onto params wt=mock but it apparently has no effect
    }

    @Override
    public NamedList<Object> processResponse(InputStream body, String encoding) {
      try {
        if (body.read() >= 0)
          readFile.set(true);
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
      return null;
    }

    @Override
    public NamedList<Object> processResponse(Reader reader) {
      throw new UnsupportedOperationException("TODO unimplemented");//TODO
    }
  });

  server.request( request );//runs request
  //request.process(server); but we don't have a NamedList response
  assertTrue(readFile.get());
}
 
开发者ID:europeana,项目名称:search,代码行数:34,代码来源:ShowFileRequestHandlerTest.java

示例6: reloadCore

import org.apache.solr.client.solrj.SolrServer; //导入方法依赖的package包/类
private NamedList<Object> reloadCore(SolrServer s, String core) throws Exception {
  
  ModifiableSolrParams params = new ModifiableSolrParams();
  params.set("action","reload");
  params.set("core", core);
  params.set("qt","/admin/cores");
  QueryRequest req = new QueryRequest(params);

  NamedList<Object> res = s.request(req);

  assertNotNull("null response from server", res);

  return res;
}
 
开发者ID:europeana,项目名称:search,代码行数:15,代码来源:TestReplicationHandler.java

示例7: watchCoreStartAt

import org.apache.solr.client.solrj.SolrServer; //导入方法依赖的package包/类
/**
 * Polls the SolrCore stats using the specified client until the "startTime" 
 * time for collection is after the specified "min".  Will loop for 
 * at most "timeout" milliseconds before throwing an assertion failure.
 * 
 * @param client The SolrServer to poll
 * @param timeout the max milliseconds to continue polling for
 * @param min the startTime value must exceed this value before the method will return, if null this method will return the first startTime value encountered.
 * @return the startTime value of collection
 */
private Date watchCoreStartAt(SolrServer client, final long timeout, 
                              final Date min) throws InterruptedException, IOException, SolrServerException {
  final long sleepInterval = 200;
  long timeSlept = 0;

  SolrParams p = params("action","status", "core", "collection1");
  while (timeSlept < timeout) {
    QueryRequest req = new QueryRequest(p);
    req.setPath("/admin/cores");
    try {
      NamedList data = client.request(req);
      for (String k : new String[] {"status","collection1"}) {
        Object o = data.get(k);
        assertNotNull("core status rsp missing key: " + k, o);
        data = (NamedList) o;
      }
      Date startTime = (Date) data.get("startTime");
      assertNotNull("core has null startTime", startTime);
      if (null == min || startTime.after(min)) {
        return startTime;
      }
    } catch (SolrException e) {
      // workarround for SOLR-4668
      if (500 != e.code()) {
        throw e;
      } // else server possibly from the core reload in progress...
    }

    timeSlept += sleepInterval;
    Thread.sleep(sleepInterval);
  }
  fail("timed out waiting for collection1 startAt time to exceed: " + min);
  return min; // compilation neccessity
}
 
开发者ID:europeana,项目名称:search,代码行数:45,代码来源:TestReplicationHandler.java

示例8: testSolrJAPICalls

import org.apache.solr.client.solrj.SolrServer; //导入方法依赖的package包/类
private void testSolrJAPICalls() throws Exception {
  SolrServer server = createNewSolrServer("", getBaseUrl((HttpSolrServer) clients.get(0)));
  CollectionAdminRequest.createCollection("testasynccollectioncreation", 1, "conf1", server, "1001");
  String state = null;

  state = getRequestStateAfterCompletion("1001", MAX_TIMEOUT_SECONDS, server);

  assertEquals("CreateCollection task did not complete!", "completed", state);

  CollectionAdminRequest.createCollection("testasynccollectioncreation", 1, "conf1", server, "1002");

  state = getRequestStateAfterCompletion("1002", MAX_TIMEOUT_SECONDS, server);

  assertEquals("Recreating a collection with the same name didn't fail, should have.", "failed", state);

  CollectionAdminRequest.AddReplica addReplica = new CollectionAdminRequest.AddReplica();
  addReplica.setCollectionName("testasynccollectioncreation");
  addReplica.setShardName("shard1");
  addReplica.setAsyncId("1003");
  server.request(addReplica);
  state = getRequestStateAfterCompletion("1003", MAX_TIMEOUT_SECONDS, server);
  assertEquals("Add replica did not complete", "completed", state);

  CollectionAdminRequest.splitShard("testasynccollectioncreation", "shard1", server, "1004");

  state = getRequestStateAfterCompletion("1004", MAX_TIMEOUT_SECONDS * 2, server);

  assertEquals("Shard split did not complete. Last recorded state: " + state, "completed", state);
}
 
开发者ID:europeana,项目名称:search,代码行数:30,代码来源:CollectionsAPIAsyncDistributedZkTest.java

示例9: main

import org.apache.solr.client.solrj.SolrServer; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		int level = 1;
		int shardId = 1;
		String shardHostPort = "localhost:8983";
		String solrUrl = "http://" + shardHostPort + "/solr"; 
		SolrServer solrServer = new HttpSolrServer( solrUrl );
		
	    ModifiableSolrParams params = new ModifiableSolrParams();
	    String queryId = "123";
	    // params.add("q", queryString);
	    // params.add("qt", "frontier");
	    params.add("level", Integer.toString(level));
	    params.add("shardId", Integer.toString(shardId));
	    params.add("queryId", queryId);
		QueryResponse qresp;
	    try {
	    	DirectXmlRequest sreq = new DirectXmlRequest("frontier", "<test/>");
	    	sreq.setPath("/frontier");
	    	sreq.setParams(params);
	    	NamedList<Object> res = solrServer.request(sreq);
	    	Object o = res.get("part_1");
	    	Query q = (Query)o;
	        System.out.println(q);
	    } catch (SolrServerException e) {
//	        throw new RuntimeException();
	        System.out.println(e.getLocalizedMessage());
	        e.printStackTrace();
	    }
	    
	    
	}
 
开发者ID:kwatters,项目名称:solrgraph,代码行数:33,代码来源:BrokerQueryTest.java

示例10: submit

import org.apache.solr.client.solrj.SolrServer; //导入方法依赖的package包/类
@Override
public void submit(final ShardRequest sreq, final String shard, final ModifiableSolrParams params) {
  // do this outside of the callable for thread safety reasons
  final List<String> urls = getURLs(shard);

  Callable<ShardResponse> task = new Callable<ShardResponse>() {
    @Override
    public ShardResponse call() throws Exception {

      ShardResponse srsp = new ShardResponse();
      if (sreq.nodeName != null) {
        srsp.setNodeName(sreq.nodeName);
      }
      srsp.setShardRequest(sreq);
      srsp.setShard(shard);
      SimpleSolrResponse ssr = new SimpleSolrResponse();
      srsp.setSolrResponse(ssr);
      long startTime = System.nanoTime();

      try {
        params.remove(CommonParams.WT); // use default (currently javabin)
        params.remove(CommonParams.VERSION);

        // SolrRequest req = new QueryRequest(SolrRequest.METHOD.POST, "/select");
        // use generic request to avoid extra processing of queries
        QueryRequest req = new QueryRequest(params);
        req.setMethod(SolrRequest.METHOD.POST);

        // no need to set the response parser as binary is the default
        // req.setResponseParser(new BinaryResponseParser());

        // if there are no shards available for a slice, urls.size()==0
        if (urls.size()==0) {
          // TODO: what's the right error code here? We should use the same thing when
          // all of the servers for a shard are down.
          throw new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE, "no servers hosting shard: " + shard);
        }

        if (urls.size() <= 1) {
          String url = urls.get(0);
          srsp.setShardAddress(url);
          SolrServer server = new HttpSolrServer(url, httpClient);
          try {
            ssr.nl = server.request(req);
          } finally {
            server.shutdown();
          }
        } else {
          LBHttpSolrServer.Rsp rsp = httpShardHandlerFactory.makeLoadBalancedRequest(req, urls);
          ssr.nl = rsp.getResponse();
          srsp.setShardAddress(rsp.getServer());
        }
      }
      catch( ConnectException cex ) {
        srsp.setException(cex); //????
      } catch (Exception th) {
        srsp.setException(th);
        if (th instanceof SolrException) {
          srsp.setResponseCode(((SolrException)th).code());
        } else {
          srsp.setResponseCode(-1);
        }
      }

      ssr.elapsedTime = TimeUnit.MILLISECONDS.convert(System.nanoTime() - startTime, TimeUnit.NANOSECONDS);

      return srsp;
    }
  };

  pending.add( completionService.submit(task) );
}
 
开发者ID:europeana,项目名称:search,代码行数:73,代码来源:HttpShardHandler.java

示例11: assertSync

import org.apache.solr.client.solrj.SolrServer; //导入方法依赖的package包/类
void assertSync(SolrServer server, int numVersions, boolean expectedResult, String... syncWith) throws IOException, SolrServerException {
  QueryRequest qr = new QueryRequest(params("qt","/get", "getVersions",Integer.toString(numVersions), "sync", StrUtils.join(Arrays.asList(syncWith), ',')));
  NamedList rsp = server.request(qr);
  assertEquals(expectedResult, (Boolean) rsp.get("sync"));
}
 
开发者ID:europeana,项目名称:search,代码行数:6,代码来源:PeerSyncTest.java

示例12: getDetails

import org.apache.solr.client.solrj.SolrServer; //导入方法依赖的package包/类
private NamedList<Object> getDetails(SolrServer s) throws Exception {
  

  ModifiableSolrParams params = new ModifiableSolrParams();
  params.set("command","details");
  params.set("_trace","getDetails");
  params.set("qt","/replication");
  QueryRequest req = new QueryRequest(params);

  NamedList<Object> res = s.request(req);

  assertNotNull("null response from server", res);

  @SuppressWarnings("unchecked") NamedList<Object> details 
    = (NamedList<Object>) res.get("details");

  assertNotNull("null details", details);

  return details;
}
 
开发者ID:europeana,项目名称:search,代码行数:21,代码来源:TestReplicationHandler.java

示例13: getCommits

import org.apache.solr.client.solrj.SolrServer; //导入方法依赖的package包/类
private NamedList<Object> getCommits(SolrServer s) throws Exception {
  

  ModifiableSolrParams params = new ModifiableSolrParams();
  params.set("command","commits");
  params.set("_trace","getCommits");
  params.set("qt","/replication");
  QueryRequest req = new QueryRequest(params);

  NamedList<Object> res = s.request(req);

  assertNotNull("null response from server", res);


  return res;
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:TestReplicationHandler.java

示例14: getIndexVersion

import org.apache.solr.client.solrj.SolrServer; //导入方法依赖的package包/类
private NamedList<Object> getIndexVersion(SolrServer s) throws Exception {
  
  ModifiableSolrParams params = new ModifiableSolrParams();
  params.set("command","indexversion");
  params.set("_trace","getIndexVersion");
  params.set("qt","/replication");
  QueryRequest req = new QueryRequest(params);

  NamedList<Object> res = s.request(req);

  assertNotNull("null response from server", res);


  return res;
}
 
开发者ID:europeana,项目名称:search,代码行数:16,代码来源:TestReplicationHandler.java


注:本文中的org.apache.solr.client.solrj.SolrServer.request方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。