Search in sources :

Example 46 with SolrDocument

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

the class RandomStream method read.

public Tuple read() throws IOException {
    if (documentIterator.hasNext()) {
        Map map = new HashMap();
        SolrDocument doc = documentIterator.next();
        for (String key : doc.keySet()) {
            map.put(key, doc.get(key));
        }
        return new Tuple(map);
    } else {
        Map fields = new HashMap();
        fields.put("EOF", true);
        Tuple tuple = new Tuple(fields);
        return tuple;
    }
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) Tuple(org.apache.solr.client.solrj.io.Tuple)

Example 47 with SolrDocument

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

the class AbstractFullDistribZkTestBase method doQuery.

void doQuery(String expectedDocs, String... queryParams) throws Exception {
    Set<String> expectedIds = new HashSet<>(StrUtils.splitSmart(expectedDocs, ",", true));
    QueryResponse rsp = cloudClient.query(params(queryParams));
    Set<String> obtainedIds = new HashSet<>();
    for (SolrDocument doc : rsp.getResults()) {
        obtainedIds.add((String) doc.get("id"));
    }
    assertEquals(expectedIds, obtainedIds);
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) HashSet(java.util.HashSet)

Example 48 with SolrDocument

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

the class BaseDistributedSearchTestCase method compare.

public static String compare(SolrDocumentList a, SolrDocumentList b, int flags, Map<String, Integer> handle) {
    boolean ordered = (flags & UNORDERED) == 0;
    String cmp;
    int f = flags(handle, "maxScore");
    if (f == 0) {
        cmp = compare(a.getMaxScore(), b.getMaxScore(), 0, handle);
        if (cmp != null)
            return ".maxScore" + cmp;
    } else if ((f & SKIP) == 0) {
        // so we skip val but otherwise both should be present
        assert (f & SKIPVAL) != 0;
        if (b.getMaxScore() != null) {
            if (a.getMaxScore() == null) {
                return ".maxScore missing";
            }
        }
    }
    cmp = compare(a.getNumFound(), b.getNumFound(), 0, handle);
    if (cmp != null)
        return ".numFound" + cmp;
    cmp = compare(a.getStart(), b.getStart(), 0, handle);
    if (cmp != null)
        return ".start" + cmp;
    cmp = compare(a.size(), b.size(), 0, handle);
    if (cmp != null)
        return ".size()" + cmp;
    // only for completely ordered results (ties might be in a different order)
    if (ordered) {
        for (int i = 0; i < a.size(); i++) {
            cmp = compare(a.get(i), b.get(i), 0, handle);
            if (cmp != null)
                return "[" + i + "]" + cmp;
        }
        return null;
    }
    // unordered case
    for (int i = 0; i < a.size(); i++) {
        SolrDocument doc = a.get(i);
        Object key = doc.getFirstValue("id");
        SolrDocument docb = null;
        if (key == null) {
            // no id field to correlate... must compare ordered
            docb = b.get(i);
        } else {
            for (int j = 0; j < b.size(); j++) {
                docb = b.get(j);
                if (key.equals(docb.getFirstValue("id")))
                    break;
            }
        }
        // if (docb == null) return "[id="+key+"]";
        cmp = compare(doc, docb, 0, handle);
        if (cmp != null)
            return "[id=" + key + "]" + cmp;
    }
    return null;
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument)

Example 49 with SolrDocument

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

the class DistributedVersionInfoTest method assertDocExists.

/**
   * Query the real-time get handler for a specific doc by ID to verify it
   * exists in the provided server, using distrib=false so it doesn't route to another replica.
   */
@SuppressWarnings("rawtypes")
protected Long assertDocExists(HttpSolrClient solr, String coll, String docId, Long expVers) throws Exception {
    QueryRequest qr = new QueryRequest(params("qt", "/get", "id", docId, "distrib", "false", "fl", "id,_version_"));
    NamedList rsp = solr.request(qr);
    SolrDocument doc = (SolrDocument) rsp.get("doc");
    String match = JSONTestUtil.matchObj("/id", doc, docId);
    assertTrue("Doc with id=" + docId + " not found in " + solr.getBaseURL() + " due to: " + match + "; rsp=" + rsp, match == null);
    Long vers = (Long) doc.getFirstValue("_version_");
    assertNotNull(vers);
    if (expVers != null)
        assertEquals("expected version of doc " + docId + " to be " + expVers, expVers, vers);
    return vers;
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) NamedList(org.apache.solr.common.util.NamedList)

Example 50 with SolrDocument

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

the class TestCloudPseudoReturnFields method testGlobsRTG.

public void testGlobsRTG() 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_*"));
        String msg = id + ": fl=val_* => " + doc;
        assertEquals(msg, 1, doc.size());
        assertTrue(msg, doc.getFieldValue("val_i") instanceof Integer);
        assertEquals(msg, 1, doc.getFieldValue("val_i"));
        for (SolrParams p : Arrays.asList(params("fl", "val_*,subj*,ss*"), params("fl", "val_*", "fl", "subj*,ss*"))) {
            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);
            // NOTE: 'subject' is diff between two docs
            // 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)

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