Search in sources :

Example 31 with MapSolrParams

use of org.apache.solr.common.params.MapSolrParams in project lucene-solr by apache.

the class StatsComponentTest method testStatsExcludeFilterQuery.

//SOLR-3177
public void testStatsExcludeFilterQuery() throws Exception {
    SolrCore core = h.getCore();
    assertU(adoc("id", "1"));
    assertU(adoc("id", "2"));
    assertU(adoc("id", "3"));
    assertU(adoc("id", "4"));
    assertU(commit());
    Map<String, String> args = new HashMap<String, String>();
    args.put(CommonParams.Q, "*:*");
    args.put(StatsParams.STATS, "true");
    args.put(StatsParams.STATS_FIELD, "{!ex=id}id");
    args.put("fq", "{!tag=id}id:[2 TO 3]");
    SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
    assertQ("test exluding filter query", req, "//lst[@name='id']/double[@name='min'][.='1.0']", "//lst[@name='id']/double[@name='max'][.='4.0']");
    args = new HashMap<String, String>();
    args.put(CommonParams.Q, "*:*");
    args.put(StatsParams.STATS, "true");
    args.put(StatsParams.STATS_FIELD, "{!key=id2}id");
    args.put("fq", "{!tag=id}id:[2 TO 3]");
    req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
    assertQ("test rename field", req, "//lst[@name='id2']/double[@name='min'][.='2.0']", "//lst[@name='id2']/double[@name='max'][.='3.0']");
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) MapSolrParams(org.apache.solr.common.params.MapSolrParams) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SolrCore(org.apache.solr.core.SolrCore)

Example 32 with MapSolrParams

use of org.apache.solr.common.params.MapSolrParams in project lucene-solr by apache.

the class StatsComponentTest method testFieldStatisticsResultsStringField.

public void testFieldStatisticsResultsStringField() throws Exception {
    SolrCore core = h.getCore();
    assertU(adoc("id", "1", "active_s", "string1"));
    assertU(adoc("id", "2", "active_s", "string2"));
    assertU(adoc("id", "3", "active_s", "string3"));
    assertU(adoc("id", "4"));
    assertU(commit());
    Map<String, String> args = new HashMap<>();
    args.put(CommonParams.Q, "*:*");
    args.put(StatsParams.STATS, "true");
    args.put(StatsParams.STATS_FIELD, "active_s");
    args.put("f.active_s.stats.calcdistinct", "true");
    args.put("indent", "true");
    SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
    assertQ("test string statistics values", req, "//str[@name='min'][.='string1']", "//str[@name='max'][.='string3']", "//long[@name='count'][.='3']", "//long[@name='missing'][.='1']", "//long[@name='countDistinct'][.='3']", "count(//arr[@name='distinctValues']/str)=3");
    assertQ("test string cardinality", req("q", "*:*", "rows", "0", "stats", "true", "stats.field", "{!cardinality=true}active_s"), "//long[@name='cardinality'][.='3']");
    // stats over a string function
    assertQ("strdist func stats", req("q", "*:*", "stats", "true", "stats.field", "{!func}strdist('string22',active_s,edit)"), "//double[@name='min'][.='0.75']", "//double[@name='max'][.='0.875']", "//double[@name='sum'][.='2.375']", "//long[@name='count'][.='3']", "//long[@name='missing'][.='1']");
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) MapSolrParams(org.apache.solr.common.params.MapSolrParams) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SolrCore(org.apache.solr.core.SolrCore)

Example 33 with MapSolrParams

use of org.apache.solr.common.params.MapSolrParams in project lucene-solr by apache.

the class SSLMigrationTest method setUrlScheme.

