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

The following examples show how to use org.apache.solr.common.params.ModifiableSolrParams#set() . 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: HttpSolrClientFactoryBean.java    From dubbox with Apache License 2.0 6 votes vote down vote up
private void createCloudClient() {

		ModifiableSolrParams params = new ModifiableSolrParams();
		params.set(HttpClientUtil.PROP_MAX_CONNECTIONS, maxConnections);// 1000
		params.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, maxConnectionsPerHost);// 5000
		params.set(HttpClientUtil.PROP_CONNECTION_TIMEOUT, timeout);
		params.set(HttpClientUtil.PROP_SO_TIMEOUT, timeout);
		HttpClient client = HttpClientUtil.createClient(params);
		LBHttpSolrClient lbHttpSolrClient = new LBHttpSolrClient(client);
		CloudSolrClient cloudSolrClient = new CloudSolrClient(url, lbHttpSolrClient);
		if (zkClientTimeout != null) {
			cloudSolrClient.setZkClientTimeout(zkClientTimeout.intValue());
		}
		if (zkConnectTimeout != null) {
			cloudSolrClient.setZkConnectTimeout(zkConnectTimeout.intValue());
		}

		if (StringUtils.isNoneBlank(collection)) {
			cloudSolrClient.setDefaultCollection(collection);
		}
		cloudSolrClient.connect();
		this.setSolrClient(cloudSolrClient);
	}
 
Example 2
Source File: MtasSolrTestSearchConsistency.java    From mtas with Apache License 2.0 6 votes vote down vote up
/**
 * Cql query parser.
 *
 * @throws IOException
 *           Signals that an I/O exception has occurred.
 */
@org.junit.Test
public void cqlQueryParser() throws IOException {
  ModifiableSolrParams params = new ModifiableSolrParams();
  params.set("q",
      "{!mtas_cql field=\"mtas\" query=\"[pos=\\\"ADJ\\\"]{2}[pos=\\\"N\\\"]\"}");
  try {
    QueryResponse qResp1 = server.query("collection1", params);
    QueryResponse qResp2 = server.query("collection2", params);
    QueryResponse qResp3 = server.query("collection3", params);
    SolrDocumentList docList1 = qResp1.getResults();
    SolrDocumentList docList2 = qResp2.getResults();
    SolrDocumentList docList3 = qResp3.getResults();
    assertFalse(docList1.isEmpty());
    assertEquals(docList1.size(), (long) docList2.size() + docList3.size());
  } catch (SolrServerException e) {
    throw new IOException(e.getMessage(), e);
  }
}
 
Example 3
Source File: CollectionAdminRequest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
default ModifiableSolrParams mergeCollParams(Create createCollTemplate) {
  ModifiableSolrParams createCollParams = new ModifiableSolrParams(); // output target
  if (createCollTemplate == null) {
    return createCollParams;
  }
  final SolrParams collParams = createCollTemplate.getParams();
  final Iterator<String> pIter = collParams.getParameterNamesIterator();
  while (pIter.hasNext()) {
    String key = pIter.next();
    if (key.equals(CollectionParams.ACTION) || key.equals("name")) {
      continue;
    }
    createCollParams.set("create-collection." + key, collParams.getParams(key));
  }
  return createCollParams;
}
 
Example 4
Source File: OverseerNodePrioritizer.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void invokeOverseerOp(String electionNode, String op) {
  ModifiableSolrParams params = new ModifiableSolrParams();
  ShardHandler shardHandler = ((HttpShardHandlerFactory)shardHandlerFactory).getShardHandler(httpClient);
  params.set(CoreAdminParams.ACTION, CoreAdminAction.OVERSEEROP.toString());
  params.set("op", op);
  params.set("qt", adminPath);
  params.set("electionNode", electionNode);
  ShardRequest sreq = new ShardRequest();
  sreq.purpose = 1;
  String replica = zkStateReader.getBaseUrlForNodeName(LeaderElector.getNodeName(electionNode));
  sreq.shards = new String[]{replica};
  sreq.actualShards = sreq.shards;
  sreq.params = params;
  shardHandler.submit(sreq, replica, sreq.params);
  shardHandler.takeCompletedOrError();
}
 
