org.apache.solr.response.SolrQueryResponse Java Examples

The following examples show how to use org.apache.solr.response.SolrQueryResponse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AnnotatedApi.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
Cmd(String command, Object obj, Method method) {
  this.command = command;
  this.obj = obj;
  try {
    this.method = MethodHandles.publicLookup().unreflect(method);
  } catch (IllegalAccessException e) {
    throw new RuntimeException("Unable to access method, may be not public or accessible ", e);
  }
  Class<?>[] parameterTypes = method.getParameterTypes();
  paramsCount = parameterTypes.length;
  if (parameterTypes.length == 1) {
    readPayloadType(method.getGenericParameterTypes()[0]);
  } else if (parameterTypes.length == 3) {
    if (parameterTypes[0] != SolrQueryRequest.class || parameterTypes[1] != SolrQueryResponse.class) {
      throw new RuntimeException("Invalid params for method " + method);
    }
    Type t = method.getGenericParameterTypes()[2];
    readPayloadType(t);
  }
  if (parameterTypes.length > 3) {
    throw new RuntimeException("Invalid params count for method " + method);
  }
}
 
Example #2
Source File: SolrInformationServer.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
private NamedList<Integer> getFacets(SolrQueryRequest request, String query, String field, int minCount)
{
    ModifiableSolrParams params =
            new ModifiableSolrParams(request.getParams())
                    .set(CommonParams.Q, query)
                    .set(CommonParams.ROWS, 0)
                    .set(FacetParams.FACET, true)
                    .set(FacetParams.FACET_FIELD, field)
                    .set(FacetParams.FACET_MINCOUNT, minCount);

    SolrQueryResponse response = cloud.getResponse(nativeRequestHandler, request, params);
    NamedList facetCounts = (NamedList) response.getValues().get("facet_counts");
    NamedList facetFields = (NamedList) facetCounts.get("facet_fields");
    return (NamedList) facetFields.get(field);
}
 
Example #3
Source File: DebugComponentTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example #4
Source File: XmlInterpolationTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
protected void assertXmlTag(String docText, boolean expected) throws Exception {
  final SolrQueryRequest req = reqDoc(docText);
  try { // 5.4 and beyond we can use try-with-resources
    final SolrQueryResponse rsp = h.queryAndResponse(req.getParams().get("qt"), req);
    final TestTag[] testTags = pullTagsFromResponse(req, rsp);
    if (!expected) {
      assertEquals(0, testTags.length);
    } else {
      assertEquals(1, testTags.length);
      final TestTag tag = testTags[0];
      validateXml(insertAnchorAtOffsets(docText, tag.startOffset, tag.endOffset, tag.docName));
    }
  } finally {
    req.close();
  }
}
 
Example #5
Source File: JsonLoaderTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testDecimalValuesInAdd() throws Exception {
  String str = "{'add':[{'id':'1','d1':256.78,'d2':-5123456789.0,'d3':0.0,'d3':1.0,'d4':1.7E-10}]}".replace('\'', '"');
  SolrQueryRequest req = req();
  SolrQueryResponse rsp = new SolrQueryResponse();
  BufferingRequestProcessor p = new BufferingRequestProcessor(null);
  JsonLoader loader = new JsonLoader();
  loader.load(req, rsp, new ContentStreamBase.StringStream(str), p);

  assertEquals(1, p.addCommands.size());

  AddUpdateCommand add = p.addCommands.get(0);
  SolrInputDocument d = add.solrDoc;
  SolrInputField f = d.getField("d1");
  assertEquals(256.78, f.getValue());
  f = d.getField("d2");
  assertEquals(-5123456789.0, f.getValue());
  f = d.getField("d3");
  assertEquals(2, ((List)f.getValue()).size());
  assertTrue(((List)f.getValue()).contains(0.0));
  assertTrue(((List) f.getValue()).contains(1.0));
  f = d.getField("d4");
  assertEquals(1.7E-10, f.getValue());

  req.close();
}
 
