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


Java SolrServer类代码示例

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


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

示例1: persistToSolr

import org.apache.solr.client.solrj.SolrServer; //导入依赖的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: 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

示例3: process

import org.apache.solr.client.solrj.SolrServer; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public FieldAnalysisResponse process(SolrServer server) throws SolrServerException, IOException {
  if (fieldTypes == null && fieldNames == null) {
    throw new IllegalStateException("At least one field type or field name need to be specified");
  }
  if (fieldValue == null) {
    throw new IllegalStateException("The field value must be set");
  }
  long startTime = TimeUnit.MILLISECONDS.convert(System.nanoTime(), TimeUnit.NANOSECONDS);
  FieldAnalysisResponse res = new FieldAnalysisResponse();
  res.setResponse(server.request(this));
  long endTime = TimeUnit.MILLISECONDS.convert(System.nanoTime(), TimeUnit.NANOSECONDS);
  res.setElapsedTime(endTime - startTime);
  return res;
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:FieldAnalysisRequest.java

示例4: obtainCollectionCounts

import org.apache.solr.client.solrj.SolrServer; //导入依赖的package包/类
private List<VloReport.CollectionCount> obtainCollectionCounts(SolrServer solrServer) throws SolrServerException {
    final SolrQuery query = new SolrQuery();
    query.setRows(0);
    query.setFacet(true);
    query.addFacetField(FacetConstants.FIELD_COLLECTION);
    query.setFacetLimit(Integer.MAX_VALUE);

    final QueryResponse result = solrServer.query(query);
    final FacetField collectionField = result.getFacetField(FacetConstants.FIELD_COLLECTION);
    logger.debug("Collection field: {}", collectionField.getValues());

    final List<VloReport.CollectionCount> counts
            = collectionField.getValues().stream().map((count) -> {
                VloReport.CollectionCount collectionCount = new VloReport.CollectionCount();
                collectionCount.setCollection(count.getName());
                collectionCount.setCount(count.getCount());
                return collectionCount;
            }).collect(Collectors.toList());
    return counts;
}
 
开发者ID:acdh-oeaw,项目名称:vlo-curation,代码行数:21,代码来源:CollectionsCollector.java

示例5: obtainFacetStats

import org.apache.solr.client.solrj.SolrServer; //导入依赖的package包/类
private List<VloReport.Facet> obtainFacetStats(VloConfig config, SolrServer solrServer) throws SolrServerException {
    final SolrQuery query = new SolrQuery();
    query.setRows(0);
    query.setFacet(true);
    FacetConstants.AVAILABLE_FACETS.forEach((field) -> {
        query.addFacetField(field);
    });
    query.setFacetLimit(-1);

    final QueryResponse result = solrServer.query(query);
    final List<FacetField> facetFields = result.getFacetFields();

    final List<VloReport.Facet> facets
            = facetFields.stream().map((field) -> {
                final VloReport.Facet facet = new VloReport.Facet();
                facet.setName(field.getName());
                facet.setValueCount(field.getValueCount());
                return facet;
            }).collect(Collectors.toList());
    return facets;
}
 
开发者ID:acdh-oeaw,项目名称:vlo-curation,代码行数:22,代码来源:FacetValueCountsCollector.java

示例6: getSolrServer

import org.apache.solr.client.solrj.SolrServer; //导入依赖的package包/类
public static synchronized SolrServer getSolrServer(String url) {
	SolrServer server = servers.get(url);
	if(server == null) {
		logger.info("Connecting to Solr: " + url);
		HttpSolrServer httpServer = new HttpSolrServer(url);
		httpServer.setSoTimeout(Integer.parseInt(SolrMeterConfiguration.getProperty("solr.server.configuration.soTimeout", "60000"))); // socket read timeout
		httpServer.setConnectionTimeout(Integer.parseInt(SolrMeterConfiguration.getProperty("solr.server.configuration.connectionTimeout", "60000")));
		httpServer.setDefaultMaxConnectionsPerHost(Integer.parseInt(SolrMeterConfiguration.getProperty("solr.server.configuration.defaultMaxConnectionsPerHost", "100000")));
		httpServer.setMaxTotalConnections(Integer.parseInt(SolrMeterConfiguration.getProperty("solr.server.configuration.maxTotalConnections", "1000000")));
		httpServer.setFollowRedirects(Boolean.parseBoolean(SolrMeterConfiguration.getProperty("solr.server.configuration.followRedirect", "false"))); // defaults to false
		httpServer.setAllowCompression(Boolean.parseBoolean(SolrMeterConfiguration.getProperty("solr.server.configuration.allowCompression", "true")));
		httpServer.setMaxRetries(Integer.parseInt(SolrMeterConfiguration.getProperty("solr.server.configuration.maxRetries", "1"))); // defaults to 0. > 1 not recommended.
		setAuthentication(httpServer);
		servers.put(url, httpServer);
		return httpServer;

	}
	return server;
}
 
开发者ID:lafourchette,项目名称:solrmeter,代码行数:20,代码来源:SolrServerRegistry.java

示例7: emitTuples

import org.apache.solr.client.solrj.SolrServer; //导入依赖的package包/类
@Override
public void emitTuples()
{
  SolrParams solrQueryParams = getQueryParams();
  try {
    SolrServer solrServer = solrServerConnector.getSolrServer();
    QueryResponse response = solrServer.query(solrQueryParams);
    SolrDocumentList queriedDocuments = response.getResults();
    for (SolrDocument solrDocument : queriedDocuments) {
      emitTuple(solrDocument);
      lastEmittedTuple = solrDocument;
      lastEmittedTimeStamp = System.currentTimeMillis();

      logger.debug("Emiting document: " + solrDocument.getFieldValue("name"));
    }
  } catch (SolrServerException ex) {
    throw new RuntimeException("Unable to fetch documents from Solr server", ex);
  }
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:20,代码来源:AbstractSolrInputOperator.java

示例8: testConfigSet

import org.apache.solr.client.solrj.SolrServer; //导入依赖的package包/类
@Test
public void testConfigSet() throws Exception {

  SolrServer server = getSolrAdmin();
  File testDir = createTempDir(LuceneTestCase.getTestClass().getSimpleName());

  File newCoreInstanceDir = new File(testDir, "newcore");

  CoreAdminRequest.Create req = new CoreAdminRequest.Create();
  req.setCoreName("corewithconfigset");
  req.setInstanceDir(newCoreInstanceDir.getAbsolutePath());
  req.setConfigSet("configset-2");

  CoreAdminResponse response = req.process(server);
  assertThat((String) response.getResponse().get("core"), is("corewithconfigset"));

  try (SolrCore core = cores.getCore("corewithconfigset")) {
    assertThat(core, is(notNullValue()));
  }

}
 
开发者ID:europeana,项目名称:search,代码行数:22,代码来源:TestCoreAdmin.java

示例9: testDeduplicationOfSubmittedTasks

import org.apache.solr.client.solrj.SolrServer; //导入依赖的package包/类
private void testDeduplicationOfSubmittedTasks() throws IOException, SolrServerException {
  SolrServer server = createNewSolrServer("", getBaseUrl((HttpSolrServer) clients.get(0)));
  CollectionAdminRequest.createCollection("ocptest_shardsplit2", 4, "conf1", server, "3000");

  CollectionAdminRequest.splitShard("ocptest_shardsplit2", SHARD1, server, "3001");
  CollectionAdminRequest.splitShard("ocptest_shardsplit2", SHARD2, server, "3002");

  // Now submit another task with the same id. At this time, hopefully the previous 3002 should still be in the queue.
  CollectionAdminResponse response = CollectionAdminRequest.splitShard("ocptest_shardsplit2", SHARD1, server, "3002");
  NamedList r = response.getResponse();
  assertEquals("Duplicate request was supposed to exist but wasn't found. De-duplication of submitted task failed.",
      "Task with the same requestid already exists.", r.get("error"));

  for (int i=3001;i<=3002;i++) {
    String state = getRequestStateAfterCompletion(i + "", REQUEST_STATUS_TIMEOUT, server);
    assertTrue("Task " + i + " did not complete, final state: " + state,state.equals("completed"));
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:MultiThreadedOCPTest.java

示例10: testSaveAFeatureShouldRetryOnFailure

import org.apache.solr.client.solrj.SolrServer; //导入依赖的package包/类
@Test
   public void testSaveAFeatureShouldRetryOnFailure() throws SolrServerException, IOException {
City city = GisgraphyTestHelper.createCityAtSpecificPoint("my city", 1.5F,
	1.6F);
city.setFeatureId(2L);

SolrServer mockSolrServer = createMock(SolrServer.class);
expect(mockSolrServer.add(((SolrInputDocument)EasyMock.anyObject()))).andThrow(new SolrServerException("exception"));
expect(mockSolrServer.add(((SolrInputDocument)EasyMock.anyObject()))).andReturn(null);
replay(mockSolrServer);

IsolrClient mockSolrClient = createMock(IsolrClient.class);
expect(mockSolrClient.getServer()).andStubReturn(mockSolrServer);
replay(mockSolrClient);

ISolRSynchroniser fakeSolrsynchroniser = new SolRSynchroniser(mockSolrClient);

fakeSolrsynchroniser.handleEvent(new GisFeatureStoredEvent(city));
EasyMock.verify(mockSolrServer);
   }
 
开发者ID:gisgraphy,项目名称:gisgraphy,代码行数:21,代码来源:SolRSynchroniserTest.java

示例11: testSaveAFeatureShouldFailWhenMaxNumberOfRetryIsReached

import org.apache.solr.client.solrj.SolrServer; //导入依赖的package包/类
@Test
   public void testSaveAFeatureShouldFailWhenMaxNumberOfRetryIsReached() throws SolrServerException, IOException {
City city = GisgraphyTestHelper.createCityAtSpecificPoint("my city", 1.5F,
	1.6F);
city.setFeatureId(2L);

SolrServer mockSolrServer = createMock(SolrServer.class);
expect(mockSolrServer.add(((SolrInputDocument)EasyMock.anyObject()))).andStubThrow(new SolrServerException("exception"));
replay(mockSolrServer);

IsolrClient mockSolrClient = createMock(IsolrClient.class);
expect(mockSolrClient.getServer()).andStubReturn(mockSolrServer);
replay(mockSolrClient);

ISolRSynchroniser fakesolrsynchroniser = new SolRSynchroniser(mockSolrClient);

try {
    fakesolrsynchroniser.handleEvent(new GisFeatureStoredEvent(city));
    fail("The solrSynchroniser should have throw");
} catch (GisgraphyCommunicationException ignore) {
}

   }
 
开发者ID:gisgraphy,项目名称:gisgraphy,代码行数:24,代码来源:SolRSynchroniserTest.java

示例12: testDeleteAListOfFeatureShouldRetryOnFailure

import org.apache.solr.client.solrj.SolrServer; //导入依赖的package包/类
@Test
   public void testDeleteAListOfFeatureShouldRetryOnFailure() throws SolrServerException, IOException {
City city = GisgraphyTestHelper.createCityAtSpecificPoint("my city", 1.5F,
	1.6F);
city.setFeatureId(2L);

SolrServer mockSolrServer = EasyMock.createMock(SolrServer.class);
expect(mockSolrServer.deleteById("2")).andThrow(new SolrServerException("exception"));
expect(mockSolrServer.deleteById("2")).andReturn(null);
expect(mockSolrServer.commit(true, true)).andReturn(null);
replay(mockSolrServer);

IsolrClient mockSolrClient = createMock(IsolrClient.class);
expect(mockSolrClient.getServer()).andStubReturn(mockSolrServer);
replay(mockSolrClient);

ISolRSynchroniser fakeSolrsynchroniser = new SolRSynchroniser(mockSolrClient);

List<City> listOfFeature = new ArrayList<City>();
listOfFeature.add(city);
fakeSolrsynchroniser.handleEvent(new GisFeatureDeleteAllEvent(listOfFeature));
EasyMock.verify(mockSolrServer);
   }
 
开发者ID:gisgraphy,项目名称:gisgraphy,代码行数:24,代码来源:SolRSynchroniserTest.java

示例13: testOptimizeShouldRetryOnFailure

import org.apache.solr.client.solrj.SolrServer; //导入依赖的package包/类
@Test
   public void testOptimizeShouldRetryOnFailure() throws SolrServerException, IOException {
SolrServer mockSolrServer = createMock(SolrServer.class);
expect(mockSolrServer.optimize(true,true)).andThrow(new SolrServerException("exception"));
expect(mockSolrServer.optimize(true, true)).andReturn(null);
replay(mockSolrServer);

IsolrClient mockSolrClient = createMock(IsolrClient.class);
expect(mockSolrClient.getServer()).andStubReturn(mockSolrServer);
replay(mockSolrClient);

ISolRSynchroniser fakeSolrsynchroniser = new SolRSynchroniser(mockSolrClient);

fakeSolrsynchroniser.optimize();
EasyMock.verify(mockSolrServer);
   }
 
开发者ID:gisgraphy,项目名称:gisgraphy,代码行数:17,代码来源:SolRSynchroniserTest.java

示例14: testOptimizeShouldFailWhenMaxNumberOfRetryIsReached

import org.apache.solr.client.solrj.SolrServer; //导入依赖的package包/类
@Test
   public void testOptimizeShouldFailWhenMaxNumberOfRetryIsReached() throws SolrServerException, IOException {
SolrServer mockSolrServer = createMock(SolrServer.class);
expect(mockSolrServer.optimize(true,true)).andStubThrow(new SolrServerException("exception"));
replay(mockSolrServer);

IsolrClient mockSolrClient = createMock(IsolrClient.class);
expect(mockSolrClient.getServer()).andStubReturn(mockSolrServer);
replay(mockSolrClient);

ISolRSynchroniser fakeSolrsynchroniser = new SolRSynchroniser(mockSolrClient);

try {
    fakeSolrsynchroniser.optimize();
} catch (GisgraphyCommunicationException ignore) {
}
   }
 
开发者ID:gisgraphy,项目名称:gisgraphy,代码行数:18,代码来源:SolRSynchroniserTest.java

示例15: testDeleteAListOfFeatureShouldFailWhenMaxNumberOfRetryIsReached

import org.apache.solr.client.solrj.SolrServer; //导入依赖的package包/类
@Test
   public void testDeleteAListOfFeatureShouldFailWhenMaxNumberOfRetryIsReached() throws SolrServerException, IOException {
City city = GisgraphyTestHelper.createCityAtSpecificPoint("my city", 1.5F,
	1.6F);
city.setFeatureId(2L);

SolrServer mockSolrServer = createMock(SolrServer.class);
expect(mockSolrServer.deleteById("2")).andStubThrow(new SolrServerException("exception"));
replay(mockSolrServer);

IsolrClient mockSolrClient = createMock(IsolrClient.class);
expect(mockSolrClient.getServer()).andStubReturn(mockSolrServer);
replay(mockSolrClient);

ISolRSynchroniser fakeSolrsynchroniser = new SolRSynchroniser(mockSolrClient);

List<City> listOfFeature = new ArrayList<City>();
listOfFeature.add(city);
try {
    fakeSolrsynchroniser.handleEvent(new GisFeatureDeleteAllEvent(listOfFeature));
    fail("The solrSynchroniser should have throw");
} catch (GisgraphyCommunicationException e) {
}
   }
 
开发者ID:gisgraphy,项目名称:gisgraphy,代码行数:25,代码来源:SolRSynchroniserTest.java


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