Example 5
Source File: SolrTestCaseJ4.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public static Long deleteAndGetVersion(String id, SolrParams params) throws Exception {
  if (params==null || params.get("versions") == null) {
    ModifiableSolrParams mparams = new ModifiableSolrParams(params);
    mparams.set("versions","true");
    params = mparams;
  }
  String response = updateJ(jsonDelId(id), params);
  @SuppressWarnings({"rawtypes"})
  Map rsp = (Map)ObjectBuilder.fromJSON(response);
  @SuppressWarnings({"rawtypes"})
  List lst = (List)rsp.get("deletes");
  if (lst == null || lst.size() == 0) return null;
  return (Long) lst.get(1);
}
 
Example 6
Source File: CrossCollectionJoinQuery.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private TupleStream createCloudSolrStream(SolrClientCache solrClientCache) throws IOException {
  String streamZkHost;
  if (zkHost != null) {
    streamZkHost = zkHost;
  } else {
    streamZkHost = searcher.getCore().getCoreContainer().getZkController().getZkServerAddress();
  }

  ModifiableSolrParams params = new ModifiableSolrParams(otherParams);
  params.set(CommonParams.Q, query);
  String fq = createHashRangeFq();
  if (fq != null) {
    params.add(CommonParams.FQ, fq);
  }
  params.set(CommonParams.FL, fromField);
  params.set(CommonParams.SORT, fromField + " asc");
  params.set(CommonParams.QT, "/export");
  params.set(CommonParams.WT, CommonParams.JAVABIN);

  StreamContext streamContext = new StreamContext();
  streamContext.setSolrClientCache(solrClientCache);

  TupleStream cloudSolrStream = new CloudSolrStream(streamZkHost, collection, params);
  TupleStream uniqueStream = new UniqueStream(cloudSolrStream, new FieldEqualitor(fromField));
  uniqueStream.setStreamContext(streamContext);
  return uniqueStream;
}
 
Example 7
Source File: DelegationTokenRequest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public SolrParams getParams() {
  ModifiableSolrParams params = new ModifiableSolrParams();
  params.set(OP_KEY, "RENEWDELEGATIONTOKEN");
  params.set(TOKEN_KEY, token);
  return params;
}
 
Example 8
Source File: TestCloudManagedSchema.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
  ModifiableSolrParams params = new ModifiableSolrParams();
  params.set(CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.STATUS.toString());
  QueryRequest request = new QueryRequest(params);
  request.setPath("/admin/cores");
  int which = r.nextInt(clients.size());
  HttpSolrClient client = (HttpSolrClient)clients.get(which);
  String previousBaseURL = client.getBaseURL();
  // Strip /collection1 step from baseURL - requests fail otherwise
  client.setBaseURL(previousBaseURL.substring(0, previousBaseURL.lastIndexOf("/")));
  @SuppressWarnings({"rawtypes"})
  NamedList namedListResponse = client.request(request);
  client.setBaseURL(previousBaseURL); // Restore baseURL 
  @SuppressWarnings({"rawtypes"})
  NamedList status = (NamedList)namedListResponse.get("status");
  @SuppressWarnings({"rawtypes"})
  NamedList collectionStatus = (NamedList)status.getVal(0);
  String collectionSchema = (String)collectionStatus.get(CoreAdminParams.SCHEMA);
  // Make sure the upgrade to managed schema happened
  assertEquals("Schema resource name differs from expected name", "managed-schema", collectionSchema);

  SolrZkClient zkClient = new SolrZkClient(zkServer.getZkHost(), 30000);
  try {
    // Make sure "DO NOT EDIT" is in the content of the managed schema
    String fileContent = getFileContentFromZooKeeper(zkClient, "/solr/configs/conf1/managed-schema");
    assertTrue("Managed schema is missing", fileContent.contains("DO NOT EDIT"));

    // Make sure the original non-managed schema is no longer in ZooKeeper
    assertFileNotInZooKeeper(zkClient, "/solr/configs/conf1", "schema.xml");

    // Make sure the renamed non-managed schema is present in ZooKeeper
    fileContent = getFileContentFromZooKeeper(zkClient, "/solr/configs/conf1/schema.xml.bak");
    assertTrue("schema file doesn't contain '<schema'", fileContent.contains("<schema"));
  } finally {
    if (zkClient != null) {
      zkClient.close();
    }
  }
}
 
