Search in sources :

Example 91 with SolrParams

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

the class TestCloudJSONFacetJoinDomain method assertFacetCountsAreCorrect.

/** 
   * Recursive Helper method that walks the actual facet response, comparing the counts to the expected output 
   * based on the equivilent filters generated from the original TermFacet.
   */
private void assertFacetCountsAreCorrect(Map<String, TermFacet> expected, SolrParams baseParams, NamedList actualFacetResponse) throws SolrServerException, IOException {
    for (Map.Entry<String, TermFacet> entry : expected.entrySet()) {
        final String facetKey = entry.getKey();
        final TermFacet facet = entry.getValue();
        final NamedList results = (NamedList) actualFacetResponse.get(facetKey);
        assertNotNull(facetKey + " key missing from: " + actualFacetResponse, results);
        final List<NamedList> buckets = (List<NamedList>) results.get("buckets");
        assertNotNull(facetKey + " has null buckets: " + actualFacetResponse, buckets);
        for (NamedList bucket : buckets) {
            final long count = ((Number) bucket.get("count")).longValue();
            // int or stringified int
            final String fieldVal = bucket.get("val").toString();
            // change our query to filter on the fieldVal, and wrap in the facet domain (if any)
            final SolrParams verifyParams = facet.applyValueConstraintAndDomain(baseParams, facetKey, fieldVal);
            // check the count for this bucket
            assertEquals(facetKey + ": " + verifyParams, count, getRandClient(random()).query(verifyParams).getResults().getNumFound());
            // recursively check subFacets
            if (!facet.subFacets.isEmpty()) {
                assertFacetCountsAreCorrect(facet.subFacets, verifyParams, bucket);
            }
        }
    }
    assertTrue("facets have unexpeted keys left over: " + actualFacetResponse, // should alwasy be a count, maybe a 'val' if we're a subfacet
    (actualFacetResponse.size() == expected.size() + 1) || (actualFacetResponse.size() == expected.size() + 2));
}
Also used : NamedList(org.apache.solr.common.util.NamedList) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) ArrayList(java.util.ArrayList) NamedList(org.apache.solr.common.util.NamedList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 92 with SolrParams

use of org.apache.solr.common.params.SolrParams 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 93 with SolrParams

use of org.apache.solr.common.params.SolrParams 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 94 with SolrParams

use of org.apache.solr.common.params.SolrParams 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 95 with SolrParams

use of org.apache.solr.common.params.SolrParams 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

SolrParams (org.apache.solr.common.params.SolrParams)310 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)179 SolrException (org.apache.solr.common.SolrException)78 Test (org.junit.Test)45 Tuple (org.apache.solr.client.solrj.io.Tuple)43 SolrDocument (org.apache.solr.common.SolrDocument)42 ArrayList (java.util.ArrayList)41 NamedList (org.apache.solr.common.util.NamedList)40 MapSolrParams (org.apache.solr.common.params.MapSolrParams)37 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)37 IOException (java.io.IOException)35 SolrDocumentList (org.apache.solr.common.SolrDocumentList)34 HashMap (java.util.HashMap)33 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)30 SolrClientCache (org.apache.solr.client.solrj.io.SolrClientCache)27 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)26 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)24 Map (java.util.Map)22 SolrIndexSearcher (org.apache.solr.search.SolrIndexSearcher)22 SolrCore (org.apache.solr.core.SolrCore)20