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

The following examples show how to use org.apache.solr.common.params.ModifiableSolrParams#get() . 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: RewriteFacetParametersComponentTest.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
/** Check that if no mincount is supplied for a field facet then it gets defaulted to 1. */
@Test
public void rewriteMincountFacetFieldOption_mincountMissing_shouldSetGenericMinCountToOne()
{
    // There are no existing facet parameters.
    ModifiableSolrParams fixed = new ModifiableSolrParams();
    when(mockParams.getParameterNamesIterator()).thenReturn(Iterators.empty());
    when(mockParams.get(ShardParams.SHARDS_PURPOSE)).thenReturn(null);

    Map<String, String> fieldMappings = new HashMap<>();
    
    // Call the method under test.
    rewriteFacetParametersComponent.rewriteMincountFacetFieldOption(fixed, mockParams, "facet.mincount", fieldMappings,
        mockRequest);

    // Check that the mincount is set to 1.
    String actual = fixed.get("facet.mincount");
    assertEquals("Expected the existing mincount to be preserved.", "1", actual);
}
 
Example 2
Source File: RewriteFacetParametersComponentTest.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
/** Check that if the mincount is set as 0 then it is updated to be 1. */
@Test
public void rewriteMincountFacetFieldOption_mincountSetZero_shouldSetMincountToOne()
{
    ModifiableSolrParams fixed = new ModifiableSolrParams();
    // The user has tried to set the mincount to zero.
    when(mockParams.getParameterNamesIterator()).thenReturn(asList("facet.mincount").iterator());
    when(mockParams.get("facet.mincount")).thenReturn("0");
    when(mockParams.get(ShardParams.SHARDS_PURPOSE)).thenReturn(null);
    
    Map<String, String> fieldMappings = new HashMap<>();
    
    // Call the method under test.
    rewriteFacetParametersComponent.rewriteMincountFacetFieldOption(fixed, mockParams, "facet.mincount", fieldMappings,
        mockRequest);

    // Check that the mincount is set to 1 and the field name is converted to the format stored by Solr.
    String actualCount = fixed.get("facet.mincount");
    assertEquals("Expected the mincount to be 1.", "1", actualCount);
}
 
Example 3
Source File: RewriteFacetParametersComponentTest.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void rewriteShardedRequestParameters_mincountSetZero_shouldKeepMincountToZero()
{
    ModifiableSolrParams fixed = new ModifiableSolrParams();
    // The user has tried to set the mincount to zero.
    when(mockParams.getParameterNamesIterator()).thenReturn(asList("facet.mincount").iterator());
    when(mockParams.get("facet.mincount")).thenReturn("0");
    when(mockParams.get(ShardParams.SHARDS_PURPOSE)).thenReturn(String.valueOf(ShardRequest.PURPOSE_GET_FACETS));

    Map<String, String> fieldMappings = new HashMap<>();

    // Call the method under test.
    rewriteFacetParametersComponent.rewriteMincountFacetFieldOption(fixed, mockParams, "facet.mincount", fieldMappings,
        mockRequest);

    // Check that the mincount is set to 1 and the field name is converted to the format stored by Solr.
    String actualCount = fixed.get("facet.mincount");
    assertEquals("Expected no fixed value", null, actualCount);
}
 
Example 4
Source File: RewriteFacetParametersComponentTest.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void rewriteMincountFacetFieldOption_mincountSetTwo_shouldKeepIt()
{
    ModifiableSolrParams fixed = new ModifiableSolrParams();
    // The user has tried to set the mincount to zero.
    when(mockParams.getParameterNamesIterator()).thenReturn(asList("facet.mincount").iterator());
    when(mockParams.get("facet.mincount")).thenReturn("2");
    when(mockParams.get(ShardParams.SHARDS_PURPOSE)).thenReturn(null);

    Map<String, String> fieldMappings = new HashMap<>();

    // Call the method under test.
    rewriteFacetParametersComponent.rewriteMincountFacetFieldOption(fixed, mockParams, "facet.mincount", fieldMappings,
        mockRequest);

    // Check that the mincount is set to 1 and the field name is converted to the format stored by Solr.
    String actualCount = fixed.get("facet.mincount");
    assertEquals("Expected the mincount to be 2.", "2", actualCount);
}
 