Example 9
Source File: CollectionAdminRequest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public SolrParams getParams() {
  ModifiableSolrParams params = (ModifiableSolrParams) super.getParams();
  params.set(CoreAdminParams.COLLECTION, collection);
  params.set(CoreAdminParams.COMMIT_NAME, commitName);
  return params;
}
 
Example 10
Source File: BasicDistributedZkTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
protected QueryResponse queryServer(ModifiableSolrParams params) throws SolrServerException, IOException {

  if (r.nextBoolean())
    return super.queryServer(params);

  if (r.nextBoolean())
    params.set("collection",DEFAULT_COLLECTION);

  QueryResponse rsp = getCommonCloudSolrClient().query(params);
  return rsp;
}
 
Example 11
Source File: IterativeMergeStrategy.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private CloseableHttpClient getHttpClient() {
  ModifiableSolrParams params = new ModifiableSolrParams();
  params.set(HttpClientUtil.PROP_MAX_CONNECTIONS, 128);
  params.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, 32);
  CloseableHttpClient httpClient = HttpClientUtil.createClient(params);

  return httpClient;
}
 
Example 12
Source File: CoreAdminRequest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public SolrParams getParams() {
  if( action == null ) {
    throw new RuntimeException( "no action specified!" );
  }
  ModifiableSolrParams params = new ModifiableSolrParams();
  params.set( CoreAdminParams.ACTION, action.toString() );
 
  params.set( CoreAdminParams.CORE, core );
  
  if (nodeName != null) {
    params.set( "nodeName", nodeName);
  }
  
  if (coreNodeName != null) {
    params.set( "coreNodeName", coreNodeName);
  }
  
  if (state != null) {
    params.set(ZkStateReader.STATE_PROP, state.toString());
  }
  
  if (checkLive != null) {
    params.set( "checkLive", checkLive);
  }
  
  if (onlyIfLeader != null) {
    params.set( "onlyIfLeader", onlyIfLeader);
  }
  
  if (onlyIfLeaderActive != null) {
    params.set( "onlyIfLeaderActive", onlyIfLeaderActive);
  }

  return params;
}
 
Example 13
Source File: TestSolrCloudWithDelegationTokens.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked"})
private int getStatusCode(String token, final String user, final String op, HttpSolrClient client)
throws Exception {
  SolrClient delegationTokenClient;
  if (random().nextBoolean()) delegationTokenClient = new HttpSolrClient.Builder(client.getBaseURL().toString())
      .withKerberosDelegationToken(token)
      .withResponseParser(client.getParser())
      .build();
  else delegationTokenClient = new CloudSolrClient.Builder(Collections.singletonList(miniCluster.getZkServer().getZkAddress()), Optional.empty())
      .withLBHttpSolrClientBuilder(new LBHttpSolrClient.Builder()
          .withSocketTimeout(30000).withConnectionTimeout(15000)
          .withResponseParser(client.getParser())
          .withHttpSolrClientBuilder(
              new HttpSolrClient.Builder()
                  .withKerberosDelegationToken(token)
          ))
      .build();
  try {
    ModifiableSolrParams p = new ModifiableSolrParams();
    if (user != null) p.set(USER_PARAM, user);
    if (op != null) p.set("op", op);
    @SuppressWarnings({"rawtypes"})
    SolrRequest req = getAdminRequest(p);
    if (user != null || op != null) {
      Set<String> queryParams = new HashSet<>();
      if (user != null) queryParams.add(USER_PARAM);
      if (op != null) queryParams.add("op");
      req.setQueryParams(queryParams);
    }
    try {
      delegationTokenClient.request(req, null);
      return HttpStatus.SC_OK;
    } catch (BaseHttpSolrClient.RemoteSolrException re) {
      return re.code();
    }
  } finally {
    delegationTokenClient.close();
  }
}
 
Example 14
Source File: CollectionAdminRequest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public SolrParams getParams() {
  ModifiableSolrParams params = new ModifiableSolrParams(super.getParams());
  params.set(CoreAdminParams.REPLICA, replica);
  params.set("property", propertyName);
  return params;
}
 
