Search in sources :

Example 81 with SolrDocument

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

the class TestCloudPseudoReturnFields method testGlobs.

public void testGlobs() throws Exception {
    SolrDocumentList docs = assertSearch(params("q", "*:*", "rows", "10", "fl", "val_*"));
    assertEquals(5, docs.getNumFound());
    // shouldn't matter what doc we pick...
    for (SolrDocument doc : docs) {
        assertEquals(doc.toString(), 1, doc.size());
        assertTrue(doc.toString(), doc.getFieldValue("val_i") instanceof Integer);
    }
    for (SolrParams p : Arrays.asList(params("q", "*:*", "rows", "10", "fl", "val_*,subj*,ss*"), params("q", "*:*", "rows", "10", "fl", "val_*", "fl", "subj*,ss*"), params("q", "*:*", "rows", "10", "fl", "val_*", "fl", "subj*", "fl", "ss*"))) {
        docs = assertSearch(p);
        // shouldn't matter what doc we pick...
        for (SolrDocument doc : docs) {
            String msg = p + " => " + doc;
            assertEquals(msg, 3, doc.size());
            assertTrue(msg, doc.getFieldValue("val_i") instanceof Integer);
            assertTrue(msg, doc.getFieldValue("subject") instanceof String);
            // TODO: val_ss: List<String>
            assertTrue(msg, doc.getFieldValue("ssto") instanceof String);
            assertEquals(msg, "X", doc.getFieldValue("ssto"));
        }
    }
}
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 82 with SolrDocument

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

the class TestCloudPseudoReturnFields method testGlobsAndExplicitRTG.

public void testGlobsAndExplicitRTG() throws Exception {
    // behavior shouldn't matter if we are committed or uncommitted
    for (String id : Arrays.asList("42", "99")) {
        SolrDocument doc = getRandClient(random()).getById(id, params("fl", "val_*,id"));
        String msg = id + ": fl=val_*,id => " + doc;
        assertEquals(msg, 2, doc.size());
        assertTrue(msg, doc.getFieldValue("id") instanceof String);
        assertTrue(msg, doc.getFieldValue("val_i") instanceof Integer);
        assertEquals(msg, 1, doc.getFieldValue("val_i"));
        for (SolrParams p : Arrays.asList(params("fl", "val_*,subj*,id"), params("fl", "val_*", "fl", "subj*", "fl", "id"), params("fl", "val_*", "fl", "subj*,id"))) {
            doc = getRandClient(random()).getById(id, p);
            msg = id + ": " + p + " => " + doc;
            assertEquals(msg, 3, doc.size());
            assertTrue(msg, doc.getFieldValue("val_i") instanceof Integer);
            assertEquals(msg, 1, doc.getFieldValue("val_i"));
            assertTrue(msg, doc.getFieldValue("subject") instanceof String);
            assertTrue(msg, doc.getFieldValue("id") instanceof String);
        }
    }
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 83 with SolrDocument

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

the class TestCloudPseudoReturnFields method testDocIdAugmenterRTG.

public void testDocIdAugmenterRTG() throws Exception {
    // for an uncommitted doc, we should get -1
    for (String id : Arrays.asList("42", "99")) {
        SolrDocument doc = getRandClient(random()).getById(id, params("fl", "[docid]"));
        String msg = id + ": fl=[docid] => " + doc;
        assertEquals(msg, 1, doc.size());
        assertTrue(msg, doc.getFieldValue("[docid]") instanceof Integer);
        assertTrue(msg, -1 <= ((Integer) doc.getFieldValue("[docid]")).intValue());
    }
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument)

Example 84 with SolrDocument

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

the class TestCloudPseudoReturnFields method testAugmentersGlobsExplicitAndScoreOhMyRTG.

public void testAugmentersGlobsExplicitAndScoreOhMyRTG() throws Exception {
    Random random = random();
    // NOTE: 'ssto' is the missing one
    final List<String> fl = Arrays.asList("id", "[docid]", "[explain]", "score", "val_*", "subj*");
    final int iters = atLeast(random, 10);
    for (int i = 0; i < iters; i++) {
        Collections.shuffle(fl, random);
        final SolrParams singleFl = params("fl", StringUtils.join(fl.toArray(), ','));
        final ModifiableSolrParams multiFl = params();
        for (String item : fl) {
            multiFl.add("fl", item);
        }
        // RTG behavior should be consistent, (committed or otherwise) 
        for (String id : Arrays.asList("42", "99")) {
            for (SolrParams params : Arrays.asList(singleFl, multiFl)) {
                SolrDocument doc = getRandClient(random()).getById(id, params);
                String msg = id + ": " + params + " => " + doc;
                assertEquals(msg, 4, doc.size());
                assertTrue(msg, doc.getFieldValue("id") instanceof String);
                assertTrue(msg, doc.getFieldValue("val_i") instanceof Integer);
                assertEquals(msg, 1, doc.getFieldValue("val_i"));
                assertTrue(msg, doc.getFieldValue("subject") instanceof String);
                assertTrue(msg, doc.getFieldValue("[docid]") instanceof Integer);
                assertTrue(msg, -1 <= ((Integer) doc.getFieldValue("[docid]")).intValue());
            // RTG: [explain] and score should be missing (ignored)
            }
        }
    }
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) Random(java.util.Random) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 85 with SolrDocument

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

the class TestCloudPseudoReturnFields method testGlobsAndScore.

public void testGlobsAndScore() throws Exception {
    SolrDocumentList docs = assertSearch(params("q", "*:*", "rows", "10", "fl", "val_*,score"));
    assertEquals(5, docs.getNumFound());
    // shouldn't matter what doc we pick...
    for (SolrDocument doc : docs) {
        assertEquals(doc.toString(), 2, doc.size());
        assertTrue(doc.toString(), doc.getFieldValue("val_i") instanceof Integer);
        assertTrue(doc.toString(), doc.getFieldValue("score") instanceof Float);
    }
    for (SolrParams p : Arrays.asList(params("q", "*:*", "rows", "10", "fl", "val_*,subj*,score"), params("q", "*:*", "rows", "10", "fl", "val_*", "fl", "subj*", "fl", "score"), params("q", "*:*", "rows", "10", "fl", "val_*", "fl", "subj*,score"))) {
        docs = assertSearch(p);
        assertEquals(p + " => " + docs, 5, docs.getNumFound());
        // shouldn't matter what doc we pick...
        for (SolrDocument doc : docs) {
            String msg = p + " => " + doc;
            assertEquals(msg, 3, doc.size());
            assertTrue(msg, doc.getFieldValue("val_i") instanceof Integer);
            assertTrue(msg, doc.getFieldValue("subject") instanceof String);
            assertTrue(msg, doc.getFieldValue("score") instanceof Float);
        }
    }
}
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)

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