Search in sources :

Example 71 with LocalSolrQueryRequest

use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.

the class BasicFunctionalityTest method testSolrParams.

@Test
public void testSolrParams() throws Exception {
    NamedList nl = new NamedList();
    nl.add("i", 555);
    nl.add("s", "bbb");
    nl.add("bt", "true");
    nl.add("bf", "false");
    Map<String, String> m = new HashMap<>();
    m.put("f.field1.i", "1000");
    m.put("s", "BBB");
    m.put("ss", "SSS");
    LocalSolrQueryRequest req = new LocalSolrQueryRequest(null, nl);
    SolrParams p = req.getParams();
    assertEquals(p.get("i"), "555");
    assertEquals(p.getInt("i").intValue(), 555);
    assertEquals(p.getInt("i", 5), 555);
    assertEquals(p.getInt("iii", 5), 5);
    assertEquals(p.getFieldParam("field1", "i"), "555");
    req.setParams(SolrParams.wrapDefaults(p, new MapSolrParams(m)));
    p = req.getParams();
    assertEquals(req.getOriginalParams().get("s"), "bbb");
    assertEquals(p.get("i"), "555");
    assertEquals(p.getInt("i").intValue(), 555);
    assertEquals(p.getInt("i", 5), 555);
    assertEquals(p.getInt("iii", 5), 5);
    assertEquals(p.getFieldParam("field1", "i"), "1000");
    assertEquals(p.get("s"), "bbb");
    assertEquals(p.get("ss"), "SSS");
    assertEquals(!!p.getBool("bt"), !p.getBool("bf"));
    assertEquals(p.getBool("foo", true), true);
    assertEquals(p.getBool("foo", false), false);
    assertEquals(!!p.getBool("bt"), !p.getBool("bf"));
    NamedList more = new NamedList();
    more.add("s", "aaa");
    more.add("s", "ccc");
    more.add("ss", "YYY");
    more.add("xx", "XXX");
    p = SolrParams.wrapAppended(p, SolrParams.toSolrParams(more));
    assertEquals(3, p.getParams("s").length);
    assertEquals("bbb", p.getParams("s")[0]);
    assertEquals("aaa", p.getParams("s")[1]);
    assertEquals("ccc", p.getParams("s")[2]);
    assertEquals(3, p.getParams("s").length);
    assertEquals("SSS", p.get("ss"));
    assertEquals("XXX", p.get("xx"));
    req.close();
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) MapSolrParams(org.apache.solr.common.params.MapSolrParams) HashMap(java.util.HashMap) NamedList(org.apache.solr.common.util.NamedList) SolrParams(org.apache.solr.common.params.SolrParams) MapSolrParams(org.apache.solr.common.params.MapSolrParams) Test(org.junit.Test)

Example 72 with LocalSolrQueryRequest

use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.

the class SolrIndexSearcher method warm.

/**
   * Warm this searcher based on an old one (primarily for auto-cache warming).
   */
public void warm(SolrIndexSearcher old) {
    // Make sure this is first! filters can help queryResults execute!
    long warmingStartTime = System.nanoTime();
    // warm the caches in order...
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.add("warming", "true");
    for (int i = 0; i < cacheList.length; i++) {
        if (log.isDebugEnabled()) {
            log.debug("autowarming [{}] from [{}]\n\t{}", this, old, old.cacheList[i]);
        }
        final SolrQueryRequest req = new LocalSolrQueryRequest(core, params) {

            @Override
            public SolrIndexSearcher getSearcher() {
                return SolrIndexSearcher.this;
            }

            @Override
            public void close() {
            }
        };
        final SolrQueryResponse rsp = new SolrQueryResponse();
        SolrRequestInfo.clearRequestInfo();
        SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
        try {
            cacheList[i].warm(this, old.cacheList[i]);
        } finally {
            try {
                req.close();
            } finally {
                SolrRequestInfo.clearRequestInfo();
            }
        }
        if (log.isDebugEnabled()) {
            log.debug("autowarming result for [{}]\n\t{}", this, cacheList[i]);
        }
    }
    warmupTime = TimeUnit.MILLISECONDS.convert(System.nanoTime() - warmingStartTime, TimeUnit.NANOSECONDS);
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrRequestInfo(org.apache.solr.request.SolrRequestInfo) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) IndexFingerprint(org.apache.solr.update.IndexFingerprint)

