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


Java HttpSolrServer.request方法代码示例

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


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

示例1: invokeCollectionApi

import org.apache.solr.client.solrj.impl.HttpSolrServer; //导入方法依赖的package包/类
protected NamedList<Object> invokeCollectionApi(String... args) throws SolrServerException, IOException {
  ModifiableSolrParams params = new ModifiableSolrParams();
  SolrRequest request = new QueryRequest(params);
  for (int i = 0; i < args.length - 1; i+=2) {
    params.add(args[i], args[i+1]);
  }
  request.setPath("/admin/collections");

  String baseUrl = ((HttpSolrServer) shardToJetty.get(SHARD1).get(0).client.solrClient)
      .getBaseURL();
  baseUrl = baseUrl.substring(0, baseUrl.length() - "collection1".length());

  HttpSolrServer baseServer = new HttpSolrServer(baseUrl);
  baseServer.setConnectionTimeout(15000);
  baseServer.setSoTimeout(60000 * 5);
  NamedList r = baseServer.request(request);
  baseServer.shutdown();
  return r;
}
 
开发者ID:europeana,项目名称:search,代码行数:20,代码来源:AbstractFullDistribZkTestBase.java

示例2: getLatestVersion

import org.apache.solr.client.solrj.impl.HttpSolrServer; //导入方法依赖的package包/类
/**
 * Gets the latest commit version and generation from the master
 */
@SuppressWarnings("unchecked")
NamedList getLatestVersion() throws IOException {
  ModifiableSolrParams params = new ModifiableSolrParams();
  params.set(COMMAND, CMD_INDEX_VERSION);
  params.set(CommonParams.WT, "javabin");
  params.set(CommonParams.QT, "/replication");
  QueryRequest req = new QueryRequest(params);
  HttpSolrServer server = new HttpSolrServer(masterUrl, myHttpClient); //XXX modify to use shardhandler
  NamedList rsp;
  try {
    server.setSoTimeout(60000);
    server.setConnectionTimeout(15000);
    
    rsp = server.request(req);
  } catch (SolrServerException e) {
    throw new SolrException(ErrorCode.SERVER_ERROR, e.getMessage(), e);
  } finally {
    server.shutdown();
  }
  return rsp;
}
 
开发者ID:europeana,项目名称:search,代码行数:25,代码来源:SnapPuller.java

示例3: getDetails

import org.apache.solr.client.solrj.impl.HttpSolrServer; //导入方法依赖的package包/类
NamedList getDetails() throws IOException, SolrServerException {
  ModifiableSolrParams params = new ModifiableSolrParams();
  params.set(COMMAND, CMD_DETAILS);
  params.set("slave", false);
  params.set(CommonParams.QT, "/replication");
  HttpSolrServer server = new HttpSolrServer(masterUrl, myHttpClient); //XXX use shardhandler
  NamedList rsp;
  try {
    server.setSoTimeout(60000);
    server.setConnectionTimeout(15000);
    QueryRequest request = new QueryRequest(params);
    rsp = server.request(request);
  } finally {
    server.shutdown();
  }
  return rsp;
}
 
开发者ID:europeana,项目名称:search,代码行数:18,代码来源:SnapPuller.java

示例4: getNumCommits

