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


Java HttpSolrServer类代码示例

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


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

示例1: persistToSolr

import org.apache.solr.client.solrj.impl.HttpSolrServer; //导入依赖的package包/类
private void persistToSolr(Collection<SolrInputDocument> docs) throws SolrServerException, IOException {
    if (docs.isEmpty()) {
        /**
         * @todo Throw an exception here? "DvObject id 9999 does not exist."
         */
        logger.info("nothing to persist");
        return;
    }
    logger.fine("persisting to Solr...");
    SolrServer solrServer = new HttpSolrServer("http://" + systemConfig.getSolrHostColonPort() + "/solr");
    /**
     * @todo Do something with these responses from Solr.
     */
    UpdateResponse addResponse = solrServer.add(docs);
    UpdateResponse commitResponse = solrServer.commit();
}
 
开发者ID:pengchengluo,项目名称:Peking-University-Open-Research-Data-Platform,代码行数:17,代码来源:SolrIndexServiceBean.java

示例2: main

import org.apache.solr.client.solrj.impl.HttpSolrServer; //导入依赖的package包/类
public static void main(String[] args) throws MalformedURLException, SolrServerException {
		HttpSolrServer solr = new HttpSolrServer("http://localhost:8983/solr");
//		  ModifiableSolrParams params = new ModifiableSolrParams(); 
//        params.setQuery("name:Samsung ");
//        params.setStart(0);
//        params.setRows(100);
		SolrQuery params = new SolrQuery();
		params.setQuery("*:*");
		params.setSort("score ",ORDER.desc);
		params.setStart(Integer.getInteger("0"));
		params.setRows(Integer.getInteger("100"));

		QueryResponse response = solr.query(params);
		SolrDocumentList results = response.getResults();
		for (int i = 0; i < results.size(); ++i) {
			System.out.println(results.get(i));
		}
	}
 
开发者ID:dimensoft,项目名称:improved-journey,代码行数:19,代码来源:SolrJSearcher.java

示例3: getNewHttpSolrServer

import org.apache.solr.client.solrj.impl.HttpSolrServer; //导入依赖的package包/类
/**
 * 
 * @param indexUrl
 * @return
 */
public static HttpSolrServer getNewHttpSolrServer(String indexUrl) {
    if (indexUrl == null) {
        throw new IllegalArgumentException("indexUrl may not be null");
    }
    HttpSolrServer server = new HttpSolrServer(indexUrl);
    server.setSoTimeout(TIMEOUT_SO); // socket read timeout
    server.setConnectionTimeout(TIMEOUT_CONNECTION);
    server.setDefaultMaxConnectionsPerHost(100);
    server.setMaxTotalConnections(100);
    server.setFollowRedirects(false); // defaults to false
    server.setAllowCompression(true);
    server.setMaxRetries(1); // defaults to 0. > 1 not recommended.
    // server.setParser(new XMLResponseParser()); // binary parser is used by default
    server.setRequestWriter(new BinaryRequestWriter());

    return server;
}
 
开发者ID:intranda,项目名称:goobi-viewer-connector,代码行数:23,代码来源:SolrSearchIndex.java

示例4: getDatasetCount

import org.apache.solr.client.solrj.impl.HttpSolrServer; //导入依赖的package包/类
public long getDatasetCount() throws SearchException{
    SolrQuery solrQuery = new SolrQuery();
    solrQuery.setQuery("*:*");
    solrQuery.setFilterQueries(SearchFields.TYPE+":datasets",
            SearchFields.PUBLICATION_STATUS+":Published");
    solrQuery.setStart(0);
    solrQuery.setRows(0);
    QueryResponse queryResponse = null;
    try {
        queryResponse = solrServer.query(solrQuery);
        return queryResponse.getResults().getNumFound();
    } catch (HttpSolrServer.RemoteSolrException | SolrServerException ex) {  
        logger.log(Level.INFO, null, ex);
        throw new SearchException("Internal Dataverse Search Engine Error", ex);
    }
}
 
开发者ID:pengchengluo,项目名称:Peking-University-Open-Research-Data-Platform,代码行数:17,代码来源:SolrSearchServiceBean.java

示例5: getDataverseCount

import org.apache.solr.client.solrj.impl.HttpSolrServer; //导入依赖的package包/类
public long getDataverseCount() throws SearchException{
    SolrQuery solrQuery = new SolrQuery();
    solrQuery.setQuery("*:*");
    solrQuery.setFilterQueries(SearchFields.TYPE+":dataverses",
            SearchFields.PUBLICATION_STATUS+":Published");
    solrQuery.setStart(0);
    solrQuery.setRows(0);
    QueryResponse queryResponse = null;
    try {
        queryResponse = solrServer.query(solrQuery);
        return queryResponse.getResults().getNumFound();
    } catch (HttpSolrServer.RemoteSolrException | SolrServerException ex) {  
        logger.log(Level.INFO, null, ex);
        throw new SearchException("Internal Dataverse Search Engine Error", ex);
    }
}
 
