Search in sources :

Example 11 with XMLResponseParser

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);
    }
}
Also used : RequestWriter(org.apache.solr.client.solrj.request.RequestWriter) ConcurrentUpdateSolrClient(org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient) XMLResponseParser(org.apache.solr.client.solrj.impl.XMLResponseParser)

Example 12 with XMLResponseParser

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));
}
Also used : QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) StringReader(java.io.StringReader) XMLResponseParser(org.apache.solr.client.solrj.impl.XMLResponseParser)

Example 13 with XMLResponseParser

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);
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) RequestWriter(org.apache.solr.client.solrj.request.RequestWriter) XMLResponseParser(org.apache.solr.client.solrj.impl.XMLResponseParser)

Example 14 with XMLResponseParser

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);
}
Also used : SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) XMLResponseParser(org.apache.solr.client.solrj.impl.XMLResponseParser) Test(org.junit.Test)

Example 15 with XMLResponseParser

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());
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Date(java.util.Date) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) XMLResponseParser(org.apache.solr.client.solrj.impl.XMLResponseParser) Test(org.junit.Test)

Aggregations

XMLResponseParser (org.apache.solr.client.solrj.impl.XMLResponseParser)18 Test (org.junit.Test)6 InputStream (java.io.InputStream)5 InputStreamReader (java.io.InputStreamReader)5 Reader (java.io.Reader)5 SolrResourceLoader (org.apache.solr.core.SolrResourceLoader)5 StringReader (java.io.StringReader)4 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)4 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)4 BinaryResponseParser (org.apache.solr.client.solrj.impl.BinaryResponseParser)3 SolrInputDocument (org.apache.solr.common.SolrInputDocument)3 NamedList (org.apache.solr.common.util.NamedList)3 List (java.util.List)2 ResponseParser (org.apache.solr.client.solrj.ResponseParser)2 ErrorTrackingConcurrentUpdateSolrClient (org.apache.solr.client.solrj.embedded.SolrExampleStreamingTest.ErrorTrackingConcurrentUpdateSolrClient)2 NoOpResponseParser (org.apache.solr.client.solrj.impl.NoOpResponseParser)2 RequestWriter (org.apache.solr.client.solrj.request.RequestWriter)2 SolrDocument (org.apache.solr.common.SolrDocument)2 SolrDocumentList (org.apache.solr.common.SolrDocumentList)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1