Example #6
Source File: SuggestionService.java    From vind with Apache License 2.0 6 votes vote down vote up
protected SuggestionResult[] createResults(SolrQueryResponse rsp, String[] singleValueFields, String[] multiValueFields, String query, String op, String df, SuggestionRequestHandler.Type type, int termLimit, int limit, SuggestionRequestHandler.LimitType limitType, SuggestionRequestHandler.Strategy strategy, String sugestionField, Map<String, Map<String,Object>> intervals) {
    SuggestionResult[] result = new SuggestionResult[2];
    switch (type) {
        case single:
            result[0] = SuggestionResultFactory.createSingleValueResult(solrCore, rsp, singleValueFields, query, op, df, termLimit, limit, limitType, strategy,sugestionField,intervals);
            break;
        case multi:
            result[1] = SuggestionResultFactory.createMultiValueResult(solrCore, rsp, multiValueFields, query, df,termLimit, limit, limitType); //TODO consider strategy
            break;
        case mixed:
            result[0] = SuggestionResultFactory.createSingleValueResult(solrCore, rsp, singleValueFields, query, op, df,termLimit, limit, limitType, strategy,sugestionField,intervals);
            result[1] = SuggestionResultFactory.createMultiValueResult(solrCore, rsp, multiValueFields, query, df, termLimit, limit, limitType);
    }

    if ((result[0] == null || result[0].getCount() ==0) && (result[1] == null || ((SuggestionResultMulti) result[1]).getCount() == 0)) {
        result = null;
    }
    return result;
}
 
Example #7
Source File: ResponseLogComponentTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testToLogIds() throws Exception {
  SolrQueryRequest req = null;
  try {
    String handler="/withlog";
    req = req("indent","true", "qt","/withlog",  "q","aa", "rows","2",
        "fl","id,subject", "responseLog","true");
    SolrQueryResponse qr = h.queryAndResponse(handler, req);
    NamedList<Object> entries = qr.getToLog();
    String responseLog = (String) entries.get("responseLog");
    assertNotNull(responseLog);
    assertTrue(responseLog.matches("\\w+,\\w+"));
  } finally {
    req.close();
  }
}
 
Example #8
Source File: UUIDUpdateProcessorFallbackTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void testProcessorPrefixReqParam() throws Exception {
  List<UpdateRequestProcessorFactory> processors = UpdateRequestProcessorChain.getReqProcessors("uuid", h.getCore());
  UpdateRequestProcessorFactory processorFactory = processors.get(0);
  assertTrue(processorFactory instanceof UUIDUpdateProcessorFactory);

  SolrQueryResponse rsp = new SolrQueryResponse();
  SolrQueryRequest req = new LocalSolrQueryRequest(h.getCore(), new ModifiableSolrParams());
  AddUpdateCommand cmd = new AddUpdateCommand(req);
  cmd.solrDoc = new SolrInputDocument();
  cmd.solrDoc.addField("random_s", "random_val");

  processorFactory.getInstance(req, rsp, null).processAdd(cmd);
  assertNotNull(cmd.solrDoc);
  assertNotNull(cmd.solrDoc.get("id"));
  assertNotNull(cmd.solrDoc.get("id").getValue());
}
 
Example #9
Source File: XmlUpdateRequestHandlerTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testExternalEntities() throws Exception
{
  String file = getFile("mailing_lists.pdf").toURI().toASCIIString();
  String xml = 
    "<?xml version=\"1.0\"?>" +
    // check that external entities are not resolved!
    "<!DOCTYPE foo [<!ENTITY bar SYSTEM \""+file+"\">]>" +
    "<add>" +
    "  &bar;" +
    "  <doc>" +
    "    <field name=\"id\">12345</field>" +
    "    <field name=\"name\">kitten</field>" +
    "  </doc>" +
    "</add>";
  SolrQueryRequest req = req();
  SolrQueryResponse rsp = new SolrQueryResponse();
  BufferingRequestProcessor p = new BufferingRequestProcessor(null);
  XMLLoader loader = new XMLLoader().init(null);
  loader.load(req, rsp, new ContentStreamBase.StringStream(xml), p);

  AddUpdateCommand add = p.addCommands.get(0);
  assertEquals("12345", add.solrDoc.getField("id").getFirstValue());
  req.close();
}
 