开发者ID:pengchengluo,项目名称:Peking-University-Open-Research-Data-Platform,代码行数:17,代码来源:SolrSearchServiceBean.java

示例6: updateConfiguration

import org.apache.solr.client.solrj.impl.HttpSolrServer; //导入依赖的package包/类
public void updateConfiguration() throws SolrServerException, IOException {
    String solrURL = settingDAO.findByKey(SettingKey.SOLR_URL).getConfigurationValue();
    String solrCore = settingDAO.findByKey(SettingKey.SOLR_CORE).getConfigurationValue();
    
    if (!solrURL.endsWith("/")) {
        solrURL = solrURL + "/";
    }
    solrServer = new HttpSolrServer(solrURL + solrCore);
    try {
        
        if (solrServer.ping().getStatus()!=0) {
            throw new SolrServerException("Solr Server not found! ");
        }    
    } catch (HttpSolrServer.RemoteSolrException ex) {
        throw new SolrServerException(ex.getMessage(),ex);
    }
}
 
开发者ID:felixhusse,项目名称:bookery,代码行数:18,代码来源:BookeryService.java

示例7: createNewSolrServer

import org.apache.solr.client.solrj.impl.HttpSolrServer; //导入依赖的package包/类
@Override
public SolrServer createNewSolrServer()
{
  try {
    // setup the server...
    String url = jetty.getBaseUrl().toString() + "/collection1";
    HttpSolrServer s = new HttpSolrServer( url );
    s.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
    s.setDefaultMaxConnectionsPerHost(100);
    s.setMaxTotalConnections(100);
    s.setUseMultiPartPost(random().nextBoolean());

    // where the magic happens
    s.setParser(new BinaryResponseParser());
    s.setRequestWriter(new BinaryRequestWriter());

    return s;
  }
  catch( Exception ex ) {
    throw new RuntimeException( ex );
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:23,代码来源:SolrExampleBinaryTest.java

示例8: testArbitraryJsonIndexing

import org.apache.solr.client.solrj.impl.HttpSolrServer; //导入依赖的package包/类
@Test
public void testArbitraryJsonIndexing() throws Exception  {
  HttpSolrServer server = (HttpSolrServer) getSolrServer();
  server.deleteByQuery("*:*");
  server.commit();
  assertNumFound("*:*", 0); // make sure it got in

  // two docs, one with uniqueKey, another without it
  String json = "{\"id\":\"abc1\", \"name\": \"name1\"} {\"name\" : \"name2\"}";
  HttpClient httpClient = server.getHttpClient();
  HttpPost post = new HttpPost(server.getBaseURL() + "/update/json/docs");
  post.setHeader("Content-Type", "application/json");
  post.setEntity(new InputStreamEntity(new ByteArrayInputStream(json.getBytes("UTF-8")), -1));
  HttpResponse response = httpClient.execute(post);
  assertEquals(200, response.getStatusLine().getStatusCode());
  server.commit();
  assertNumFound("*:*", 2);
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:SolrSchemalessExampleTests.java

示例9: createNewSolrServer

import org.apache.solr.client.solrj.impl.HttpSolrServer; //导入依赖的package包/类
@Override
public SolrServer createNewSolrServer() {
  try {
    // setup the server...
    String url = jetty.getBaseUrl().toString() + "/collection1";
    HttpSolrServer s = new HttpSolrServer(url);
    s.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
    s.setDefaultMaxConnectionsPerHost(100);
    s.setMaxTotalConnections(100);
    s.setUseMultiPartPost(random().nextBoolean());
    
    if (random().nextBoolean()) {
      s.setParser(new BinaryResponseParser());
      s.setRequestWriter(new BinaryRequestWriter());
    }
    
    return s;
  } catch (Exception ex) {
    throw new RuntimeException(ex);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:22,代码来源:SolrSchemalessExampleTests.java

示例10: testSolrException

import org.apache.solr.client.solrj.impl.HttpSolrServer; //导入依赖的package包/类
public void testSolrException() throws Throwable {
  // test a connection to a solr server that probably doesn't exist
  // this is a very simple test and most of the test should be considered verified 
  // if the compiler won't let you by without the try/catch
  boolean gotExpectedError = false;
  try {
    // switched to a local address to avoid going out on the net, ns lookup issues, etc.
    // set a 1ms timeout to let the connection fail faster.
    HttpClient httpClient = HttpClientUtil.createClient(null);
    HttpClientUtil.setConnectionTimeout(httpClient,  1);
    SolrServer client = new HttpSolrServer("http://[ff01::114]:11235/solr/", httpClient);
    SolrQuery query = new SolrQuery("test123");
    client.query(query);
    client.shutdown();
  } catch (SolrServerException sse) {
    gotExpectedError = true;
    /***
    assertTrue(UnknownHostException.class == sse.getRootCause().getClass()
            //If one is using OpenDNS, then you don't get UnknownHostException, instead you get back that the query couldn't execute
            || (sse.getRootCause().getClass() == SolrException.class && ((SolrException) sse.getRootCause()).code() == 302 && sse.getMessage().equals("Error executing query")));
    ***/
  }
  assertTrue(gotExpectedError);
}
 
开发者ID:europeana,项目名称:search,代码行数:25,代码来源:SolrExceptionTest.java

示例11: createNewSolrServer

import org.apache.solr.client.solrj.impl.HttpSolrServer; //导入依赖的package包/类
@Override
public SolrServer createNewSolrServer() {
  try {
    String url = jetty.getBaseUrl().toString() + "/collection1";
    HttpSolrServer s = new HttpSolrServer(url);
    s.setUseMultiPartPost(random().nextBoolean());
    s.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
    s.setDefaultMaxConnectionsPerHost(100);
    s.setMaxTotalConnections(100);
    s.setParser(new XMLResponseParser());
    s.setRequestWriter(new RequestWriter());
    return s;
  } catch (Exception ex) {
    throw new RuntimeException(ex);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:SolrExampleXMLTest.java

示例12: addDocs

import org.apache.solr.client.solrj.impl.HttpSolrServer; //导入依赖的package包/类
private void addDocs(SolrInstance solrInstance) throws IOException, SolrServerException {
  List<SolrInputDocument> docs = new ArrayList<>();
  for (int i = 0; i < 10; i++) {
    SolrInputDocument doc = new SolrInputDocument();
    doc.addField("id", i);
    doc.addField("name", solrInstance.name);
    docs.add(doc);
  }
  HttpSolrServer solrServer = new HttpSolrServer(solrInstance.getUrl(), httpClient);
  SolrResponseBase resp;
  try {
    resp = solrServer.add(docs);
    assertEquals(0, resp.getStatus());
    resp = solrServer.commit();
  } finally {
    solrServer.shutdown();
  }
  assertEquals(0, resp.getStatus());
}
 
开发者ID:europeana,项目名称:search,代码行数:20,代码来源:TestLBHttpSolrServer.java

示例13: createNewSolrServer

import org.apache.solr.client.solrj.impl.HttpSolrServer; //导入依赖的package包/类
/**
 * Create a new solr server.
 * If createJetty was called, an http implementation will be created,
 * otherwise an embedded implementation will be created.
 * Subclasses should override for other options.
 */
public SolrServer createNewSolrServer() {
  if (jetty != null) {
    try {
      // setup the server...
      String url = jetty.getBaseUrl().toString() + "/" + "collection1";
      HttpSolrServer s = new HttpSolrServer( url );
      s.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
      s.setDefaultMaxConnectionsPerHost(100);
      s.setMaxTotalConnections(100);
      return s;
    }
    catch( Exception ex ) {
      throw new RuntimeException( ex );
    }
  } else {
    return new EmbeddedSolrServer( h.getCoreContainer(), "" );
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:25,代码来源:SolrJettyTestBase.java

示例14: waitForNon403or404or503

import org.apache.solr.client.solrj.impl.HttpSolrServer; //导入依赖的package包/类
public  static void waitForNon403or404or503(HttpSolrServer collectionClient)
    throws Exception {
  SolrException exp = null;
  long timeoutAt = System.currentTimeMillis() + 30000;

  while (System.currentTimeMillis() < timeoutAt) {
    boolean missing = false;

    try {
      collectionClient.query(new SolrQuery("*:*"));
    } catch (SolrException e) {
      if (!(e.code() == 403 || e.code() == 503 || e.code() == 404)) {
        throw e;
      }
      exp = e;
      missing = true;
    }
    if (!missing) {
      return;
    }
    Thread.sleep(50);
  }

  fail("Could not find the new collection - " + exp.code() + " : " + collectionClient.getBaseURL());
}
 
开发者ID:europeana,项目名称:search,代码行数:26,代码来源:AbstractFullDistribZkTestBase.java

示例15: 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


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