本文整理汇总了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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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()));
}
}
示例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"));
}
}
示例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);
}
示例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) {
}
}
示例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);
}
示例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);
}
示例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) {
}
}
示例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) {
}
}