Java Code Examples for org.apache.solr.common.params.ModifiableSolrParams#getBool()

The following examples show how to use org.apache.solr.common.params.ModifiableSolrParams#getBool() . 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: TestRandomFaceting.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void validateResponse(String expected, String actual, ModifiableSolrParams params, String method,
      List<String> methods) throws Exception {
  if (params.getBool("facet.exists", false)) {
    if (isSortByCount(params)) { // it's challenged with facet.sort=count 
      expected = getExpectationForSortByCount(params, methods);// that requires to recalculate expactation
    } else { // facet.sort=index
      expected = capFacetCountsTo1(expected);
    }
  }
  
  String err = JSONTestUtil.match("/", actual, expected, 0.0);
  if (err != null) {
    log.error("ERROR: mismatch facet response: {}\n expected ={}\n response = {}\n request = {}"
        , err, expected, actual, params);
    fail(err);
  }
}
 
Example 2
Source File: SQLHandler.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
  ModifiableSolrParams params = new ModifiableSolrParams(req.getParams());
  params = adjustParams(params);
  req.setParams(params);

  String sql = params.get("stmt");
  // Set defaults for parameters
  params.set("numWorkers", params.getInt("numWorkers", 1));
  params.set("workerCollection", params.get("workerCollection", defaultWorkerCollection));
  params.set("workerZkhost", params.get("workerZkhost", defaultZkhost));
  params.set("aggregationMode", params.get("aggregationMode", "facet"));

  TupleStream tupleStream = null;
  try {

    if(!isCloud) {
      throw new IllegalStateException(sqlNonCloudErrorMsg);
    }

    if(sql == null) {
      throw new Exception("stmt parameter cannot be null");
    }

    String url = CalciteSolrDriver.CONNECT_STRING_PREFIX;

    Properties properties = new Properties();
    // Add all query parameters
    Iterator<String> parameterNamesIterator = params.getParameterNamesIterator();
    while(parameterNamesIterator.hasNext()) {
      String param = parameterNamesIterator.next();
      properties.setProperty(param, params.get(param));
    }

    // Set these last to ensure that they are set properly
    properties.setProperty("lex", Lex.MYSQL.toString());
    properties.setProperty("zk", defaultZkhost);

    String driverClass = CalciteSolrDriver.class.getCanonicalName();

    // JDBC driver requires metadata from the SQLHandler. Default to false since this adds a new Metadata stream.
    boolean includeMetadata = params.getBool("includeMetadata", false);
    tupleStream = new SqlHandlerStream(url, sql, null, properties, driverClass, includeMetadata);

    tupleStream = new StreamHandler.TimerStream(new ExceptionStream(tupleStream));

    rsp.add("result-set", tupleStream);
  } catch(Exception e) {
    //Catch the SQL parsing and query transformation exceptions.
    if(tupleStream != null) {
      tupleStream.close();
    }
    SolrException.log(log, e);
    rsp.add("result-set", new StreamHandler.DummyErrorStream(e));
  }
}