當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。