Example 5
Source File: ModifiableSolrParamsMatcher.java    From metron with Apache License 2.0 6 votes vote down vote up
@Override
public boolean matches(ModifiableSolrParams modifiableSolrParams) {
  for(String name: expectedModifiableSolrParams.getParameterNames()) {
    String expectedValue = expectedModifiableSolrParams.get(name);
    String value = modifiableSolrParams.get(name);
    if(expectedValue == null) {
      if (value != null) {
        return false;
      }
    } else {
      if (!expectedValue.equals(value)) {
        return false;
      }
    }
  }
  return true;
}
 
Example 6
Source File: RewriteFacetParametersComponentTest.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
/** Check that if the mincount is set as 0 then it is updated to be 1. */
@Test
public void rewriteMincountFacetFieldOption_perFieldMincountSetZero_shouldSetPerFieldMincountToOne()
{
    ModifiableSolrParams fixed = new ModifiableSolrParams();
    // The user has tried to set the mincount to zero.
    when(mockParams.getParameterNamesIterator()).thenReturn(asList("f.NAME.facet.mincount","f.CONTENT.facet.mincount").iterator());
    when(mockParams.getParams("f.NAME.facet.mincount")).thenReturn(new String[]{"0"});
    when(mockParams.getParams("f.CONTENT.facet.mincount")).thenReturn(new String[]{"0"});
    when(mockParams.get(ShardParams.SHARDS_PURPOSE)).thenReturn(null);

    Map<String, String> fieldMappings = ImmutableMap.of(
        "NAME",
                "{!afts key=SEARCH.FACET_FIELDS.LOCATION}text@s____@{http://www.alfresco.org/model/content/1.0}name","CONTENT",
        "{!afts key=SEARCH.FACET_FIELDS.LOCATION}text@s____@{http://www.alfresco.org/model/content/1.0}content");

    // Call the method under test.
    rewriteFacetParametersComponent.rewriteMincountFacetFieldOption(fixed, mockParams, "facet.mincount", fieldMappings,
        mockRequest);

    // Check that the mincount is set to 1 and the field name is converted to the format stored by Solr.
    String actualNameCount = fixed.get("f.{!afts key=SEARCH.FACET_FIELDS.LOCATION}text@s____@{http://www.alfresco.org/model/content/1.0}name.facet.mincount");
    assertEquals("Expected the mincount to be 1.", "1", actualNameCount);
    String actualContentCount = fixed.get("f.{!afts key=SEARCH.FACET_FIELDS.LOCATION}text@s____@{http://www.alfresco.org/model/content/1.0}content.facet.mincount");
    assertEquals("Expected the mincount to be 1.", "1", actualContentCount);
}
 
Example 7
Source File: RewriteFacetParametersComponentTest.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
/** Check that if the user supplies a mincount of 2 then this is not changed. */
@Test
public void rewriteMincountFacetFieldOption_perFieldMincountSetTwo_shouldKeepIt()
{
    ModifiableSolrParams fixed = new ModifiableSolrParams();
    // The user has tried to set the mincount to zero.
    when(mockParams.getParameterNamesIterator()).thenReturn(asList("f.NAME.facet.mincount","f.CONTENT.facet.mincount").iterator());
    when(mockParams.getParams("f.NAME.facet.mincount")).thenReturn(new String[]{"2"});
    when(mockParams.getParams("f.CONTENT.facet.mincount")).thenReturn(new String[]{"0"});
    when(mockParams.get(ShardParams.SHARDS_PURPOSE)).thenReturn(null);

    Map<String, String> fieldMappings = ImmutableMap.of(
        "NAME",
        "{!afts key=SEARCH.FACET_FIELDS.LOCATION}text@s____@{http://www.alfresco.org/model/content/1.0}name","CONTENT",
        "{!afts key=SEARCH.FACET_FIELDS.LOCATION}text@s____@{http://www.alfresco.org/model/content/1.0}content");

    // Call the method under test.
    rewriteFacetParametersComponent.rewriteMincountFacetFieldOption(fixed, mockParams, "facet.mincount", fieldMappings,
        mockRequest);

    // Check that the mincount is kept as 2 and the field name is converted to the format stored by Solr.
    String actualNameCount = fixed.get("f.{!afts key=SEARCH.FACET_FIELDS.LOCATION}text@s____@{http://www.alfresco.org/model/content/1.0}name.facet.mincount");
    assertEquals("Expected the mincount to be 2.", "2", actualNameCount);
    String actualContentCount = fixed.get("f.{!afts key=SEARCH.FACET_FIELDS.LOCATION}text@s____@{http://www.alfresco.org/model/content/1.0}content.facet.mincount");
    assertEquals("Expected the mincount to be 1.", "1", actualContentCount);
}
 