Example #10
Source File: JsonLoaderTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void testAtomicUpdateFieldValue() throws Exception {
  String str = "[{'id':'1', 'val_s':{'add':'foo'}}]".replace('\'', '"');
  SolrQueryRequest req = req();
  SolrQueryResponse rsp = new SolrQueryResponse();
  BufferingRequestProcessor p = new BufferingRequestProcessor(null);
  JsonLoader loader = new JsonLoader();
  loader.load(req, rsp, new ContentStreamBase.StringStream(str), p);

  assertEquals( 1, p.addCommands.size() );

  AddUpdateCommand add = p.addCommands.get(0);
  assertEquals(add.commitWithin, -1);
  assertEquals(add.overwrite, true);
  assertEquals("SolrInputDocument(fields: [id=1, val_s={add=foo}])", add.solrDoc.toString());

  req.close();
}
 
Example #11
Source File: ManagedFeatureStore.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Called to retrieve a named part (the given childId) of the resource at the
 * given endpoint. Note: since we have a unique child feature store we ignore
 * the childId.
 */
@Override
public void doGet(BaseSolrResource endpoint, String childId) {
  final SolrQueryResponse response = endpoint.getSolrResponse();

  // If no feature store specified, show all the feature stores available
  if (childId == null) {
    response.add(FEATURE_STORE_JSON_FIELD, stores.keySet());
  } else {
    final FeatureStore store = getFeatureStore(childId);
    if (store == null) {
      throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
          "missing feature store [" + childId + "]");
    }
    response.add(FEATURES_JSON_FIELD,
        featuresAsManagedResources(store));
  }
}
 
Example #12
Source File: V2HttpCall.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
protected void execute(SolrQueryResponse rsp) {
  SolrCore.preDecorateResponse(solrReq, rsp);
  if (api == null) {
    rsp.setException(new SolrException(SolrException.ErrorCode.NOT_FOUND,
        "Cannot find correspond api for the path : " + solrReq.getContext().get(CommonParams.PATH)));
  } else {
    try {
      api.call(solrReq, rsp);
    } catch (Exception e) {
      rsp.setException(e);
    }
  }

  SolrCore.postDecorateResponse(handler, solrReq, rsp);
}
 
Example #13
Source File: VelocityResponseWriterTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
@Ignore("SOLR-14025: Velocity's SecureUberspector addresses this")
public void testSandboxIntersection() throws Exception {
  assumeTrue("This test only works with security manager", System.getSecurityManager() != null);
  VelocityResponseWriter vrw = new VelocityResponseWriter();
  NamedList<String> nl = new NamedList<>();
  nl.add("template.base.dir", getFile("velocity").getAbsolutePath());
  vrw.init(nl);
  SolrQueryRequest req = req(VelocityResponseWriter.TEMPLATE,"sandbox_intersection");
  SolrQueryResponse rsp = new SolrQueryResponse();
  StringWriter buf = new StringWriter();
  try {
    vrw.write(buf, req, rsp);
    fail("template broke outside the box, retrieved: " + buf);
  } catch (MethodInvocationException e) {
    assertNotNull(e.getCause());
    assertEquals(AccessControlException.class, e.getCause().getClass());
    // expected failure, can't get outside the box
  }
}
 
Example #14
Source File: MaxSizeAutoCommitTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testAdds() throws Exception {

  Assert.assertEquals("There have been no updates yet, so there shouldn't have been any commits", 0,
                      hardCommitTracker.getCommitCount());

  long tlogSizePreUpdates = updateHandler.getUpdateLog().getCurrentLogSizeFromStream();
  Assert.assertEquals("There have been no updates yet, so tlog should be empty", 0, tlogSizePreUpdates);

  // Add a large number of docs - should trigger a commit
  int numDocsToAdd = 500;
  SolrQueryResponse updateResp = new SolrQueryResponse();
  
  monitor.doStuffAndExpectAtLeastOneCommit(hardCommitTracker, updateHandler, () -> {
      updateRequestHandler.handleRequest(constructBatchAddDocRequest(0, numDocsToAdd), updateResp);
    });
}
 
Example #15
Source File: AnalyticsComponent.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void finishStage(ResponseBuilder rb) {
  if (rb.isAnalytics() && rb.stage == ResponseBuilder.STAGE_GET_FIELDS) {
    AnalyticsRequestManager reqManager = getAnalyticsRequestManager(rb);
    // Generate responses from the merged shard data
    if (rb.isOlapAnalytics()) {
      rb.rsp.add(AnalyticsResponseHeadings.COMPLETED_OLD_HEADER, reqManager.createOldResponse());
    } else {
      rb.rsp.add(AnalyticsResponseHeadings.COMPLETED_HEADER, reqManager.createResponse());
    }
    if (reqManager.isPartialResults()) {
      rb.rsp.getResponseHeader().asShallowMap().put(SolrQueryResponse.RESPONSE_HEADER_PARTIAL_RESULTS_KEY,true);
    }
  }

  super.finishStage(rb);
}
 