private void setUrlScheme(String value) throws Exception {
    @SuppressWarnings("rawtypes") Map m = makeMap("action", CollectionAction.CLUSTERPROP.toString().toLowerCase(Locale.ROOT), "name", "urlScheme", "val", value);
    @SuppressWarnings("unchecked") SolrParams params = new MapSolrParams(m);
    SolrRequest request = new QueryRequest(params);
    request.setPath("/admin/collections");
    List<String> urls = new ArrayList<String>();
    for (Replica replica : getReplicas()) {
        urls.add(replica.getStr(ZkStateReader.BASE_URL_PROP));
    }
    //Create new SolrServer to configure new HttpClient w/ SSL config
    getLBHttpSolrClient(urls.toArray(new String[] {})).request(request);
}
Also used : MapSolrParams(org.apache.solr.common.params.MapSolrParams) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) SolrRequest(org.apache.solr.client.solrj.SolrRequest) ArrayList(java.util.ArrayList) SolrParams(org.apache.solr.common.params.SolrParams) MapSolrParams(org.apache.solr.common.params.MapSolrParams) Utils.makeMap(org.apache.solr.common.util.Utils.makeMap) Map(java.util.Map) Replica(org.apache.solr.common.cloud.Replica)

Example 34 with MapSolrParams

use of org.apache.solr.common.params.MapSolrParams in project lucene-solr by apache.

the class SharedFSAutoReplicaFailoverTest method testBasics.

