Search in sources :

Example 81 with SolrQueryRequest

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

the class SolrRequestParserTest method testAddHttpRequestToContext.

@Test
public void testAddHttpRequestToContext() throws Exception {
    HttpServletRequest request = getMock("/solr/select", null, -1);
    when(request.getMethod()).thenReturn("GET");
    when(request.getQueryString()).thenReturn("q=title:solr");
    Map<String, String> headers = new HashMap<>();
    headers.put("X-Forwarded-For", "10.0.0.1");
    when(request.getHeaderNames()).thenReturn(new Vector<>(headers.keySet()).elements());
    for (Map.Entry<String, String> entry : headers.entrySet()) {
        Vector<String> v = new Vector<>();
        v.add(entry.getValue());
        when(request.getHeaders(entry.getKey())).thenReturn(v.elements());
    }
    SolrRequestParsers parsers = new SolrRequestParsers(h.getCore().getSolrConfig());
    assertFalse(parsers.isAddRequestHeadersToContext());
    SolrQueryRequest solrReq = parsers.parse(h.getCore(), "/select", request);
    assertFalse(solrReq.getContext().containsKey("httpRequest"));
    parsers.setAddRequestHeadersToContext(true);
    solrReq = parsers.parse(h.getCore(), "/select", request);
    assertEquals(request, solrReq.getContext().get("httpRequest"));
    assertEquals("10.0.0.1", ((HttpServletRequest) solrReq.getContext().get("httpRequest")).getHeaders("X-Forwarded-For").nextElement());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) HashMap(java.util.HashMap) Vector(java.util.Vector) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 82 with SolrQueryRequest

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

the class IgnoreCommitOptimizeUpdateProcessorFactoryTest method processCommit.

SolrQueryResponse processCommit(final String chain, boolean optimize, Boolean commitEndPoint) throws IOException {
    SolrCore core = h.getCore();
    UpdateRequestProcessorChain pc = core.getUpdateProcessingChain(chain);
    assertNotNull("No Chain named: " + chain, pc);
    SolrQueryResponse rsp = new SolrQueryResponse();
    SolrQueryRequest req = new LocalSolrQueryRequest(core, new ModifiableSolrParams());
    if (commitEndPoint != null) {
        ((ModifiableSolrParams) req.getParams()).set(DistributedUpdateProcessor.COMMIT_END_POINT, commitEndPoint.booleanValue());
    }
    try {
        SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
        CommitUpdateCommand cmd = new CommitUpdateCommand(req, false);
        cmd.optimize = optimize;
        UpdateRequestProcessor processor = pc.createProcessor(req, rsp);
        processor.processCommit(cmd);
    } finally {
        SolrRequestInfo.clearRequestInfo();
        req.close();
    }
    return rsp;
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrCore(org.apache.solr.core.SolrCore) SolrRequestInfo(org.apache.solr.request.SolrRequestInfo) CommitUpdateCommand(org.apache.solr.update.CommitUpdateCommand) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 83 with SolrQueryRequest

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

the class SolrTestCaseHS method clearQueryCache.

/***
  public static void clearNCache() {
    SolrQueryRequest req = req();
    req.getSearcher().getnCache().clear();  // OFF-HEAP
    req.close();
  }***/
public static void clearQueryCache() {
    SolrQueryRequest req = req();
    req.getSearcher();
    req.close();
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest)

Example 84 with SolrQueryRequest

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

the class DebugComponentTest method ensureRidPresent.

@SuppressWarnings("unchecked")
private void ensureRidPresent(ResponseBuilder rb, String expectedRid) {
    SolrQueryRequest req = rb.req;
    SolrQueryResponse resp = rb.rsp;
    //a generated request ID should be added to the request
    String rid = req.getParams().get(CommonParams.REQUEST_ID);
    if (expectedRid == null) {
        assertTrue(rid + " Doesn't match expected pattern.", Pattern.matches(".*-collection1-[0-9]*-[0-9]+", rid));
    } else {
        assertEquals("Expecting " + expectedRid + " but found " + rid, expectedRid, rid);
    }
    //The request ID is added to the debug/track section
    assertEquals(rid, ((NamedList<Object>) rb.getDebugInfo().get("track")).get(CommonParams.REQUEST_ID));
    //RID must be added to the toLog, so that it's included in the main request log
    assertEquals(rid, resp.getToLog().get(CommonParams.REQUEST_ID));
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse)

Example 85 with SolrQueryRequest

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

the class LukeRequestHandlerTest method testFlParam.

@Test
public void testFlParam() {
    SolrQueryRequest req = req("qt", "/admin/luke", "fl", "solr_t solr_s", "show", "all");
    try {
        // First, determine that the two fields ARE there
        String response = h.query(req);
        assertNull(TestHarness.validateXPath(response, getFieldXPathPrefix("solr_t") + "[@name='index']", getFieldXPathPrefix("solr_s") + "[@name='index']"));
        // Now test that the other fields are NOT there
        for (String f : Arrays.asList("solr_ti", "solr_td", "solr_dt", "solr_b")) {
            assertNotNull(TestHarness.validateXPath(response, getFieldXPathPrefix(f) + "[@name='index']"));
        }
        // Insure * works
        req = req("qt", "/admin/luke", "fl", "*");
        response = h.query(req);
        for (String f : Arrays.asList("solr_t", "solr_s", "solr_ti", "solr_td", "solr_dt", "solr_b")) {
            if (h.getCore().getLatestSchema().getField(f).getType().isPointField())
                continue;
            assertNull(TestHarness.validateXPath(response, getFieldXPathPrefix(f) + "[@name='index']"));
        }
    } catch (Exception e) {
        fail("Caught unexpected exception " + e.getMessage());
    }
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) Test(org.junit.Test)

Aggregations

SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)362 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)148 Test (org.junit.Test)143 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)129 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)106 SolrCore (org.apache.solr.core.SolrCore)58 ArrayList (java.util.ArrayList)49 NamedList (org.apache.solr.common.util.NamedList)48 SolrInputDocument (org.apache.solr.common.SolrInputDocument)45 HashMap (java.util.HashMap)43 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)37 SolrParams (org.apache.solr.common.params.SolrParams)36 SolrException (org.apache.solr.common.SolrException)34 IOException (java.io.IOException)24 Query (org.apache.lucene.search.Query)24 BufferingRequestProcessor (org.apache.solr.update.processor.BufferingRequestProcessor)24 List (java.util.List)23 MapSolrParams (org.apache.solr.common.params.MapSolrParams)23 ContentStreamBase (org.apache.solr.common.util.ContentStreamBase)23 Map (java.util.Map)22