Example #16
Source File: HttpSolrCall.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void handleAdminRequest() throws IOException {
  SolrQueryResponse solrResp = new SolrQueryResponse();
  SolrCore.preDecorateResponse(solrReq, solrResp);
  handleAdmin(solrResp);
  SolrCore.postDecorateResponse(handler, solrReq, solrResp);
  if (solrResp.getToLog().size() > 0) {
    if (log.isInfoEnabled()) { // has to come second and in it's own if to keep ./gradlew check happy.
      log.info(handler != null ? MarkerFactory.getMarker(handler.getClass().getName()) : MarkerFactory.getMarker(HttpSolrCall.class.getName()), solrResp.getToLogAsString("[admin]"));
    }
  }
  QueryResponseWriter respWriter = SolrCore.DEFAULT_RESPONSE_WRITERS.get(solrReq.getParams().get(CommonParams.WT));
  if (respWriter == null) respWriter = getResponseWriter();
  writeResponse(solrResp, respWriter, Method.getMethod(req.getMethod()));
  if (shouldAudit()) {
    EventType eventType = solrResp.getException() == null ? EventType.COMPLETED : EventType.ERROR;
    if (shouldAudit(eventType)) {
      cores.getAuditLoggerPlugin().doAudit(
          new AuditEvent(eventType, req, getAuthCtx(), solrReq.getRequestTimer().getTime(), solrResp.getException()));
    }
  }
}
 
Example #17
Source File: MaxSizeAutoCommitTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeletes() throws Exception {

  Assert.assertEquals("There have been no updates yet, so there shouldn't have been any commits", 0,
                      hardCommitTracker.getCommitCount());

  long tlogSizePreUpdates = updateHandler.getUpdateLog().getCurrentLogSizeFromStream();
  Assert.assertEquals("There have been no updates yet, so tlog should be empty", 0, tlogSizePreUpdates);
  
  // Add docs
  int numDocsToAdd = 500;
  SolrQueryResponse updateResp = new SolrQueryResponse();
  
  monitor.doStuffAndExpectAtLeastOneCommit(hardCommitTracker, updateHandler, () -> {
      updateRequestHandler.handleRequest(constructBatchAddDocRequest(0, numDocsToAdd), updateResp);
    });
  
  // Delete all documents - should trigger a commit
  
  monitor.doStuffAndExpectAtLeastOneCommit(hardCommitTracker, updateHandler, () -> {
      updateRequestHandler.handleRequest(constructBatchDeleteDocRequest(0, numDocsToAdd), updateResp);
    });
  
}
 
Example #18
Source File: AtomicUpdateProcessorFactoryTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void testWrongAtomicOpPassed() throws Exception {
  ModifiableSolrParams params = new ModifiableSolrParams()
      .add("processor", "Atomic")
      .add("atomic.cat", "delete")
      .add("commit", "true");
  try (SolrQueryRequest req = new LocalSolrQueryRequest(h.getCore(), params)) {
    AddUpdateCommand cmd = new AddUpdateCommand(req);
    AtomicUpdateProcessorFactory factory = new AtomicUpdateProcessorFactory();
    factory.inform(h.getCore());
    factory.getInstance(cmd.getReq(), new SolrQueryResponse(),
        null).processAdd(cmd);
  } catch (SolrException e) {
    assertEquals("Unexpected param(s) for AtomicUpdateProcessor, invalid atomic op passed: 'delete'",
        e.getMessage());
  }
}
 
Example #19
Source File: TestHarness.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/** It is the users responsibility to close the request object when done with it.
 * This method does not set/clear SolrRequestInfo */
public SolrQueryResponse queryAndResponse(String handler, SolrQueryRequest req) throws Exception {
  try (SolrCore core = getCoreInc()) {
    SolrQueryResponse rsp = new SolrQueryResponse();
    core.execute(core.getRequestHandler(handler), req, rsp);
    if (rsp.getException() != null) {
      throw rsp.getException();
    }
    return rsp;
  }
}
 