Example 15
Source File: AbstractFullDistribZkTestBase.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
protected void logReplicationDetails(Replica replica, StringBuilder builder) throws IOException {
  try (HttpSolrClient client = new HttpSolrClient.Builder(replica.getCoreUrl()).build()) {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("qt", "/replication");
    params.set(ReplicationHandler.COMMAND, ReplicationHandler.CMD_DETAILS);
    try {
      QueryResponse response = client.query(params);
      builder.append(String.format(Locale.ROOT, "%s: %s%s", replica.getName(), response.getResponse(), System.lineSeparator()));
    } catch (SolrServerException e) {
      log.warn("Unable to ger replication details for replica {}", replica.getName(), e);
    }
  }
}
 
Example 16
Source File: DistributedFacetExistsSmallTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private void checkRandomParams() throws Exception {
  final ModifiableSolrParams params = buildParams();
  Random rand = random();

  if (rand.nextBoolean()) {
    int from;
    params.set("q", "["+(from = rand.nextInt(maxId/2))+
                " TO "+((from-1)+(rand.nextInt(maxId)))+"]");
  }
  
  int offset = 0;
  int indexSize = 6;
  if (rand .nextInt(100) < 20) {
    if (rand.nextBoolean()) {
      offset = rand.nextInt(100) < 10 ? rand.nextInt(indexSize *2) : rand.nextInt(indexSize/3+1);
    }
    params.add("facet.offset", Integer.toString(offset));
  }

  int limit = 100;
  if (rand.nextInt(100) < 20) {
    if (rand.nextBoolean()) {
      limit = rand.nextInt(100) < 10 ? rand.nextInt(indexSize/2+1) : rand.nextInt(indexSize*2);
    }
    params.add("facet.limit", Integer.toString(limit));
  }

  if (rand.nextBoolean()) {
    params.add("facet.sort", rand.nextBoolean() ? "index" : "count");
  }

  if ( rand.nextInt(100) < 20) {
    final String[] prefixes = new String[] {"A","B","C"};
    params.add("facet.prefix", prefixes[rand.nextInt(prefixes.length)]);
  }

  // don't bother trying to to test facet.missing=true + facet.limit=0
  // distrib & non-distrib are known to behave differently in this 
  if (rand.nextInt(100) < 20 && 0 < params.getInt("facet.limit", 100)) {
    params.add("facet.missing", "true");
  }
  
  if (rand.nextInt(100) < 20) { // assigning only valid vals
    params.add("facet.mincount", rand.nextBoolean() ? "0": "1" );
  }
  
  query(params);
}
 
Example 17
Source File: TestRedisQParserPluginIT.java    From solr-redis with Apache License 2.0 4 votes vote down vote up
@Test(expected = RuntimeException.class)
public void shouldThrowExceptionOnEvalReturningNestedTable() throws Exception {
  final ModifiableSolrParams params = new ModifiableSolrParams();
  params.set("q", "{!redis command=eval script='return {1, {1}};'}string_field");
  JQ(req(params));
}
 
Example 18
Source File: CollectionAdminRequest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public SolrParams getParams() {
  ModifiableSolrParams params = (ModifiableSolrParams) super.getParams();
  params.set(CoreAdminParams.COLLECTION, collection);
  params.set(CoreAdminParams.NAME, backupName);
  params.set(CoreAdminParams.BACKUP_LOCATION, location); //note: optional
  params.set("collection.configName", configName); //note: optional
  if (maxShardsPerNode != null) {
    params.set( ZkStateReader.MAX_SHARDS_PER_NODE, maxShardsPerNode);
  }
  if (replicationFactor != null && nrtReplicas != null) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
        "Cannot set both replicationFactor and nrtReplicas as they mean the same thing");
  }
  if (replicationFactor != null) {
    params.set(ZkStateReader.REPLICATION_FACTOR, replicationFactor);
  }
  if (nrtReplicas != null) {
    params.set(ZkStateReader.NRT_REPLICAS, nrtReplicas);
  }
  if (pullReplicas != null) {
    params.set(ZkStateReader.PULL_REPLICAS, pullReplicas);
  }
  if (tlogReplicas != null) {
    params.set(ZkStateReader.TLOG_REPLICAS, tlogReplicas);
  }
  if (autoAddReplicas != null) {
    params.set(ZkStateReader.AUTO_ADD_REPLICAS, autoAddReplicas);
  }
  if (properties != null) {
    addProperties(params, properties);
  }
  if (repositoryName.isPresent()) {
    params.set(CoreAdminParams.BACKUP_REPOSITORY, repositoryName.get());
  }
  if (createNodeSet.isPresent()) {
    params.set(CREATE_NODE_SET_PARAM, createNodeSet.get());
  }
  if (createNodeSetShuffle.isPresent()) {
    params.set(CREATE_NODE_SET_SHUFFLE_PARAM, createNodeSetShuffle.get());
  }

  return params;
}
 
