Search in sources :

Example 76 with SolrDocument

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

the class TestCloudPseudoReturnFields method testFunctionsRTG.

public void testFunctionsRTG() throws Exception {
    // if we use RTG (committed or otherwise) functions should behave the same
    for (String id : Arrays.asList("42", "99")) {
        for (SolrParams p : Arrays.asList(params("fl", "log(val_i),abs(val_i)"), params("fl", "log(val_i)", "fl", "abs(val_i)"))) {
            SolrDocument doc = getRandClient(random()).getById(id, p);
            String msg = id + "," + p + " => " + doc;
            assertEquals(msg, 2, doc.size());
            assertTrue(msg, doc.getFieldValue("log(val_i)") instanceof Double);
            assertTrue(msg, doc.getFieldValue("abs(val_i)") instanceof Float);
            // true for both these specific docs
            assertEquals(msg, 0.0D, doc.getFieldValue("log(val_i)"));
            assertEquals(msg, 1.0F, doc.getFieldValue("abs(val_i)"));
        }
    }
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 77 with SolrDocument

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

the class TestCloudPseudoReturnFields method testAllRealFieldsRTG.

public void testAllRealFieldsRTG() throws Exception {
    // shouldn't matter if we use RTG (committed or otherwise)
    for (String fl : TestPseudoReturnFields.ALL_REAL_FIELDS) {
        for (int i : Arrays.asList(42, 43, 44, 45, 46, 99)) {
            SolrDocument doc = getRandClient(random()).getById("" + i, params("fl", fl));
            assertEquals(fl + " => " + doc, 4, doc.size());
            assertTrue(fl + " => " + doc, doc.getFieldValue("id") instanceof String);
            assertTrue(fl + " => " + doc, doc.getFieldValue("val_i") instanceof Integer);
            assertTrue(fl + " => " + doc, doc.getFieldValue("subject") instanceof String);
            // TODO: val_ss: List<String>
            assertTrue(fl + " => " + doc, doc.getFieldValue("ssto") instanceof String);
        }
    }
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument)

Example 78 with SolrDocument

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

the class TestCloudPseudoReturnFields method testScoreAndAllRealFieldsRTG.

public void testScoreAndAllRealFieldsRTG() throws Exception {
    // also shouldn't matter if we use RTG (committed or otherwise) .. score should be ignored
    for (String fl : TestPseudoReturnFields.SCORE_AND_REAL_FIELDS) {
        for (int i : Arrays.asList(42, 43, 44, 45, 46, 99)) {
            SolrDocument doc = getRandClient(random()).getById("" + i, params("fl", fl));
            assertEquals(fl + " => " + doc, 4, doc.size());
            assertTrue(fl + " => " + doc, doc.getFieldValue("id") instanceof String);
            assertTrue(fl + " => " + doc, doc.getFieldValue("val_i") instanceof Integer);
            assertTrue(fl + " => " + doc, doc.getFieldValue("subject") instanceof String);
            // TODO: val_ss: List<String>
            assertTrue(fl + " => " + doc, doc.getFieldValue("ssto") instanceof String);
        }
    }
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument)

Example 79 with SolrDocument

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

the class TestCloudPseudoReturnFields method testFilterAndOneRealFieldRTG.

public void testFilterAndOneRealFieldRTG() throws Exception {
    SolrParams params = params("fl", "id,val_i", "fq", "{!field f='subject' v=$my_var}", "my_var", "uncommitted");
    SolrDocumentList docs = getRandClient(random()).getById(Arrays.asList("42", "99"), params);
    final String msg = params + " => " + docs;
    assertEquals(msg, 1, docs.size());
    assertEquals(msg, 1, docs.getNumFound());
    SolrDocument doc = docs.get(0);
    assertEquals(msg, 2, doc.size());
    assertEquals(msg, "99", doc.getFieldValue("id"));
    assertEquals(msg, 1, doc.getFieldValue("val_i"));
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrDocumentList(org.apache.solr.common.SolrDocumentList)

Example 80 with SolrDocument

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

the class TestCloudPseudoReturnFields method testScoreAndAllRealFields.

public void testScoreAndAllRealFields() throws Exception {
    for (String fl : TestPseudoReturnFields.SCORE_AND_REAL_FIELDS) {
        SolrDocumentList docs = assertSearch(params("q", "*:*", "rows", "10", "fl", fl));
        // shouldn't matter what doc we pick...
        for (SolrDocument doc : docs) {
            assertEquals(fl + " => " + doc, 5, doc.size());
            assertTrue(fl + " => " + doc, doc.getFieldValue("id") instanceof String);
            assertTrue(fl + " => " + doc, doc.getFieldValue("score") instanceof Float);
            assertTrue(fl + " => " + doc, doc.getFieldValue("val_i") instanceof Integer);
            assertTrue(fl + " => " + doc, doc.getFieldValue("subject") instanceof String);
            // TODO: val_ss: List<String>
            assertTrue(fl + " => " + doc, doc.getFieldValue("ssto") instanceof String);
        }
    }
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) SolrDocumentList(org.apache.solr.common.SolrDocumentList)

Aggregations

SolrDocument (org.apache.solr.common.SolrDocument)230 SolrDocumentList (org.apache.solr.common.SolrDocumentList)93 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)81 ArrayList (java.util.ArrayList)50 SolrQuery (org.apache.solr.client.solrj.SolrQuery)47 Test (org.junit.Test)46 SolrParams (org.apache.solr.common.params.SolrParams)38 SolrServerException (org.apache.solr.client.solrj.SolrServerException)35 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)35 IOException (java.io.IOException)32 SolrInputDocument (org.apache.solr.common.SolrInputDocument)28 HashMap (java.util.HashMap)26 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)24 NamedList (org.apache.solr.common.util.NamedList)21 Map (java.util.Map)20 List (java.util.List)18 SolrClient (org.apache.solr.client.solrj.SolrClient)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)12 SolrException (org.apache.solr.common.SolrException)12