Example 8
Source File: RewriteFacetParametersComponentTest.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void rewriteMincountFacetPivotOption_mincountMissing_shouldSetPivotMinCountToOne()
{
    // There are no existing facet parameters.
    ModifiableSolrParams fixed = new ModifiableSolrParams();
    when(mockParams.getParameterNamesIterator()).thenReturn(Iterators.empty());
    when(mockParams.get(ShardParams.SHARDS_PURPOSE)).thenReturn(null);

    Map<String, String> fieldMappings = new HashMap<>();

    // Call the method under test.
    rewriteFacetParametersComponent.rewriteMincountFacetFieldOption(fixed, mockParams, "facet.pivot.mincount", fieldMappings,
        mockRequest);

    // Check that the mincount is set to 1.
    String actual = fixed.get("facet.pivot.mincount");
    assertEquals("Expected the existing mincount to be preserved.", "1", actual);
}
 
Example 9
Source File: RewriteFacetParametersComponentTest.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void rewriteMincountFacetPivotOption_mincountSetTwo_shouldKeepIt()
{
    ModifiableSolrParams fixed = new ModifiableSolrParams();
    // The user has tried to set the mincount to zero.
    when(mockParams.getParameterNamesIterator()).thenReturn(asList("facet.pivot.mincount").iterator());
    when(mockParams.get("facet.pivot.mincount")).thenReturn("2");
    when(mockParams.get(ShardParams.SHARDS_PURPOSE)).thenReturn(null);

    Map<String, String> fieldMappings = new HashMap<>();

    // Call the method under test.
    rewriteFacetParametersComponent.rewriteMincountFacetFieldOption(fixed, mockParams, "facet.pivot.mincount", fieldMappings,
        mockRequest);

    // Check that the mincount is set to 1 and the field name is converted to the format stored by Solr.
    String actualCount = fixed.get("facet.pivot.mincount");
    assertEquals("Expected the mincount to be 2.", "2", actualCount);
}
 
Example 10
Source File: SearchStream.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
void init(String zkHost, String collection, ModifiableSolrParams params) throws IOException {
  this.zkHost  = zkHost;
  this.params   = params;

  if(this.params.get(CommonParams.Q) == null) {
    this.params.add(CommonParams.Q, "*:*");
  }
  this.collection = collection;
  if(params.get(CommonParams.SORT) != null) {
    this.comp = parseComp(params.get(CommonParams.SORT), params.get(CommonParams.FL));
  }
}
 
Example 11
Source File: ReplicationHandler.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
private void deleteSnapshot(ModifiableSolrParams params, SolrQueryResponse rsp) {
  params.required().get(NAME);

  String location = params.get(CoreAdminParams.BACKUP_LOCATION);
  core.getCoreContainer().assertPathAllowed(location == null ? null : Path.of(location));
  SnapShooter snapShooter = new SnapShooter(core, location, params.get(NAME));
  snapShooter.validateDeleteSnapshot();
  snapShooter.deleteSnapAsync(this);
  rsp.add(STATUS, OK_STATUS);
}
 
Example 12
Source File: MCRSolrProxyServlet.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
/**
 * redirects to query handler by using value of 'qt' parameter
 */
private static void redirectToQueryHandler(HttpServletRequest request, HttpServletResponse resp)
    throws IOException {
    ModifiableSolrParams solrQueryParameter = getSolrQueryParameter(request);
    String queryHandlerPath = solrQueryParameter.get(QUERY_HANDLER_PAR_NAME, SOLR_QUERY_PATH);
    solrQueryParameter.remove(QUERY_HANDLER_PAR_NAME);
    Map<String, String[]> parameters = toMultiMap(solrQueryParameter);
    doRedirectToQueryHandler(resp, queryHandlerPath, parameters);
}
 