Example #20
Source File: JsonLoaderTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testBigDecimalValuesInAdd() throws Exception {
  String str = ("{'add':[{'id':'1','bd1':0.12345678901234567890123456789012345,"
               + "'bd2':12345678901234567890.12345678901234567890,'bd3':0.012345678901234567890123456789012345,"
               + "'bd3':123456789012345678900.012345678901234567890}]}").replace('\'', '"');
  SolrQueryRequest req = req();
  SolrQueryResponse rsp = new SolrQueryResponse();
  BufferingRequestProcessor p = new BufferingRequestProcessor(null);
  JsonLoader loader = new JsonLoader();
  loader.load(req, rsp, new ContentStreamBase.StringStream(str), p);

  assertEquals(1, p.addCommands.size());

  AddUpdateCommand add = p.addCommands.get(0);
  SolrInputDocument d = add.solrDoc;
  SolrInputField f = d.getField("bd1");                        
  assertTrue(f.getValue() instanceof String);
  assertEquals("0.12345678901234567890123456789012345", f.getValue());
  f = d.getField("bd2");
  assertTrue(f.getValue() instanceof String);
  assertEquals("12345678901234567890.12345678901234567890", f.getValue());
  f = d.getField("bd3");
  assertEquals(2, ((List)f.getValue()).size());
  assertTrue(((List)f.getValue()).contains("0.012345678901234567890123456789012345"));
  assertTrue(((List)f.getValue()).contains("123456789012345678900.012345678901234567890"));

  req.close();
}
 
Example #21
Source File: UpdateProcessorTestBase.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Runs a document through the specified chain, and returns the final
 * document used when the chain is completed (NOTE: some chains may
 * modify the document in place
 */
protected SolrInputDocument processAdd(final String chain,
                                       final SolrParams requestParams,
                                       final SolrInputDocument docIn)
  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, requestParams);
  try {
    SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
    AddUpdateCommand cmd = new AddUpdateCommand(req);
    cmd.solrDoc = docIn;

    UpdateRequestProcessor processor = pc.createProcessor(req, rsp);
    if (null != processor) {
      // test chain might be empty or short circuited.
      processor.processAdd(cmd);
    }

    return cmd.solrDoc;
  } finally {
    SolrRequestInfo.clearRequestInfo();
    req.close();
  }
}
 
Example #22
Source File: ImpersonatorCollectionsHandler.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
  called.set(true);
  super.handleRequestBody(req, rsp);
  String doAs = req.getParams().get(KerberosPlugin.IMPERSONATOR_DO_AS_HTTP_PARAM);
  if (doAs != null) {
    HttpServletRequest httpRequest = (HttpServletRequest)req.getContext().get("httpRequest");
    Assert.assertNotNull(httpRequest);
    String user = req.getParams().get(PseudoAuthenticator.USER_NAME);
    Assert.assertNotNull(user);
    Assert.assertEquals(user, httpRequest.getAttribute(KerberosPlugin.IMPERSONATOR_USER_NAME));
  }
}
 
Example #23
Source File: ManagedModelStore.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Called to retrieve a named part (the given childId) of the resource at the
 * given endpoint. Note: since we have a unique child managed store we ignore
 * the childId.
 */
@Override
public void doGet(BaseSolrResource endpoint, String childId) {

  final SolrQueryResponse response = endpoint.getSolrResponse();
  response.add(MODELS_JSON_FIELD,
      modelsAsManagedResources(store.getModels()));
}
 
Example #24
Source File: DocExpirationUpdateProcessorFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public UpdateRequestProcessor getInstance(SolrQueryRequest req, 
                                          SolrQueryResponse rsp, 
                                          UpdateRequestProcessor next ) {

  String defaultTtl = (null == ttlParam) ? null : req.getParams().get(ttlParam);

  if (null == ttlField && null == defaultTtl) {
    // nothing to do, shortcircut ourselves out of the chain.
    return next;
  } else {
    return new TTLUpdateProcessor(defaultTtl, expireField, ttlField, next);
  }
}
 
