本文整理汇总了Java中org.apache.solr.client.solrj.impl.LBHttpSolrServer.query方法的典型用法代码示例。如果您正苦于以下问题:Java LBHttpSolrServer.query方法的具体用法?Java LBHttpSolrServer.query怎么用?Java LBHttpSolrServer.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.solr.client.solrj.impl.LBHttpSolrServer
的用法示例。
在下文中一共展示了LBHttpSolrServer.query方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testReliability
import org.apache.solr.client.solrj.impl.LBHttpSolrServer; //导入方法依赖的package包/类
public void testReliability() throws Exception {
String[] s = new String[solr.length];
for (int i = 0; i < solr.length; i++) {
s[i] = solr[i].getUrl();
}
ModifiableSolrParams params = new ModifiableSolrParams();
params.set(HttpClientUtil.PROP_CONNECTION_TIMEOUT, 250);
params.set(HttpClientUtil.PROP_SO_TIMEOUT, 250);
HttpClient myHttpClient = HttpClientUtil.createClient(params);
LBHttpSolrServer lbHttpSolrServer = new LBHttpSolrServer(myHttpClient, s);
lbHttpSolrServer.setAliveCheckInterval(500);
// Kill a server and test again
solr[1].jetty.stop();
solr[1].jetty = null;
// query the servers
for (String value : s)
lbHttpSolrServer.query(new SolrQuery("*:*"));
// Start the killed server once again
solr[1].startJetty();
// Wait for the alive check to complete
waitForServer(30000, lbHttpSolrServer, 3, "solr1");
}
示例2: testTwoServers
import org.apache.solr.client.solrj.impl.LBHttpSolrServer; //导入方法依赖的package包/类
public void testTwoServers() throws Exception {
LBHttpSolrServer lbHttpSolrServer = new LBHttpSolrServer(httpClient, solr[0].getUrl(), solr[1].getUrl());
lbHttpSolrServer.setAliveCheckInterval(500);
SolrQuery solrQuery = new SolrQuery("*:*");
QueryResponse resp = null;
solr[0].jetty.stop();
solr[0].jetty = null;
resp = lbHttpSolrServer.query(solrQuery);
String name = resp.getResults().get(0).getFieldValue("name").toString();
Assert.assertEquals("solr/collection11", name);
resp = lbHttpSolrServer.query(solrQuery);
name = resp.getResults().get(0).getFieldValue("name").toString();
Assert.assertEquals("solr/collection11", name);
solr[1].jetty.stop();
solr[1].jetty = null;
solr[0].startJetty();
Thread.sleep(1200);
try {
resp = lbHttpSolrServer.query(solrQuery);
} catch(SolrServerException e) {
// try again after a pause in case the error is lack of time to start server
Thread.sleep(3000);
resp = lbHttpSolrServer.query(solrQuery);
}
name = resp.getResults().get(0).getFieldValue("name").toString();
Assert.assertEquals("solr/collection10", name);
}
示例3: waitForServer
import org.apache.solr.client.solrj.impl.LBHttpSolrServer; //导入方法依赖的package包/类
private void waitForServer(int maximum, LBHttpSolrServer server, int nServers, String serverName) throws Exception {
long endTime = System.currentTimeMillis() + maximum;
while (System.currentTimeMillis() < endTime) {
QueryResponse resp;
try {
resp = server.query(new SolrQuery("*:*"));
} catch (Exception e) {
log.warn("", e);
continue;
}
String name = resp.getResults().get(0).getFieldValue("name").toString();
if (name.equals(serverName))
return;
}
}