Example 13
Source File: SolrTestCaseHS.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public static String getQueryResponse(String wt, SolrParams params) throws Exception {
  ModifiableSolrParams p = new ModifiableSolrParams(params);
  p.set("wt", wt);
  String path = p.get("qt");
  p.remove("qt");
  p.set("indent","true");

  DirectSolrConnection connection = new DirectSolrConnection(h.getCore());
  String raw = connection.request(path, p, null);
  return raw;
}
 
Example 14
Source File: RewriteFacetParametersComponentTest.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void rewriteMincountFacetFieldOption_perFieldMincountSetZero_shouldSetPerFieldMincountAndMincountToOne()
{
    ModifiableSolrParams fixed = new ModifiableSolrParams();
    // The user has tried to set the mincount to zero.
    when(mockParams.getParameterNamesIterator()).thenReturn(asList("f.NAME.facet.mincount","f.CONTENT.facet.mincount").iterator());
    when(mockParams.getParams("f.NAME.facet.mincount")).thenReturn(new String[]{"0"});
    when(mockParams.getParams("f.CONTENT.facet.mincount")).thenReturn(new String[]{"0"});
    when(mockParams.get(ShardParams.SHARDS_PURPOSE)).thenReturn(null);

    Map<String, String> fieldMappings = ImmutableMap.of(
        "NAME",
        "{!afts key=SEARCH.FACET_FIELDS.LOCATION}text@s____@{http://www.alfresco.org/model/content/1.0}name","CONTENT",
        "{!afts key=SEARCH.FACET_FIELDS.LOCATION}text@s____@{http://www.alfresco.org/model/content/1.0}content");

    // Call the method under test.
    rewriteFacetParametersComponent.rewriteMincountFacetFieldOption(fixed, mockParams, "facet.mincount", fieldMappings,
        mockRequest);

    // Check that the mincount is set to 1 and the field name is converted to the format stored by Solr.
    String actualNameCount = fixed.get("f.{!afts key=SEARCH.FACET_FIELDS.LOCATION}text@s____@{http://www.alfresco.org/model/content/1.0}name.facet.mincount");
    assertEquals("Expected the mincount to be 1.", "1", actualNameCount);
    String actualContentCount = fixed.get("f.{!afts key=SEARCH.FACET_FIELDS.LOCATION}text@s____@{http://www.alfresco.org/model/content/1.0}content.facet.mincount");
    assertEquals("Expected the mincount to be 1.", "1", actualContentCount);
    String actualCount = fixed.get("facet.mincount");
    assertEquals("Expected the mincount to be 1.", "1", actualCount);
}
 
Example 15
Source File: OpenNLPLangDetectUpdateProcessorFactoryTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
protected OpenNLPLangDetectUpdateProcessor createLangIdProcessor(ModifiableSolrParams parameters) throws Exception {
  if (parameters.get("langid.model") == null) { // handle superclass tests that don't provide the model filename
    parameters.set("langid.model", TEST_MODEL);
  }
  if (parameters.get("langid.threshold") == null) { // handle superclass tests that don't provide confidence threshold
    parameters.set("langid.threshold", "0.3");
  }
  SolrQueryRequest req = _parser.buildRequestFrom(h.getCore(), new ModifiableSolrParams(), null);
  OpenNLPLangDetectUpdateProcessorFactory factory = new OpenNLPLangDetectUpdateProcessorFactory();
  factory.init(parameters.toNamedList());
  factory.inform(h.getCore());
  return (OpenNLPLangDetectUpdateProcessor)factory.getInstance(req, resp, null);
}
 
Example 16
Source File: TestRandomFaceting.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private boolean isSortByCount(ModifiableSolrParams in) {
  boolean sortIsCount;
  String sortParam = in.get("facet.sort");
  sortIsCount = "count".equals(sortParam) || (sortParam==null && in.getInt("facet.limit",100)>0);
  return sortIsCount;
}
 
