Search in sources :

Example 56 with SolrInputDocument

use of org.apache.solr.common.SolrInputDocument in project lucene-solr by apache.

the class CloudSolrClientTest method testCollectionDoesntExist.

@Test
public void testCollectionDoesntExist() throws Exception {
    CloudSolrClient client = getRandomClient();
    SolrInputDocument doc = new SolrInputDocument("id", "1", "title_s", "my doc");
    try {
        client.add("boguscollectionname", doc);
        fail();
    } catch (SolrException ex) {
        if (ex.getMessage().equals("Collection not found: boguscollectionname")) {
        // pass
        } else {
            throw ex;
        }
    }
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrException(org.apache.solr.common.SolrException) Test(org.junit.Test)

Example 57 with SolrInputDocument

use of org.apache.solr.common.SolrInputDocument in project lucene-solr by apache.

the class SolrExampleStreamingTest method testWaitOptions.

public void testWaitOptions() throws Exception {
    // SOLR-3903
    final List<Throwable> failures = new ArrayList<>();
    final String serverUrl = jetty.getBaseUrl().toString() + "/collection1";
    try (ConcurrentUpdateSolrClient concurrentClient = new FailureRecordingConcurrentUpdateSolrClient(serverUrl, 2, 2)) {
        int docId = 42;
        for (UpdateRequest.ACTION action : EnumSet.allOf(UpdateRequest.ACTION.class)) {
            for (boolean waitSearch : Arrays.asList(true, false)) {
                for (boolean waitFlush : Arrays.asList(true, false)) {
                    UpdateRequest updateRequest = new UpdateRequest();
                    SolrInputDocument document = new SolrInputDocument();
                    document.addField("id", docId++);
                    updateRequest.add(document);
                    updateRequest.setAction(action, waitSearch, waitFlush);
                    concurrentClient.request(updateRequest);
                }
            }
        }
        concurrentClient.commit();
        concurrentClient.blockUntilFinished();
    }
    if (0 != failures.size()) {
        assertEquals(failures.size() + " Unexpected Exception, starting with...", null, failures.get(0));
    }
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) ArrayList(java.util.ArrayList) ConcurrentUpdateSolrClient(org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient)

Example 58 with SolrInputDocument

use of org.apache.solr.common.SolrInputDocument in project lucene-solr by apache.

the class TestSolrProperties method testProperties.

@Test
public void testProperties() throws Exception {
    UpdateRequest up = new UpdateRequest();
    up.setAction(ACTION.COMMIT, true, true);
    up.deleteByQuery("*:*");
    up.process(getSolrCore0());
    up.process(getSolrCore1());
    up.clear();
    // Add something to each core
    SolrInputDocument doc = new SolrInputDocument();
    doc.setField("id", "AAA");
    doc.setField("core0", "yup stopfra stopfrb stopena stopenb");
    // Add to core0
    up.add(doc);
    up.process(getSolrCore0());
    SolrTestCaseJ4.ignoreException("unknown field");
    // You can't add it to core1
    try {
        up.process(getSolrCore1());
        fail("Can't add core0 field to core1!");
    } catch (Exception ex) {
    }
    // Add to core1
    doc.setField("id", "BBB");
    doc.setField("core1", "yup stopfra stopfrb stopena stopenb");
    doc.removeField("core0");
    up.add(doc);
    up.process(getSolrCore1());
    // You can't add it to core1
    try {
        SolrTestCaseJ4.ignoreException("core0");
        up.process(getSolrCore0());
        fail("Can't add core1 field to core0!");
    } catch (Exception ex) {
    }
    SolrTestCaseJ4.resetExceptionIgnores();
    // now Make sure AAA is in 0 and BBB in 1
    SolrQuery q = new SolrQuery();
    QueryRequest r = new QueryRequest(q);
    q.setQuery("id:AAA");
    assertEquals(1, r.process(getSolrCore0()).getResults().size());
    assertEquals(0, r.process(getSolrCore1()).getResults().size());
    // Now test Changing the default core
    assertEquals(1, getSolrCore0().query(new SolrQuery("id:AAA")).getResults().size());
    assertEquals(0, getSolrCore0().query(new SolrQuery("id:BBB")).getResults().size());
    assertEquals(0, getSolrCore1().query(new SolrQuery("id:AAA")).getResults().size());
    assertEquals(1, getSolrCore1().query(new SolrQuery("id:BBB")).getResults().size());
    // Now test reloading it should have a newer open time
    String name = "core0";
    SolrClient coreadmin = getSolrAdmin();
    CoreAdminResponse mcr = CoreAdminRequest.getStatus(name, coreadmin);
    long before = mcr.getStartTime(name).getTime();
    CoreAdminRequest.reloadCore(name, coreadmin);
    mcr = CoreAdminRequest.getStatus(name, coreadmin);
    long after = mcr.getStartTime(name).getTime();
    assertTrue("should have more recent time: " + after + "," + before, after > before);
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) SolrClient(org.apache.solr.client.solrj.SolrClient) CoreAdminResponse(org.apache.solr.client.solrj.response.CoreAdminResponse) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Example 59 with SolrInputDocument

use of org.apache.solr.common.SolrInputDocument in project lucene-solr by apache.

the class BasicHttpSolrClientTest method testCollectionParameters.

@Test
public void testCollectionParameters() throws IOException, SolrServerException {
    try (HttpSolrClient client = getHttpSolrClient(jetty.getBaseUrl().toString())) {
        SolrInputDocument doc = new SolrInputDocument();
        doc.addField("id", "collection");
        client.add("collection1", doc);
        client.commit("collection1");
        assertEquals(1, client.query("collection1", new SolrQuery("id:collection")).getResults().getNumFound());
    }
    final String collection1Url = jetty.getBaseUrl().toString() + "/collection1";
    try (HttpSolrClient client = getHttpSolrClient(collection1Url)) {
        assertEquals(1, client.query(new SolrQuery("id:collection")).getResults().getNumFound());
    }
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Example 60 with SolrInputDocument

use of org.apache.solr.common.SolrInputDocument in project lucene-solr by apache.

the class TestLBHttpSolrClient method addDocs.

private void addDocs(SolrInstance solrInstance) throws IOException, SolrServerException {
    List<SolrInputDocument> docs = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        SolrInputDocument doc = new SolrInputDocument();
        doc.addField("id", i);
        doc.addField("name", solrInstance.name);
        docs.add(doc);
    }
    SolrResponseBase resp;
    try (HttpSolrClient client = getHttpSolrClient(solrInstance.getUrl(), httpClient)) {
        resp = client.add(docs);
        assertEquals(0, resp.getStatus());
        resp = client.commit();
        assertEquals(0, resp.getStatus());
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) LBHttpSolrClient(org.apache.solr.client.solrj.impl.LBHttpSolrClient) SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrResponseBase(org.apache.solr.client.solrj.response.SolrResponseBase) ArrayList(java.util.ArrayList)

Aggregations

SolrInputDocument (org.apache.solr.common.SolrInputDocument)520 Test (org.junit.Test)166 ArrayList (java.util.ArrayList)98 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)76 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)69 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)63 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)55 SolrQuery (org.apache.solr.client.solrj.SolrQuery)54 IOException (java.io.IOException)47 SolrException (org.apache.solr.common.SolrException)47 IndexSchema (org.apache.solr.schema.IndexSchema)41 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)41 HashMap (java.util.HashMap)39 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)34 List (java.util.List)33 SolrServerException (org.apache.solr.client.solrj.SolrServerException)32 SolrDocument (org.apache.solr.common.SolrDocument)31 NamedList (org.apache.solr.common.util.NamedList)31 Map (java.util.Map)30 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)29