Example #25
Source File: TikaLanguageIdentifierUpdateProcessorFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public UpdateRequestProcessor getInstance(SolrQueryRequest req,
                                          SolrQueryResponse rsp, UpdateRequestProcessor next) {
  // Process defaults, appends and invariants if we got a request
  if(req != null) {
    SolrPluginUtils.setDefaults(req, defaults, appends, invariants);
  }
  return new TikaLanguageIdentifierUpdateProcessor(req, rsp, next);
}
 
Example #26
Source File: TestInitParams.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testElevateExample(){
  SolrRequestHandler handler = h.getCore().getRequestHandler("/elevate");
  SolrQueryResponse rsp = new SolrQueryResponse();
  handler.handleRequest(req("initArgs", "true"), rsp);
  @SuppressWarnings({"rawtypes"})
  NamedList nl = (NamedList) rsp.getValues().get("initArgs");
  @SuppressWarnings({"rawtypes"})
  NamedList def = (NamedList) nl.get(PluginInfo.DEFAULTS);
  assertEquals("text" ,def.get("df"));

}
 
Example #27
Source File: CdcrRequestHandler.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void handleEnableBufferAction(SolrQueryRequest req, SolrQueryResponse rsp) {
  if (bufferStateManager.getState() == CdcrParams.BufferState.DISABLED) {
    bufferStateManager.setState(CdcrParams.BufferState.ENABLED);
    bufferStateManager.synchronize();
  }

  rsp.add(CdcrParams.CdcrAction.STATUS.toLower(), this.getStatus());
}
 
Example #28
Source File: CollectionsHandler.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked"})
void invokeAction(SolrQueryRequest req, SolrQueryResponse rsp, CoreContainer cores, CollectionAction action, CollectionOperation operation) throws Exception {
  if (!coreContainer.isZooKeeperAware()) {
    throw new SolrException(BAD_REQUEST,
        "Invalid request. collections can be accessed only in SolrCloud mode");
  }
  Map<String, Object> props = operation.execute(req, rsp, this);
  if (props == null) {
    return;
  }

  String asyncId = req.getParams().get(ASYNC);
  if (asyncId != null) {
    props.put(ASYNC, asyncId);
  }

  props.put(QUEUE_OPERATION, operation.action.toLower());

  if (operation.sendToOCPQueue) {
    ZkNodeProps zkProps = new ZkNodeProps(props);
    SolrResponse overseerResponse = sendToOCPQueue(zkProps, operation.timeOut);
    rsp.getValues().addAll(overseerResponse.getResponse());
    Exception exp = overseerResponse.getException();
    if (exp != null) {
      rsp.setException(exp);
    }

    //TODO yuck; shouldn't create-collection at the overseer do this?  (conditionally perhaps)
    if (action.equals(CollectionAction.CREATE) && asyncId == null) {
      if (rsp.getException() == null) {
        waitForActiveCollection(zkProps.getStr(NAME), cores, overseerResponse);
      }
    }

  } else {
    // submits and doesn't wait for anything (no response)
    coreContainer.getZkController().getOverseer().offerStateUpdate(Utils.toJSON(props));
  }

}
 
Example #29
Source File: SolrFacetService.java    From chronix.server with Apache License 2.0 5 votes vote down vote up
/**
 * @param req          the solr query request
 * @param rsp          the solr query response
 * @param matchingDocs the set of matching documents
 * @param solrParams   the solr request params
 * @return pivot processor
 */
PivotFacetProcessor pivotFacetProcessor(SolrQueryRequest req,
                                        SolrQueryResponse rsp,
                                        DocSet matchingDocs,
                                        SolrParams solrParams) {
    ResponseBuilder rb = new ResponseBuilder(req, rsp, emptyList());
    rb.doFacets = true;
    return new PivotFacetProcessor(req, matchingDocs, solrParams, rb);
}
 
Example #30
Source File: QuerySegmenterQParserTest.java    From query-segmenter with Apache License 2.0 5 votes vote down vote up
private SolrQueryRequest request(ModifiableSolrParams params, String handlerName) {
  SolrCore core = h.getCore();
  SolrRequestHandler handler = core.getRequestHandler(handlerName);

  SolrQueryResponse rsp = new SolrQueryResponse();
  NamedList<Object> list = new NamedList<Object>();
  list.add("responseHeader", new SimpleOrderedMap<Object>());
  rsp.setAllValues(list);
  SolrQueryRequest req = new LocalSolrQueryRequest(core, params);
  handler.handleRequest(req, rsp);
  return req;
}