Example 17
Source File: StatsStream.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public StatsStream(StreamExpression expression, StreamFactory factory) throws IOException{
  // grab all parameters out
  String collectionName = factory.getValueOperand(expression, 0);

  if(collectionName.indexOf('"') > -1) {
    collectionName = collectionName.replaceAll("\"", "").replaceAll(" ", "");
  }

  List<StreamExpressionNamedParameter> namedParams = factory.getNamedOperands(expression);

  StreamExpressionNamedParameter zkHostExpression = factory.getNamedOperand(expression, "zkHost");
  List<StreamExpression> metricExpressions = factory.getExpressionOperandsRepresentingTypes(expression, Expressible.class, Metric.class);

  // Collection Name
  if(null == collectionName){
    throw new IOException(String.format(Locale.ROOT,"invalid expression %s - collectionName expected as first operand",expression));
  }

  // Construct the metrics
  Metric[] metrics = null;
  if(metricExpressions.size() > 0) {
    metrics = new Metric[metricExpressions.size()];
    for(int idx = 0; idx < metricExpressions.size(); ++idx){
      metrics[idx] = factory.constructMetric(metricExpressions.get(idx));
    }
  } else {
    metrics = new Metric[1];
    metrics[0] = new CountMetric();
  }

  // pull out known named params
  ModifiableSolrParams params = new ModifiableSolrParams();
  for(StreamExpressionNamedParameter namedParam : namedParams){
    if(!namedParam.getName().equals("zkHost")){
      params.add(namedParam.getName(), namedParam.getParameter().toString().trim());
    }
  }

  if(params.get("q") == null) {
    params.set("q", "*:*");
  }

  // zkHost, optional - if not provided then will look into factory list to get
  String zkHost = null;
  if(null == zkHostExpression){
    zkHost = factory.getCollectionZkHost(collectionName);
    if(zkHost == null) {
      zkHost = factory.getDefaultZkHost();
    }
  } else if(zkHostExpression.getParameter() instanceof StreamExpressionValue){
    zkHost = ((StreamExpressionValue)zkHostExpression.getParameter()).getValue();
  }

  // We've got all the required items
  init(collectionName, params, metrics, zkHost);
}
 
Example 18
Source File: Facet2DStream.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public Facet2DStream(StreamExpression expression, StreamFactory factory) throws IOException {

    String collectionName = factory.getValueOperand(expression, 0);

    if (collectionName.indexOf('"') > -1) {
      collectionName = collectionName.replaceAll("\"", "").replaceAll(" ", "");
    }

    List<StreamExpressionNamedParameter> namedParams = factory.getNamedOperands(expression);
    StreamExpressionNamedParameter bucketXExpression = factory.getNamedOperand(expression, "x");
    StreamExpressionNamedParameter bucketYExpression = factory.getNamedOperand(expression, "y");
    StreamExpressionNamedParameter dimensionsExpression = factory.getNamedOperand(expression, "dimensions");
    List <StreamExpression> metricExpression = factory.getExpressionOperandsRepresentingTypes(expression, Expressible.class, Metric.class);
    StreamExpressionNamedParameter zkHostExpression = factory.getNamedOperand(expression, "zkHost");

    if (collectionName == null) {
      throw new IOException(String.format(Locale.ROOT, "invalid expression %s - collectionName expected as first operand", expression));
    }

    ModifiableSolrParams params = new ModifiableSolrParams();
    for (StreamExpressionNamedParameter namedParam : namedParams) {
      if (!namedParam.getName().equals("x") && !namedParam.getName().equals("y") &&
          !namedParam.getName().equals("dimensions") && !namedParam.getName().equals("zkHost")){
        params.add(namedParam.getName(), namedParam.getParameter().toString().trim());
      }
    }

    if(params.get("q") == null) {
      params.set("q", "*:*");
    }

    Bucket x = null;
    if (bucketXExpression != null) {
      if (bucketXExpression.getParameter() instanceof StreamExpressionValue) {
        String keyX = ((StreamExpressionValue) bucketXExpression.getParameter()).getValue();
        if(keyX != null && !keyX.equals("")){
          x = new Bucket(keyX.trim());
        }
      }
    }
    Bucket y = null;
    if (bucketYExpression != null) {
      if (bucketYExpression.getParameter() instanceof StreamExpressionValue) {
        String keyY = ((StreamExpressionValue) bucketYExpression.getParameter()).getValue();
        if(keyY != null && !keyY.equals("")){
          y = new Bucket(keyY.trim());
        }
      }
    }

    if (x == null || y == null) {
      throw new IOException(String.format(Locale.ROOT, "invalid expression %s - x and y buckets expected. eg. 'x=\"name\"'", expression, collectionName));
    }

    Metric metric = null;
    if(metricExpression == null || metricExpression.size() == 0){
      metric = new CountMetric();
    } else {
      metric = factory.constructMetric(metricExpression.get(0));
    }

    String bucketSortString = metric.getIdentifier() + " desc";
    FieldComparator bucketSort = parseBucketSort(bucketSortString, x, y);

    int dimensionX = 10;
    int dimensionY = 10;
    if (dimensionsExpression != null) {
      if (dimensionsExpression.getParameter() instanceof StreamExpressionValue) {
        String[] strDimensions = ((StreamExpressionValue) dimensionsExpression.getParameter()).getValue().split(",");
        if (strDimensions.length != 2) {
          throw new IOException(String.format(Locale.ROOT, "invalid expression %s - two dimension values expected"));
        }
        dimensionX = Integer.parseInt(strDimensions[0].trim());
        dimensionY = Integer.parseInt(strDimensions[1].trim());
      }
    }

    String zkHost = null;
    if (zkHostExpression == null) {
      zkHost = factory.getCollectionZkHost(collectionName);
      if (zkHost == null) {
        zkHost = factory.getDefaultZkHost();
      }
    } else if (zkHostExpression.getParameter() instanceof StreamExpressionValue) {
      zkHost = ((StreamExpressionValue) zkHostExpression.getParameter()).getValue();
    }

    if (zkHost == null) {
      throw new IOException(String.format(Locale.ROOT, "invalid expression %s - zkHost not found for collection '%s'", expression, collectionName));
    }

    init(collectionName, params, x, y, bucketSort, dimensionX, dimensionY, metric, zkHost);
  }
 