Example 19
Source File: AbstractAlfrescoDistributedIT.java    From SearchServices with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Returns the QueryResponse from {@link #queryRandomShard}
 */
protected QueryResponse query(SolrClient solrClient, boolean setDistribParams, SolrParams p) throws Exception
{
    Random r = SOLR_RANDOM_SUPPLIER.getRandomGenerator();
    final ModifiableSolrParams params = new ModifiableSolrParams(p);

    // TODO: look into why passing true causes fails
    params.set("distrib", "false");
    final QueryResponse controlRsp = solrClient.query(params);
    SOLR_RESPONSE_COMPARATOR.validateResponse(controlRsp);

    params.remove("distrib");
    if (setDistribParams)
        setDistributedParams(params);

    QueryResponse rsp = queryRandomShard(params);

    SOLR_RESPONSE_COMPARATOR.compareResponses(rsp, controlRsp);

    if (stress > 0)
    {
        log.info("starting stress...");
        Thread[] threads = new Thread[nThreads];
        for (int i = 0; i < threads.length; i++)
        {
            threads[i] = new Thread(() -> {
                for (int j = 0; j < stress; j++)
                {
                    int which = r.nextInt(clientShards.size());
                    SolrClient client = clientShards.get(which);
                    try
                    {
                        QueryResponse rsp1 = client.query(new ModifiableSolrParams(params));
                        if (verifyStress)
                        {
                            SOLR_RESPONSE_COMPARATOR.compareResponses(rsp1, controlRsp);
                        }
                    } catch (SolrServerException | IOException e)
                    {
                        throw new RuntimeException(e);
                    }
                }
            });
            threads[i].start();
        }

        for (Thread thread : threads)
        {
            thread.join();
        }
    }
    return rsp;
}
 
Example 20
Source File: CollectionAdminRequest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public SolrParams getParams() {
  ModifiableSolrParams params = (ModifiableSolrParams) super.getParams();

  if (configName != null)
    params.set("collection.configName", configName);
  if (createNodeSet != null)
    params.set(CREATE_NODE_SET_PARAM, createNodeSet);
  if (numShards != null) {
    params.set( ZkStateReader.NUM_SHARDS_PROP, numShards);
  }
  if (maxShardsPerNode != null) {
    params.set( ZkStateReader.MAX_SHARDS_PER_NODE, maxShardsPerNode);
  }
  if (routerName != null)
    params.set( "router.name", routerName);
  if (shards != null)
    params.set("shards", shards);
  if (routerField != null) {
    params.set("router.field", routerField);
  }
  if (nrtReplicas != null) {
    params.set( ZkStateReader.NRT_REPLICAS, nrtReplicas);
  }
  if (autoAddReplicas != null) {
    params.set(ZkStateReader.AUTO_ADD_REPLICAS, autoAddReplicas);
  }
  if (properties != null) {
    addProperties(params, properties);
  }
  if (pullReplicas != null) {
    params.set(ZkStateReader.PULL_REPLICAS, pullReplicas);
  }
  if (tlogReplicas != null) {
    params.set(ZkStateReader.TLOG_REPLICAS, tlogReplicas);
  }
  if (rule != null) params.set(DocCollection.RULE, rule);
  if (snitch != null) params.set(DocCollection.SNITCH, snitch);
  params.setNonNull(POLICY, policy);
  params.setNonNull(WITH_COLLECTION, withCollection);
  params.setNonNull(ALIAS, alias);
  return params;
}