Search in sources :

Example 61 with SolrDocumentList

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

the class TestCloudPseudoReturnFields method assertSearchOneDoc.

/** 
   * Given a set of query params, executes as a Query against a random SolrClient and 
   * asserts that exactly one document is returned 
   */
public static SolrDocument assertSearchOneDoc(SolrParams p) throws Exception {
    SolrDocumentList docs = assertSearch(p);
    assertEquals("does not match exactly one doc: " + p.toString() + " => " + docs.toString(), 1, docs.getNumFound());
    assertEquals("does not contain exactly one doc: " + p.toString() + " => " + docs.toString(), 1, docs.size());
    return docs.get(0);
}
Also used : SolrDocumentList(org.apache.solr.common.SolrDocumentList)

Example 62 with SolrDocumentList

use of org.apache.solr.common.SolrDocumentList 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)

Example 63 with SolrDocumentList

use of org.apache.solr.common.SolrDocumentList 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 64 with SolrDocumentList

use of org.apache.solr.common.SolrDocumentList 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)

Example 65 with SolrDocumentList

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

the class TestCloudPseudoReturnFields method testFunctionsAndExplicit.

public void testFunctionsAndExplicit() throws Exception {
    for (SolrParams p : Arrays.asList(params("q", "*:*", "rows", "1", "fl", "log(val_i),val_i"), params("q", "*:*", "rows", "1", "fl", "log(val_i)", "fl", "val_i"))) {
        SolrDocumentList docs = assertSearch(p);
        assertEquals(p + " => " + docs, 5, docs.getNumFound());
        // doesn't really matter which one
        SolrDocument doc = docs.get(0);
        assertEquals(p + " => " + doc, 2, doc.size());
        assertTrue(p + " => " + doc, doc.getFieldValue("log(val_i)") instanceof Double);
        assertTrue(p + " => " + doc, doc.getFieldValue("val_i") instanceof Integer);
    }
}
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

SolrDocumentList (org.apache.solr.common.SolrDocumentList)161 SolrDocument (org.apache.solr.common.SolrDocument)89 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)52 Test (org.junit.Test)52 NamedList (org.apache.solr.common.util.NamedList)36 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)33 SolrQuery (org.apache.solr.client.solrj.SolrQuery)32 ArrayList (java.util.ArrayList)29 SolrParams (org.apache.solr.common.params.SolrParams)28 SolrServerException (org.apache.solr.client.solrj.SolrServerException)20 SolrInputDocument (org.apache.solr.common.SolrInputDocument)18 IOException (java.io.IOException)15 Map (java.util.Map)14 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)14 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)13 HashMap (java.util.HashMap)12 List (java.util.List)10 Date (java.util.Date)8 LinkedHashMap (java.util.LinkedHashMap)8 SolrClient (org.apache.solr.client.solrj.SolrClient)8