Example 19
Source File: TestJsonFacets.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Test
public void testOverrequest() throws Exception {
  initServers();
  Client client = servers.getClient(random().nextInt());
  client.queryDefaults().set( "shards", servers.getShards(), "debugQuery", Boolean.toString(random().nextBoolean()) );

  List<SolrClient> clients = client.getClientProvider().all();
  assertTrue(clients.size() >= 3);

  client.deleteByQuery("*:*", null);

  ModifiableSolrParams p = params("cat_s", "cat_s");
  String cat_s = p.get("cat_s");

  clients.get(0).add( sdoc("id", "1", cat_s, "A") ); // A will win tiebreak
  clients.get(0).add( sdoc("id", "2", cat_s, "B") );

  clients.get(1).add( sdoc("id", "3", cat_s, "B") );
  clients.get(1).add( sdoc("id", "4", cat_s, "A") ); // A will win tiebreak

  clients.get(2).add( sdoc("id", "5", cat_s, "B") );
  clients.get(2).add( sdoc("id", "6", cat_s, "B") );

  client.commit();

  // Shard responses should be A=1, A=1, B=2, merged should be "A=2, B=2" hence A wins tiebreak

  client.testJQ(params(p, "q", "*:*",
      "json.facet", "{" +
          "cat0:{type:terms, field:${cat_s}, sort:'count desc', limit:1, overrequest:0}" +
          ",cat1:{type:terms, field:${cat_s}, sort:'count desc', limit:1, overrequest:1}" +
          ",catDef:{type:terms, field:${cat_s}, sort:'count desc', limit:1, overrequest:-1}" +  // -1 is default overrequest
          ",catBig:{type:terms, field:${cat_s}, sort:'count desc', offset:1, limit:2147483647, overrequest:2147483647}" +  // make sure overflows don't mess us up
          "}"
      )
      , "facets=={ count:6" +
          ", cat0:{ buckets:[ {val:A,count:2} ] }" +  // with no overrequest, we incorrectly conclude that A is the top bucket
          ", cat1:{ buckets:[ {val:B,count:4} ] }" +
          ", catDef:{ buckets:[ {val:B,count:4} ] }" +
          ", catBig:{ buckets:[ {val:A,count:2} ] }" +
          "}"
  );
}
 
Example 20
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));
  }
}