Example 73 with LocalSolrQueryRequest

use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.

the class BasicZkTest method request.

public SolrQueryRequest request(String... q) {
    LocalSolrQueryRequest req = lrf.makeRequest(q);
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.add(req.getParams());
    params.set("distrib", false);
    req.setParams(params);
    return req;
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 74 with LocalSolrQueryRequest

use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.

the class FieldAnalysisRequestHandlerTest method testNoDefaultField.

@Test(expected = Exception.class)
public void testNoDefaultField() throws Exception {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.add(CommonParams.Q, "fox brown");
    SolrQueryRequest req = new LocalSolrQueryRequest(h.getCore(), params);
    handler.resolveAnalysisRequest(req);
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) Test(org.junit.Test)

Example 75 with LocalSolrQueryRequest

use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.

the class TestCollectionAPIs method makeCall.

public static Pair<SolrQueryRequest, SolrQueryResponse> makeCall(final ApiBag apiBag, String path, final SolrRequest.METHOD method, final String payload, final CoreContainer cc) throws Exception {
    SolrParams queryParams = new MultiMapSolrParams(Collections.emptyMap());
    if (path.indexOf('?') > 0) {
        String queryStr = path.substring(path.indexOf('?') + 1);
        path = path.substring(0, path.indexOf('?'));
        queryParams = SolrRequestParsers.parseQueryString(queryStr);
    }
    final HashMap<String, String> parts = new HashMap<>();
    Api api = apiBag.lookup(path, method.toString(), parts);
    if (api == null)
        throw new RuntimeException("No handler at path :" + path);
    SolrQueryResponse rsp = new SolrQueryResponse();
    LocalSolrQueryRequest req = new LocalSolrQueryRequest(null, queryParams) {

        @Override
        public List<CommandOperation> getCommands(boolean validateInput) {
            if (payload == null)
                return Collections.emptyList();
            return ApiBag.getCommandOperations(new StringReader(payload), api.getCommandSchema(), true);
        }

        @Override
        public Map<String, String> getPathTemplateValues() {
            return parts;
        }

        @Override
        public String getHttpMethod() {
            return method.toString();
        }
    };
    try {
        api.call(req, rsp);
    } catch (ApiBag.ExceptionWithErrObject e) {
        throw new RuntimeException(e.getMessage() + Utils.toJSONString(e.getErrs()), e);
    }
    return new Pair<>(req, rsp);
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) MultiMapSolrParams(org.apache.solr.common.params.MultiMapSolrParams) HashMap(java.util.HashMap) CommandOperation(org.apache.solr.common.util.CommandOperation) ApiBag(org.apache.solr.api.ApiBag) Utils.fromJSONString(org.apache.solr.common.util.Utils.fromJSONString) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) StringReader(java.io.StringReader) SolrParams(org.apache.solr.common.params.SolrParams) MultiMapSolrParams(org.apache.solr.common.params.MultiMapSolrParams) Api(org.apache.solr.api.Api) Pair(org.apache.solr.common.util.Pair)

Aggregations

LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)107 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)61 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)49 SolrCore (org.apache.solr.core.SolrCore)47 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)41 Test (org.junit.Test)41 HashMap (java.util.HashMap)32 NamedList (org.apache.solr.common.util.NamedList)26 ArrayList (java.util.ArrayList)23 MapSolrParams (org.apache.solr.common.params.MapSolrParams)21 SolrException (org.apache.solr.common.SolrException)18 List (java.util.List)15 LinkedHashMap (java.util.LinkedHashMap)11 SolrParams (org.apache.solr.common.params.SolrParams)10 SearchComponent (org.apache.solr.handler.component.SearchComponent)10 SolrRequestHandler (org.apache.solr.request.SolrRequestHandler)10 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)10 Map (java.util.Map)9 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)9 IOException (java.io.IOException)8