packagecom.cs.teset;importjava.util.List;importorg.apache.solr.client.solrj.SolrQuery;importorg.apache.solr.client.solrj.SolrServerException;importorg.apache.solr.client.solrj.impl.HttpSolrServer;importorg.apache.solr.client.solrj.response.QueryResponse;importorg.apache.solr.common.SolrDocumentList;importcom.cs.solr.entity.Student;public classSolrQueryTest {private static int connectionTimeout = 60000;private static int soTimeout = 60000;private static int maxRetries = 1;private static int defaultMaxCOnnectionPerhost = 100;private static int maxTotalConnections = 100;private static boolean followRedirects = false;private static boolean allowCompression = true;public static void main(String[] args) throwsClassNotFoundException {
queryAll();
}public static void queryAll() throwsClassNotFoundException {try{
HttpSolrServer server= newHttpSolrServer("http://localhost:8983/solr/mycore");
server.setSoTimeout(soTimeout);
server.setConnectionTimeout(connectionTimeout);
server.setDefaultMaxConnectionsPerHost(defaultMaxCOnnectionPerhost);
server.setMaxTotalConnections(maxTotalConnections);
server.setFollowRedirects(followRedirects);
server.setAllowCompression(allowCompression);
server.setMaxRetries(maxRetries);
SolrQuery params= new SolrQuery("*:*");//查询所有
QueryResponse qs =server.query(params);
SolrDocumentList results=qs.getResults();
List list =qs.getBeans(Student.class);for(Student student : list) {
System.out.println(student.getName());
}//System.out.println(list);
} catch(SolrServerException e) {
e.printStackTrace();
}
}
}