Search in sources :

Example 96 with SolrParams

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

the class TestCloudPseudoReturnFields method testAugmentersAndExplicitRTG.

public void testAugmentersAndExplicitRTG() throws Exception {
    // behavior shouldn't matter if we are committed or uncommitted
    for (String id : Arrays.asList("42", "99")) {
        for (SolrParams p : Arrays.asList(params("fl", "id,[docid],[explain],x_alias:[value v=10 t=int]"), params("fl", "id,[docid]", "fl", "[explain],x_alias:[value v=10 t=int]"), params("fl", "id", "fl", "[docid]", "fl", "[explain]", "fl", "x_alias:[value v=10 t=int]"))) {
            SolrDocument doc = getRandClient(random()).getById(id, p);
            String msg = id + ": " + p + " => " + doc;
            assertEquals(msg, 3, doc.size());
            assertTrue(msg, doc.getFieldValue("id") instanceof String);
            // RTG: [explain] should be missing (ignored)
            assertTrue(msg, doc.getFieldValue("x_alias") instanceof Integer);
            assertEquals(msg, 10, doc.getFieldValue("x_alias"));
            assertTrue(msg, doc.getFieldValue("[docid]") instanceof Integer);
            assertTrue(msg, -1 <= ((Integer) doc.getFieldValue("[docid]")).intValue());
        }
    }
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 97 with SolrParams

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

the class TestCloudPseudoReturnFields method testAugmentersRTG.

public void testAugmentersRTG() throws Exception {
    // behavior shouldn't matter if we are committed or uncommitted
    for (String id : Arrays.asList("42", "99")) {
        for (SolrParams p : Arrays.asList(params("fl", "[docid],[shard],[explain],x_alias:[value v=10 t=int]"), params("fl", "[docid],[shard]", "fl", "[explain],x_alias:[value v=10 t=int]"), params("fl", "[docid]", "fl", "[shard]", "fl", "[explain]", "fl", "x_alias:[value v=10 t=int]"))) {
            SolrDocument doc = getRandClient(random()).getById(id, p);
            String msg = id + ": " + p + " => " + doc;
            assertEquals(msg, 3, doc.size());
            assertTrue(msg, doc.getFieldValue("[shard]") instanceof String);
            // RTG: [explain] should be ignored
            assertTrue(msg, doc.getFieldValue("x_alias") instanceof Integer);
            assertEquals(msg, 10, doc.getFieldValue("x_alias"));
            assertTrue(msg, doc.getFieldValue("[docid]") instanceof Integer);
            assertTrue(msg, -1 <= ((Integer) doc.getFieldValue("[docid]")).intValue());
        }
    }
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 98 with SolrParams

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

Example 99 with SolrParams

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

the class TestSmileRequest method testDistribJsonRequest.

@Test
public void testDistribJsonRequest() throws Exception {
    initServers();
    SolrTestCaseHS.Client client = servers.getClient(random().nextInt());
    client.tester = new SolrTestCaseHS.Client.Tester() {

        @Override
        public void assertJQ(SolrClient client, SolrParams args, String... tests) throws Exception {
            ((HttpSolrClient) client).setParser(SmileResponseParser.inst);
            QueryRequest query = new QueryRequest(args);
            String path = args.get("qt");
            if (path != null) {
                query.setPath(path);
            }
            NamedList<Object> rsp = client.request(query);
            Map m = rsp.asMap(5);
            String jsonStr = Utils.toJSONString(m);
            SolrTestCaseHS.matchJSON(jsonStr, tests);
        }
    };
    client.queryDefaults().set("shards", servers.getShards());
    TestJsonRequest.doJsonRequest(client);
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) SolrClient(org.apache.solr.client.solrj.SolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) NamedList(org.apache.solr.common.util.NamedList) SolrParams(org.apache.solr.common.params.SolrParams) SolrTestCaseHS(org.apache.solr.SolrTestCaseHS) SolrClient(org.apache.solr.client.solrj.SolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) Map(java.util.Map) IOException(java.io.IOException) Test(org.junit.Test) SmileWriterTest(org.apache.solr.response.SmileWriterTest)

Example 100 with SolrParams

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

the class StreamingTest method testMergeStream.

@Test
public void testMergeStream() throws Exception {
    new UpdateRequest().add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "0").add(id, "2", "a_s", "hello2", "a_i", "2", "a_f", "0").add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3").add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4").add(id, "1", "a_s", "hello1", "a_i", "1", "a_f", "1").commit(cluster.getSolrClient(), COLLECTIONORALIAS);
    StreamContext streamContext = new StreamContext();
    SolrClientCache solrClientCache = new SolrClientCache();
    streamContext.setSolrClientCache(solrClientCache);
    try {
        //Test ascending
        SolrParams sParamsA = mapParams("q", "id:(4 1)", "fl", "id,a_s,a_i", "sort", "a_i asc");
        CloudSolrStream streamA = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
        SolrParams sParamsB = mapParams("q", "id:(0 2 3)", "fl", "id,a_s,a_i", "sort", "a_i asc");
        CloudSolrStream streamB = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsB);
        MergeStream mstream = new MergeStream(streamA, streamB, new FieldComparator("a_i", ComparatorOrder.ASCENDING));
        mstream.setStreamContext(streamContext);
        List<Tuple> tuples = getTuples(mstream);
        assertEquals(5, tuples.size());
        assertOrder(tuples, 0, 1, 2, 3, 4);
        //Test descending
        sParamsA = mapParams("q", "id:(4 1)", "fl", "id,a_s,a_i", "sort", "a_i desc");
        streamA = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
        sParamsB = mapParams("q", "id:(0 2 3)", "fl", "id,a_s,a_i", "sort", "a_i desc");
        streamB = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsB);
        mstream = new MergeStream(streamA, streamB, new FieldComparator("a_i", ComparatorOrder.DESCENDING));
        mstream.setStreamContext(streamContext);
        tuples = getTuples(mstream);
        assertEquals(5, tuples.size());
        assertOrder(tuples, 4, 3, 2, 1, 0);
        //Test compound sort
        sParamsA = mapParams("q", "id:(2 4 1)", "fl", "id,a_s,a_i,a_f", "sort", "a_f asc,a_i asc");
        streamA = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
        sParamsB = mapParams("q", "id:(0 3)", "fl", "id,a_s,a_i,a_f", "sort", "a_f asc,a_i asc");
        streamB = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsB);
        mstream = new MergeStream(streamA, streamB, new MultipleFieldComparator(new FieldComparator("a_f", ComparatorOrder.ASCENDING), new FieldComparator("a_i", ComparatorOrder.ASCENDING)));
        mstream.setStreamContext(streamContext);
        tuples = getTuples(mstream);
        assertEquals(5, tuples.size());
        assertOrder(tuples, 0, 2, 1, 3, 4);
        sParamsA = mapParams("q", "id:(2 4 1)", "fl", "id,a_s,a_i,a_f", "sort", "a_f asc,a_i desc");
        streamA = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
        sParamsB = mapParams("q", "id:(0 3)", "fl", "id,a_s,a_i,a_f", "sort", "a_f asc,a_i desc");
        streamB = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsB);
        mstream = new MergeStream(streamA, streamB, new MultipleFieldComparator(new FieldComparator("a_f", ComparatorOrder.ASCENDING), new FieldComparator("a_i", ComparatorOrder.DESCENDING)));
        mstream.setStreamContext(streamContext);
        tuples = getTuples(mstream);
        assertEquals(5, tuples.size());
        assertOrder(tuples, 2, 0, 1, 3, 4);
    } finally {
        solrClientCache.close();
    }
}
Also used : UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) SolrClientCache(org.apache.solr.client.solrj.io.SolrClientCache) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) FieldComparator(org.apache.solr.client.solrj.io.comp.FieldComparator) MultipleFieldComparator(org.apache.solr.client.solrj.io.comp.MultipleFieldComparator) MultipleFieldComparator(org.apache.solr.client.solrj.io.comp.MultipleFieldComparator) Tuple(org.apache.solr.client.solrj.io.Tuple) Test(org.junit.Test)

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