// very slow tests, especially since jetty is started and stopped
// serially
private void testBasics() throws Exception {
    String collection1 = "solrj_collection";
    Create createCollectionRequest = CollectionAdminRequest.createCollection(collection1, "conf1", 2, 2).setMaxShardsPerNode(2).setRouterField("myOwnField").setAutoAddReplicas(true);
    CollectionAdminResponse response = createCollectionRequest.process(cloudClient);
    assertEquals(0, response.getStatus());
    assertTrue(response.isSuccess());
    waitForRecoveriesToFinish(collection1, false);
    String collection2 = "solrj_collection2";
    createCollectionRequest = CollectionAdminRequest.createCollection(collection2, "conf1", 2, 2).setMaxShardsPerNode(2).setRouterField("myOwnField").setAutoAddReplicas(false);
    CollectionAdminResponse response2 = createCollectionRequest.process(getCommonCloudSolrClient());
    assertEquals(0, response2.getStatus());
    assertTrue(response2.isSuccess());
    waitForRecoveriesToFinish(collection2, false);
    String collection3 = "solrj_collection3";
    createCollectionRequest = CollectionAdminRequest.createCollection(collection3, "conf1", 5, 1).setMaxShardsPerNode(1).setRouterField("myOwnField").setAutoAddReplicas(true);
    CollectionAdminResponse response3 = createCollectionRequest.process(getCommonCloudSolrClient());
    assertEquals(0, response3.getStatus());
    assertTrue(response3.isSuccess());
    waitForRecoveriesToFinish(collection3, false);
    // a collection has only 1 replica per a shard
    String collection4 = "solrj_collection4";
    createCollectionRequest = CollectionAdminRequest.createCollection(collection4, "conf1", 5, 1).setMaxShardsPerNode(5).setRouterField("text").setAutoAddReplicas(true);
    CollectionAdminResponse response4 = createCollectionRequest.process(getCommonCloudSolrClient());
    assertEquals(0, response4.getStatus());
    assertTrue(response4.isSuccess());
    waitForRecoveriesToFinish(collection4, false);
    // all collections
    String[] collections = { collection1, collection2, collection3, collection4 };
    // add some documents to collection4
    final int numDocs = 100;
    // indexed but not committed
    addDocs(collection4, numDocs, false);
    // no result because not committed yet
    queryAndAssertResultSize(collection4, 0, 10000);
    assertUlogDir(collections);
    ChaosMonkey.stop(jettys.get(1));
    ChaosMonkey.stop(jettys.get(2));
    Thread.sleep(5000);
    assertTrue("Timeout waiting for all live and active", ClusterStateUtil.waitForAllActiveAndLiveReplicas(cloudClient.getZkStateReader(), collection1, 120000));
    assertSliceAndReplicaCount(collection1);
    assertEquals(4, ClusterStateUtil.getLiveAndActiveReplicaCount(cloudClient.getZkStateReader(), collection1));
    assertTrue(ClusterStateUtil.getLiveAndActiveReplicaCount(cloudClient.getZkStateReader(), collection2) < 4);
    // collection3 has maxShardsPerNode=1, there are 4 standard jetties and one control jetty and 2 nodes stopped
    ClusterStateUtil.waitForLiveAndActiveReplicaCount(cloudClient.getZkStateReader(), collection3, 3, 30000);
    // collection4 has maxShardsPerNode=5 and setMaxShardsPerNode=5
    ClusterStateUtil.waitForLiveAndActiveReplicaCount(cloudClient.getZkStateReader(), collection4, 5, 30000);
    // all docs should be queried after failover
    // to query all docs
    cloudClient.commit();
    assertSingleReplicationAndShardSize(collection4, 5);
    queryAndAssertResultSize(collection4, numDocs, 10000);
    // collection1 should still be at 4
    assertEquals(4, ClusterStateUtil.getLiveAndActiveReplicaCount(cloudClient.getZkStateReader(), collection1));
    // and collection2 less than 4
    assertTrue(ClusterStateUtil.getLiveAndActiveReplicaCount(cloudClient.getZkStateReader(), collection2) < 4);
    assertUlogDir(collections);
    ChaosMonkey.stop(jettys);
    ChaosMonkey.stop(controlJetty);
    assertTrue("Timeout waiting for all not live", ClusterStateUtil.waitForAllReplicasNotLive(cloudClient.getZkStateReader(), 45000));
    ChaosMonkey.start(jettys);
    ChaosMonkey.start(controlJetty);
    assertTrue("Timeout waiting for all live and active", ClusterStateUtil.waitForAllActiveAndLiveReplicas(cloudClient.getZkStateReader(), collection1, 120000));
    assertSliceAndReplicaCount(collection1);
    assertSingleReplicationAndShardSize(collection3, 5);
    // all docs should be queried
    assertSingleReplicationAndShardSize(collection4, 5);
    queryAndAssertResultSize(collection4, numDocs, 10000);
    assertUlogDir(collections);
    int jettyIndex = random().nextInt(jettys.size());
    ChaosMonkey.stop(jettys.get(jettyIndex));
    ChaosMonkey.start(jettys.get(jettyIndex));
    assertTrue("Timeout waiting for all live and active", ClusterStateUtil.waitForAllActiveAndLiveReplicas(cloudClient.getZkStateReader(), collection1, 60000));
    assertSliceAndReplicaCount(collection1);
    assertUlogDir(collections);
    assertSingleReplicationAndShardSize(collection3, 5);
    ClusterStateUtil.waitForLiveAndActiveReplicaCount(cloudClient.getZkStateReader(), collection3, 5, 30000);
    assertSingleReplicationAndShardSize(collection4, 5);
    ClusterStateUtil.waitForLiveAndActiveReplicaCount(cloudClient.getZkStateReader(), collection4, 5, 30000);
    //disable autoAddReplicas
    Map m = makeMap("action", CollectionParams.CollectionAction.CLUSTERPROP.toLower(), "name", ZkStateReader.AUTO_ADD_REPLICAS, "val", "false");
    SolrRequest request = new QueryRequest(new MapSolrParams(m));
    request.setPath("/admin/collections");
    cloudClient.request(request);
    int currentCount = ClusterStateUtil.getLiveAndActiveReplicaCount(cloudClient.getZkStateReader(), collection1);
    ChaosMonkey.stop(jettys.get(3));
    //solr.xml has defined workLoopDelay=10s and waitAfterExpiration=10s
    //Hence waiting for 30 seconds to be on the safe side.
    Thread.sleep(30000);
    //Ensures that autoAddReplicas has not kicked in.
    assertTrue(currentCount > ClusterStateUtil.getLiveAndActiveReplicaCount(cloudClient.getZkStateReader(), collection1));
    //enable autoAddReplicas
    m = makeMap("action", CollectionParams.CollectionAction.CLUSTERPROP.toLower(), "name", ZkStateReader.AUTO_ADD_REPLICAS);
    request = new QueryRequest(new MapSolrParams(m));
    request.setPath("/admin/collections");
    cloudClient.request(request);
    assertTrue("Timeout waiting for all live and active", ClusterStateUtil.waitForAllActiveAndLiveReplicas(cloudClient.getZkStateReader(), collection1, 90000));
    assertSliceAndReplicaCount(collection1);
    assertUlogDir(collections);
    // restart all to test core saved state
    ChaosMonkey.stop(jettys);
    ChaosMonkey.stop(controlJetty);
    assertTrue("Timeout waiting for all not live", ClusterStateUtil.waitForAllReplicasNotLive(cloudClient.getZkStateReader(), 45000));
    ChaosMonkey.start(jettys);
    ChaosMonkey.start(controlJetty);
    assertTrue("Timeout waiting for all live and active", ClusterStateUtil.waitForAllActiveAndLiveReplicas(cloudClient.getZkStateReader(), collection1, 120000));
    assertSliceAndReplicaCount(collection1);
    assertUlogDir(collections);
    assertSliceAndReplicaCount(collection1);
    assertSingleReplicationAndShardSize(collection3, 5);
    // all docs should be queried
    assertSingleReplicationAndShardSize(collection4, 5);
    queryAndAssertResultSize(collection4, numDocs, 10000);
}
Also used : MapSolrParams(org.apache.solr.common.params.MapSolrParams) CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) Create(org.apache.solr.client.solrj.request.CollectionAdminRequest.Create) SolrRequest(org.apache.solr.client.solrj.SolrRequest) HashMap(java.util.HashMap) Map(java.util.Map) Utils.makeMap(org.apache.solr.common.util.Utils.makeMap)

