use of org.apache.solr.client.solrj.impl.XMLResponseParser in project lucene-solr by apache.
the class SolrExampleStreamingTest method createNewSolrClient.
@Override
public SolrClient createNewSolrClient() {
try {
// setup the server...
String url = jetty.getBaseUrl().toString() + "/collection1";
// smaller queue size hits locks more often
ConcurrentUpdateSolrClient concurrentClient = new ErrorTrackingConcurrentUpdateSolrClient(url, 2, 5);
concurrentClient.setParser(new XMLResponseParser());
concurrentClient.setRequestWriter(new RequestWriter());
return concurrentClient;
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
use of org.apache.solr.client.solrj.impl.XMLResponseParser in project lucene-solr by apache.
the class TestDocumentObjectBinder method testDynamicFieldBinding.
public void testDynamicFieldBinding() {
DocumentObjectBinder binder = new DocumentObjectBinder();
XMLResponseParser parser = new XMLResponseParser();
NamedList<Object> nl = parser.processResponse(new StringReader(xml));
QueryResponse res = new QueryResponse(nl, null);
List<Item> l = binder.getBeans(Item.class, res.getResults());
assertArrayEquals(new String[] { "Mobile Store", "iPod Store", "CCTV Store" }, l.get(3).getAllSuppliers());
assertTrue(l.get(3).supplier.containsKey("supplier_1"));
assertTrue(l.get(3).supplier.containsKey("supplier_2"));
assertEquals(2, l.get(3).supplier.size());
List<String> supplierOne = l.get(3).supplier.get("supplier_1");
assertEquals("Mobile Store", supplierOne.get(0));
assertEquals("iPod Store", supplierOne.get(1));
List<String> supplierTwo = l.get(3).supplier.get("supplier_2");
assertEquals("CCTV Store", supplierTwo.get(0));
}
use of org.apache.solr.client.solrj.impl.XMLResponseParser in project lucene-solr by apache.
the class SolrExampleXMLTest method createNewSolrClient.
@Override
public SolrClient createNewSolrClient() {
try {
String url = jetty.getBaseUrl().toString() + "/collection1";
HttpSolrClient client = getHttpSolrClient(url);
client.setUseMultiPartPost(random().nextBoolean());
client.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
client.setParser(new XMLResponseParser());
client.setRequestWriter(new RequestWriter());
return client;
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
use of org.apache.solr.client.solrj.impl.XMLResponseParser in project lucene-solr by apache.
the class TestClusteringResponse method testClusteringResponse.
@Test
public void testClusteringResponse() throws Exception {
XMLResponseParser parser = new XMLResponseParser();
/*Load a simple XML with the clustering response encoded in an XML format*/
InputStream is = new SolrResourceLoader().openResource("solrj/sampleClusteringResponse.xml");
assertNotNull(is);
Reader in = new InputStreamReader(is, StandardCharsets.UTF_8);
NamedList<Object> response = parser.processResponse(in);
in.close();
QueryResponse qr = new QueryResponse(response, null);
ClusteringResponse clusteringResponse = qr.getClusteringResponse();
List<Cluster> clusters = clusteringResponse.getClusters();
Assert.assertEquals(4, clusters.size());
checkCluster(clusters.get(0), Arrays.asList("label1"), Arrays.asList("id1", "id2", "id3"), 0.6d, false);
checkCluster(clusters.get(1), Arrays.asList("label2"), Arrays.asList("id5", "id6"), 0.93d, false);
checkCluster(clusters.get(2), Arrays.asList("label3"), Arrays.asList("id7", "id8"), 1.26d, false);
checkCluster(clusters.get(3), Arrays.asList("label4"), Arrays.asList("id9"), 0d, true);
List<Cluster> sub = clusters.get(0).getSubclusters();
checkCluster(sub.get(0), Arrays.asList("label1.sub1"), Arrays.asList("id1", "id2"), 0.0d, false);
checkCluster(sub.get(1), Arrays.asList("label1.sub2"), Arrays.asList("id2"), 0.0d, false);
assertEquals(sub.size(), 2);
}
use of org.apache.solr.client.solrj.impl.XMLResponseParser in project lucene-solr by apache.
the class QueryResponseTest method testRangeFacets.
@Test
public void testRangeFacets() throws Exception {
XMLResponseParser parser = new XMLResponseParser();
InputStream is = new SolrResourceLoader().openResource("solrj/sampleRangeFacetResponse.xml");
assertNotNull(is);
Reader in = new InputStreamReader(is, StandardCharsets.UTF_8);
NamedList<Object> response = parser.processResponse(in);
in.close();
QueryResponse qr = new QueryResponse(response, null);
Assert.assertNotNull(qr);
int counter = 0;
RangeFacet.Numeric price = null;
RangeFacet.Date manufacturedateDt = null;
for (RangeFacet r : qr.getFacetRanges()) {
assertNotNull(r);
if ("price".equals(r.getName())) {
price = (RangeFacet.Numeric) r;
} else if ("manufacturedate_dt".equals(r.getName())) {
manufacturedateDt = (RangeFacet.Date) r;
}
counter++;
}
assertEquals(2, counter);
assertNotNull(price);
assertNotNull(manufacturedateDt);
assertEquals(0.0F, price.getStart());
assertEquals(5.0F, price.getEnd());
assertEquals(1.0F, price.getGap());
assertEquals("0.0", price.getCounts().get(0).getValue());
assertEquals(3, price.getCounts().get(0).getCount());
assertEquals("1.0", price.getCounts().get(1).getValue());
assertEquals(0, price.getCounts().get(1).getCount());
assertEquals("2.0", price.getCounts().get(2).getValue());
assertEquals(0, price.getCounts().get(2).getCount());
assertEquals("3.0", price.getCounts().get(3).getValue());
assertEquals(0, price.getCounts().get(3).getCount());
assertEquals("4.0", price.getCounts().get(4).getValue());
assertEquals(0, price.getCounts().get(4).getCount());
assertEquals(new Date(Instant.parse("2005-02-13T15:26:37Z").toEpochMilli()), manufacturedateDt.getStart());
assertEquals(new Date(Instant.parse("2008-02-13T15:26:37Z").toEpochMilli()), manufacturedateDt.getEnd());
assertEquals("+1YEAR", manufacturedateDt.getGap());
assertEquals("2005-02-13T15:26:37Z", manufacturedateDt.getCounts().get(0).getValue());
assertEquals(4, manufacturedateDt.getCounts().get(0).getCount());
assertEquals("2006-02-13T15:26:37Z", manufacturedateDt.getCounts().get(1).getValue());
assertEquals(7, manufacturedateDt.getCounts().get(1).getCount());
assertEquals("2007-02-13T15:26:37Z", manufacturedateDt.getCounts().get(2).getValue());
assertEquals(0, manufacturedateDt.getCounts().get(2).getCount());
assertEquals(90, manufacturedateDt.getBefore());
assertEquals(1, manufacturedateDt.getAfter());
assertEquals(11, manufacturedateDt.getBetween());
}
Aggregations