import org.apache.solr.client.solrj.impl.HttpSolrServer; //导入方法依赖的package包/类
private Long getNumCommits(HttpSolrServer solrServer) throws
    SolrServerException, IOException {
  HttpSolrServer server = new HttpSolrServer(solrServer.getBaseURL());
  server.setConnectionTimeout(15000);
  server.setSoTimeout(60000);
  ModifiableSolrParams params = new ModifiableSolrParams();
  params.set("qt", "/admin/mbeans?key=updateHandler&stats=true");
  // use generic request to avoid extra processing of queries
  QueryRequest req = new QueryRequest(params);
  NamedList<Object> resp = server.request(req);
  NamedList mbeans = (NamedList) resp.get("solr-mbeans");
  NamedList uhandlerCat = (NamedList) mbeans.get("UPDATEHANDLER");
  NamedList uhandler = (NamedList) uhandlerCat.get("updateHandler");
  NamedList stats = (NamedList) uhandler.get("stats");
  Long commits = (Long) stats.get("commits");
  server.shutdown();
  return commits;
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:BasicDistributedZkTest.java

示例5: deleteShard

import org.apache.solr.client.solrj.impl.HttpSolrServer; //导入方法依赖的package包/类
protected void deleteShard(String shard) throws SolrServerException, IOException,
    KeeperException, InterruptedException {

  ModifiableSolrParams params = new ModifiableSolrParams();
  params.set("action", CollectionParams.CollectionAction.DELETESHARD.toString());
  params.set("collection", AbstractFullDistribZkTestBase.DEFAULT_COLLECTION);
  params.set("shard", shard);
  SolrRequest request = new QueryRequest(params);
  request.setPath("/admin/collections");

  String baseUrl = ((HttpSolrServer) shardToJetty.get(SHARD1).get(0).client.solrClient)
      .getBaseURL();
  baseUrl = baseUrl.substring(0, baseUrl.length() - "collection1".length());

  HttpSolrServer baseServer = new HttpSolrServer(baseUrl);
  baseServer.setConnectionTimeout(15000);
  baseServer.setSoTimeout(60000);
  baseServer.request(request);
  baseServer.shutdown();
}
 
开发者ID:europeana,项目名称:search,代码行数:21,代码来源:DeleteShardTest.java

示例6: testQueryParse

import org.apache.solr.client.solrj.impl.HttpSolrServer; //导入方法依赖的package包/类
/**
 * Parse response from query using NoOpResponseParser.
 */
@Test
public void testQueryParse() throws Exception {
  HttpSolrServer server = (HttpSolrServer) createNewSolrServer();
  SolrQuery query = new SolrQuery("id:1234");
  QueryRequest req = new QueryRequest(query);
  server.setParser(new NoOpResponseParser());
  NamedList<Object> resp = server.request(req);
  String responseString = (String) resp.get("response");

  assertResponse(responseString);
  server.shutdown();
}
 
开发者ID:europeana,项目名称:search,代码行数:16,代码来源:NoOpResponseParserTest.java

示例7: doTest

import org.apache.solr.client.solrj.impl.HttpSolrServer; //导入方法依赖的package包/类
@Override
public void doTest() throws Exception {
  ModifiableSolrParams params = new ModifiableSolrParams();
  params.set(CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.STATUS.toString());
  QueryRequest request = new QueryRequest(params);
  request.setPath("/admin/cores");
  int which = r.nextInt(clients.size());
  HttpSolrServer client = (HttpSolrServer)clients.get(which);
  String previousBaseURL = client.getBaseURL();
  // Strip /collection1 step from baseURL - requests fail otherwise
  client.setBaseURL(previousBaseURL.substring(0, previousBaseURL.lastIndexOf("/")));
  NamedList namedListResponse = client.request(request);
  client.setBaseURL(previousBaseURL); // Restore baseURL 
  NamedList status = (NamedList)namedListResponse.get("status");
  NamedList collectionStatus = (NamedList)status.get("collection1");
  String collectionSchema = (String)collectionStatus.get(CoreAdminParams.SCHEMA);
  // Make sure the upgrade to managed schema happened
  assertEquals("Schema resource name differs from expected name", "managed-schema", collectionSchema);

  SolrZkClient zkClient = new SolrZkClient(zkServer.getZkHost(), 30000);
  try {
    // Make sure "DO NOT EDIT" is in the content of the managed schema
    String fileContent = getFileContentFromZooKeeper(zkClient, "/solr/configs/conf1/managed-schema");
    assertTrue("Managed schema is missing", fileContent.contains("DO NOT EDIT"));

    // Make sure the original non-managed schema is no longer in ZooKeeper
    assertFileNotInZooKeeper(zkClient, "/solr/configs/conf1", "schema.xml");

    // Make sure the renamed non-managed schema is present in ZooKeeper
    fileContent = getFileContentFromZooKeeper(zkClient, "/solr/configs/conf1/schema.xml.bak");
    assertTrue("schema file doesn't contain '<schema'", fileContent.contains("<schema"));
  } finally {
    if (zkClient != null) {
      zkClient.close();
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:38,代码来源:TestCloudManagedSchema.java

示例8: createThings

import org.apache.solr.client.solrj.impl.HttpSolrServer; //导入方法依赖的package包/类
@BeforeClass
public static void createThings() throws Exception {
  solrHome = createSolrHome();
  createJetty(solrHome.getAbsolutePath(), null, null);
  String url = jetty.getBaseUrl().toString();
  collection1 = new HttpSolrServer(url);
  collection2 = new HttpSolrServer(url + "/collection2");
  
  String urlCollection1 = jetty.getBaseUrl().toString() + "/" + "collection1";
  String urlCollection2 = jetty.getBaseUrl().toString() + "/" + "collection2";
  shard1 = urlCollection1.replaceAll("https?://", "");
  shard2 = urlCollection2.replaceAll("https?://", "");
  
  //create second core
  CoreAdminRequest.Create req = new CoreAdminRequest.Create();
  req.setCoreName("collection2");
  collection1.request(req);
  
  SolrInputDocument doc = new SolrInputDocument();
  doc.setField("id", "1");
  doc.setField("subject", "batman");
  doc.setField("title", "foo bar");
  collection1.add(doc);
  collection1.commit();
  
  doc.setField("id", "2");
  doc.setField("subject", "superman");
  collection2.add(doc);
  collection2.commit();
  
  doc = new SolrInputDocument();
  doc.setField("id", "3");
  doc.setField("subject", "aquaman");
  doc.setField("title", "foo bar");
  collection1.add(doc);
  collection1.commit();
  
}
 
开发者ID:europeana,项目名称:search,代码行数:39,代码来源:TestTolerantSearch.java

示例9: submit

import org.apache.solr.client.solrj.impl.HttpSolrServer; //导入方法依赖的package包/类
private void submit(final Req req, boolean isCommit) {
  if (req.synchronous) {
    blockAndDoRetries();
    
    HttpSolrServer server = new HttpSolrServer(req.node.getUrl(),
        servers.getHttpClient());
    try {
      server.request(req.uReq);
    } catch (Exception e) {
      throw new SolrException(ErrorCode.SERVER_ERROR, "Failed synchronous update on shard " + req.node + " update: " + req.uReq , e);
    } finally {
      server.shutdown();
    }
    
    return;
  }
  
  if (log.isDebugEnabled()) {
    log.debug("sending update to "
        + req.node.getUrl() + " retry:"
        + req.retries + " " + req.cmdString + " params:" + req.uReq.getParams());
  }
  
  if (isCommit) {
    // a commit using ConncurrentUpdateSolrServer is not async,
    // so we make it async to prevent commits from happening
    // serially across multiple nodes
    pending.add(completionService.submit(new Callable<Object>() {
      
      @Override
      public Object call() throws Exception {
        doRequest(req);
        return null;
      }

    }));
  } else {
    doRequest(req);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:41,代码来源:SolrCmdDistributor.java

示例10: handleSyncShardAction

import org.apache.solr.client.solrj.impl.HttpSolrServer; //导入方法依赖的package包/类
private void handleSyncShardAction(SolrQueryRequest req, SolrQueryResponse rsp) throws KeeperException, InterruptedException, SolrServerException, IOException {
  log.info("Syncing shard : " + req.getParamString());
  String collection = req.getParams().required().get("collection");
  String shard = req.getParams().required().get("shard");
  
  ClusterState clusterState = coreContainer.getZkController().getClusterState();
  
  ZkNodeProps leaderProps = clusterState.getLeader(collection, shard);
  ZkCoreNodeProps nodeProps = new ZkCoreNodeProps(leaderProps);
  
  HttpSolrServer server = new HttpSolrServer(nodeProps.getBaseUrl());
  try {
    server.setConnectionTimeout(15000);
    server.setSoTimeout(60000);
    RequestSyncShard reqSyncShard = new CoreAdminRequest.RequestSyncShard();
    reqSyncShard.setCollection(collection);
    reqSyncShard.setShard(shard);
    reqSyncShard.setCoreName(nodeProps.getCoreName());
    server.request(reqSyncShard);
  } finally {
    server.shutdown();
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:24,代码来源:CollectionsHandler.java

示例11: fetchFileList

import org.apache.solr.client.solrj.impl.HttpSolrServer; //导入方法依赖的package包/类
/**
 * Fetches the list of files in a given index commit point and updates internal list of files to download.
 */
private void fetchFileList(long gen) throws IOException {
  ModifiableSolrParams params = new ModifiableSolrParams();
  params.set(COMMAND,  CMD_GET_FILE_LIST);
  params.set(GENERATION, String.valueOf(gen));
  params.set(CommonParams.WT, "javabin");
  params.set(CommonParams.QT, "/replication");
  QueryRequest req = new QueryRequest(params);
  HttpSolrServer server = new HttpSolrServer(masterUrl, myHttpClient);  //XXX modify to use shardhandler
  try {
    server.setSoTimeout(60000);
    server.setConnectionTimeout(15000);
    NamedList response = server.request(req);

    List<Map<String, Object>> files = (List<Map<String,Object>>) response.get(CMD_GET_FILE_LIST);
    if (files != null)
      filesToDownload = Collections.synchronizedList(files);
    else {
      filesToDownload = Collections.emptyList();
      LOG.error("No files to download for index generation: "+ gen);
    }

    files = (List<Map<String,Object>>) response.get(CONF_FILES);
    if (files != null)
      confFilesToDownload = Collections.synchronizedList(files);

  } catch (SolrServerException e) {
    throw new IOException(e);
  } finally {
    server.shutdown();
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:35,代码来源:SnapPuller.java

示例12: requestRecovery

import org.apache.solr.client.solrj.impl.HttpSolrServer; //导入方法依赖的package包/类
private void requestRecovery(final ZkNodeProps leaderProps, final String baseUrl, final String coreName) throws SolrServerException, IOException {
  Thread thread = new Thread() {
    {
      setDaemon(true);
    }
    @Override
    public void run() {
      RequestRecovery recoverRequestCmd = new RequestRecovery();
      recoverRequestCmd.setAction(CoreAdminAction.REQUESTRECOVERY);
      recoverRequestCmd.setCoreName(coreName);
      
      HttpSolrServer server = new HttpSolrServer(baseUrl, client);
      try {
        server.setConnectionTimeout(30000);
        server.setSoTimeout(120000);
        server.request(recoverRequestCmd);
      } catch (Throwable t) {
        SolrException.log(log, ZkCoreNodeProps.getCoreUrl(leaderProps) + ": Could not tell a replica to recover", t);
        if (t instanceof Error) {
          throw (Error) t;
        }
      } finally {
        server.shutdown();
      }
    }
  };
  updateExecutor.execute(thread);
}
 
开发者ID:europeana,项目名称:search,代码行数:29,代码来源:SyncStrategy.java

示例13: createThings

import org.apache.solr.client.solrj.impl.HttpSolrServer; //导入方法依赖的package包/类
@BeforeClass
public static void createThings() throws Exception {
  solrHome = createSolrHome();
  createJetty(solrHome.getAbsolutePath(), null, null);
  String url = jetty.getBaseUrl().toString();
  collection1 = new HttpSolrServer(url);
  collection2 = new HttpSolrServer(url + "/collection2");
  
  String urlCollection1 = jetty.getBaseUrl().toString() + "/" + "collection1";
  String urlCollection2 = jetty.getBaseUrl().toString() + "/" + "collection2";
  shard1 = urlCollection1.replaceAll("https?://", "");
  shard2 = urlCollection2.replaceAll("https?://", "");
  
  //create second core
  CoreAdminRequest.Create req = new CoreAdminRequest.Create();
  req.setCoreName("collection2");
  collection1.request(req);
  
  SolrInputDocument doc = new SolrInputDocument();
  doc.setField("id", "1");
  doc.setField("text", "batman");
  collection1.add(doc);
  collection1.commit();
  
  doc.setField("id", "2");
  doc.setField("text", "superman");
  collection2.add(doc);
  collection2.commit();
  
}
 
开发者ID:europeana,项目名称:search,代码行数:31,代码来源:DistributedDebugComponentTest.java

示例14: assertDocExists

import org.apache.solr.client.solrj.impl.HttpSolrServer; //导入方法依赖的package包/类
/**
 * Query the real-time get handler for a specific doc by ID to verify it
 * exists in the provided server, using distrib=false so it doesn't route to another replica.
 */
@SuppressWarnings("rawtypes")
protected void assertDocExists(HttpSolrServer solr, String coll, String docId) throws Exception {
  QueryRequest qr = new QueryRequest(params("qt", "/get", "id", docId, "distrib", "false"));
  NamedList rsp = solr.request(qr);
  String match = JSONTestUtil.matchObj("/id", rsp.get("doc"), new Integer(docId));
  assertTrue("Doc with id=" + docId + " not found in " + solr.getBaseURL()
      + " due to: " + match + "; rsp="+rsp, match == null);
}
 
开发者ID:europeana,项目名称:search,代码行数:13,代码来源:HttpPartitionTest.java

示例15: testFailedCoreCreateCleansUp

import org.apache.solr.client.solrj.impl.HttpSolrServer; //导入方法依赖的package包/类
private void testFailedCoreCreateCleansUp() throws Exception {
  Create createCmd = new Create();
  createCmd.setCoreName("core1");
  createCmd.setCollection("the_core_collection");
  String coredataDir = createTempDir().getAbsolutePath();
  createCmd.setDataDir(coredataDir);
  createCmd.setNumShards(1);
  createCmd.setSchemaName("nonexistent_schema.xml");
  
  String url = getBaseUrl(clients.get(0));
  final HttpSolrServer server = new HttpSolrServer(url);
  try {
    server.request(createCmd);
    fail("Expected SolrCore create to fail");
  } catch (Exception e) {
    
  } finally {
    server.shutdown();
  }
  
  long timeout = System.currentTimeMillis() + 15000;
  while (cloudClient.getZkStateReader().getZkClient().exists("/collections/the_core_collection", true)) {
    if (timeout <= System.currentTimeMillis()) {
      fail(cloudClient.getZkStateReader().getZkClient().getChildren("/collections", null, true).toString() + " Collection zk node still exists");
    }
    Thread.sleep(100);
  }
  
  
  assertFalse("Collection zk node still exists", cloudClient.getZkStateReader().getZkClient().exists("/collections/the_core_collection", true));
}
 
开发者ID:europeana,项目名称:search,代码行数:32,代码来源:BasicDistributedZkTest.java


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