Example 35 with MapSolrParams

use of org.apache.solr.common.params.MapSolrParams in project lucene-solr by apache.

the class BlobHandler method verifyWithRealtimeGet.

private void verifyWithRealtimeGet(String blobName, long version, SolrQueryRequest req, Map<String, Object> doc) {
    for (; ; ) {
        SolrQueryResponse response = new SolrQueryResponse();
        String id = blobName + "/" + version;
        forward(req, "/get", new MapSolrParams(singletonMap(ID, id)), response);
        if (response.getValues().get("doc") == null) {
            //ensure that the version does not exist
            return;
        } else {
            log.info("id {} already exists trying next ", id);
            version++;
            doc.put("version", version);
            id = blobName + "/" + version;
            doc.put(ID, id);
        }
    }
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) MapSolrParams(org.apache.solr.common.params.MapSolrParams)

Aggregations

MapSolrParams (org.apache.solr.common.params.MapSolrParams)50 HashMap (java.util.HashMap)33 SolrCore (org.apache.solr.core.SolrCore)24 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)20 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)19 SolrParams (org.apache.solr.common.params.SolrParams)14 Test (org.junit.Test)14 LinkedHashMap (java.util.LinkedHashMap)11 ArrayList (java.util.ArrayList)10 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)10 SolrException (org.apache.solr.common.SolrException)6 UpdateRequestHandler (org.apache.solr.handler.UpdateRequestHandler)6 SolrQueryRequestBase (org.apache.solr.request.SolrQueryRequestBase)6 Map (java.util.Map)4 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)4 Utils.makeMap (org.apache.solr.common.util.Utils.makeMap)4 IOException (java.io.IOException)3 SchemaField (org.apache.solr.schema.SchemaField)3 StringWriter (java.io.StringWriter)2 Collections.singletonMap (java.util.Collections.singletonMap)2