当前位置: 首页>>代码示例>>Java>>正文


Java StrUtils类代码示例

本文整理汇总了Java中org.apache.solr.common.util.StrUtils的典型用法代码示例。如果您正苦于以下问题:Java StrUtils类的具体用法?Java StrUtils怎么用?Java StrUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


StrUtils类属于org.apache.solr.common.util包,在下文中一共展示了StrUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toString

import org.apache.solr.common.util.StrUtils; //导入依赖的package包/类
/** Like {@link #toQueryString()}, but only replacing enough chars so that
 * the URL may be unambiguously pasted back into a browser.
 * This method can be used to properly log query parameters without
 * making them unreadable.
 * <p>
 * Characters with a numeric value less than 32 are encoded.
 * &amp;,=,%,+,space are encoded.
 */
@Override
public String toString() {
    final StringBuilder sb = new StringBuilder(128);
    try {
        boolean first=true;
        for (final Iterator<String> it = getParameterNamesIterator(); it.hasNext();) {
            final String name = it.next();
            for (String val : getParams(name)) {
                if (!first) sb.append('&');
                first=false;
                StrUtils.partialURLEncodeVal(sb, name);
                sb.append('=');
                StrUtils.partialURLEncodeVal(sb, val);
            }
        }
        return sb.toString();
    } catch (IOException e) {
        // impossible!
        throw new AssertionError(e);
    }
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:30,代码来源:SolrParams.java

示例2: parseFieldMapStr

import org.apache.solr.common.util.StrUtils; //导入依赖的package包/类
private Map<Integer, String> parseFieldMapStr(String fieldMapStr) {
  Map<Integer, String> result = new HashMap<Integer, String>();
  // looks like: number=name,number=name, ....
  List<String> keyValues = StrUtils.splitSmart(fieldMapStr, ',');
  for (String keyValue : keyValues) {
    String[] splits = keyValue.split("=");
    if (splits != null && splits.length == 2) {
      result.put(Integer.parseInt(splits[0].trim()), splits[1].trim());
    } else {
      throw new RuntimeException("Invalid Field mapping passed in: " + fieldMapStr);
    }
  }
  // check whether or not the fieldId is on the field map
  if (result.containsValue(idField)) {
    useDefaultId = false;
  }
  return result;
}
 
开发者ID:lucidworks,项目名称:hadoop-solr,代码行数:19,代码来源:CSVIngestMapper.java

示例3: getCollectionList

import org.apache.solr.common.util.StrUtils; //导入依赖的package包/类
private Set<String> getCollectionList(ClusterState clusterState,
    String collection) {
  // Extract each comma separated collection name and store in a List.
  List<String> rawCollectionsList = StrUtils.splitSmart(collection, ",", true);
  Set<String> collectionsList = new HashSet<>();
  // validate collections
  for (String collectionName : rawCollectionsList) {
    if (!clusterState.getCollections().contains(collectionName)) {
      Aliases aliases = zkStateReader.getAliases();
      String alias = aliases.getCollectionAlias(collectionName);
      if (alias != null) {
        List<String> aliasList = StrUtils.splitSmart(alias, ",", true); 
        collectionsList.addAll(aliasList);
        continue;
      }
      
      throw new SolrException(ErrorCode.BAD_REQUEST, "Collection not found: " + collectionName);
    }
    
    collectionsList.add(collectionName);
  }
  return collectionsList;
}
 
开发者ID:europeana,项目名称:search,代码行数:24,代码来源:CloudSolrServer.java

示例4: toString

import org.apache.solr.common.util.StrUtils; //导入依赖的package包/类
@Override
public String toString() {
  StringBuilder sb = new StringBuilder(128);
  try {
    boolean first=true;

    for (Map.Entry<String,String[]> entry : map.entrySet()) {
      String key = entry.getKey();
      String[] valarr = entry.getValue();

      for (String val : valarr) {
        if (!first) sb.append('&');
        first=false;
        sb.append(key);
        sb.append('=');
        StrUtils.partialURLEncodeVal(sb, val==null ? "" : val);
      }
    }
  }
  catch (IOException e) {throw new RuntimeException(e);}  // can't happen

  return sb.toString();
}
 
开发者ID:europeana,项目名称:search,代码行数:24,代码来源:MultiMapSolrParams.java

示例5: toString

import org.apache.solr.common.util.StrUtils; //导入依赖的package包/类
@Override
public String toString() {
  StringBuilder sb = new StringBuilder(128);
  try {
    boolean first=true;

    for (Map.Entry<String,String> entry : map.entrySet()) {
      String key = entry.getKey();
      String val = entry.getValue();

      if (!first) sb.append('&');
      first=false;
      sb.append(key);
      sb.append('=');
      StrUtils.partialURLEncodeVal(sb, val==null ? "" : val);
    }
  }
  catch (IOException e) {throw new RuntimeException(e);}  // can't happen

  return sb.toString();
}
 
开发者ID:europeana,项目名称:search,代码行数:22,代码来源:MapSolrParams.java

示例6: init

import org.apache.solr.common.util.StrUtils; //导入依赖的package包/类
@Override
public void init(final NamedList args) {
  if (args != null) {
    SolrParams params = SolrParams.toSolrParams(args);
    boolean enabled = params.getBool("enabled", true);
    this.enabled = enabled;

    overwriteDupes = params.getBool("overwriteDupes", true);

    signatureField = params.get("signatureField", "signatureField");

    signatureClass = params.get("signatureClass",
        "org.apache.solr.update.processor.Lookup3Signature");
    this.params = params;

    Object fields = args.get("fields");
    sigFields = fields == null ? null: StrUtils.splitSmart((String)fields, ",", true); 
    if (sigFields != null) {
      Collections.sort(sigFields);
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:23,代码来源:SignatureUpdateProcessorFactory.java

示例7: requestUpdates

import org.apache.solr.common.util.StrUtils; //导入依赖的package包/类
private boolean requestUpdates(ShardResponse srsp, List<Long> toRequest) {
  String replica = srsp.getShardRequest().shards[0];

  log.info(msg() + "Requesting updates from " + replica + "n=" + toRequest.size() + " versions=" + toRequest);

  // reuse our original request object
  ShardRequest sreq = srsp.getShardRequest();

  sreq.purpose = 0;
  sreq.params = new ModifiableSolrParams();
  sreq.params.set("qt", "/get");
  sreq.params.set("distrib", false);
  sreq.params.set("getUpdates", StrUtils.join(toRequest, ','));
  sreq.params.set("onlyIfActive", onlyIfActive);
  sreq.responses.clear();  // needs to be zeroed for correct correlation to occur

  shardHandler.submit(sreq, sreq.shards[0], sreq.params);

  return true;
}
 
开发者ID:europeana,项目名称:search,代码行数:21,代码来源:PeerSync.java

示例8: makeURLList

import org.apache.solr.common.util.StrUtils; //导入依赖的package包/类
/**
 * Creates a randomized list of urls for the given shard.
 *
 * @param shard the urls for the shard, separated by '|'
 * @return A list of valid urls (including protocol) that are replicas for the shard
 */
public List<String> makeURLList(String shard) {
  List<String> urls = StrUtils.splitSmart(shard, "|", true);

  // convert shard to URL
  for (int i=0; i<urls.size(); i++) {
    urls.set(i, buildUrl(urls.get(i)));
  }

  //
  // Shuffle the list instead of use round-robin by default.
  // This prevents accidental synchronization where multiple shards could get in sync
  // and query the same replica at the same time.
  //
  if (urls.size() > 1)
    Collections.shuffle(urls, r);

  return urls;
}
 
开发者ID:europeana,项目名称:search,代码行数:25,代码来源:HttpShardHandlerFactory.java

示例9: prepare

import org.apache.solr.common.util.StrUtils; //导入依赖的package包/类
@Override
public void prepare(ResponseBuilder rb) throws IOException {
  SolrParams params = rb.req.getParams();
  if (params.getBool(TermsParams.TERMS, false)) {
    rb.doTerms = true;
  }

  // TODO: temporary... this should go in a different component.
  String shards = params.get(ShardParams.SHARDS);
  if (shards != null) {
    rb.isDistrib = true;
    if (params.get(ShardParams.SHARDS_QT) == null) {
      throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "No shards.qt parameter specified");
    }
    List<String> lst = StrUtils.splitSmart(shards, ",", true);
    rb.shards = lst.toArray(new String[lst.size()]);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:TermsComponent.java

示例10: processSync

import org.apache.solr.common.util.StrUtils; //导入依赖的package包/类
public void processSync(ResponseBuilder rb, int nVersions, String sync) {
  
  boolean onlyIfActive = rb.req.getParams().getBool("onlyIfActive", false);
  
  if (onlyIfActive) {
    if (!rb.req.getCore().getCoreDescriptor().getCloudDescriptor().getLastPublished().equals(ZkStateReader.ACTIVE)) {
      log.info("Last published state was not ACTIVE, cannot sync.");
      rb.rsp.add("sync", "false");
      return;
    }
  }
  
  List<String> replicas = StrUtils.splitSmart(sync, ",", true);
  
  boolean cantReachIsSuccess = rb.req.getParams().getBool("cantReachIsSuccess", false);
  
  PeerSync peerSync = new PeerSync(rb.req.getCore(), replicas, nVersions, cantReachIsSuccess, true);
  boolean success = peerSync.sync();
  
  // TODO: more complex response?
  rb.rsp.add("sync", success);
}
 
开发者ID:europeana,项目名称:search,代码行数:23,代码来源:RealTimeGetComponent.java

示例11: doSimpleQuery

import org.apache.solr.common.util.StrUtils; //导入依赖的package包/类
/**
 * Executes a basic query
 */
public static DocList doSimpleQuery(String sreq,
                                    SolrQueryRequest req,
                                    int start, int limit) throws IOException {
  List<String> commands = StrUtils.splitSmart(sreq,';');

  String qs = commands.size() >= 1 ? commands.get(0) : "";
  try {
  Query query = QParser.getParser(qs, null, req).getQuery();

  // If the first non-query, non-filter command is a simple sort on an indexed field, then
  // we can use the Lucene sort ability.
  Sort sort = null;
  if (commands.size() >= 2) {
    sort = QueryParsing.parseSortSpec(commands.get(1), req).getSort();
  }

  DocList results = req.getSearcher().getDocList(query,(DocSet)null, sort, start, limit);
  return results;
  } catch (SyntaxError e) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Error parsing query: " + qs);
  }

}
 
开发者ID:europeana,项目名称:search,代码行数:27,代码来源:SolrPluginUtils.java

示例12: assertParamsEquals

import org.apache.solr.common.util.StrUtils; //导入依赖的package包/类
private void assertParamsEquals(TrackingShardHandlerFactory.ShardRequestAndParams requestAndParams, String paramName, String... values) {
  if (requestAndParams == null) return;
  int expectedCount = values.length;
  String[] params = requestAndParams.params.getParams(paramName);
  if (expectedCount > 0 && (params == null || params.length == 0)) {
    fail("Expected non-zero number of '" + paramName + "' parameters in request");
  }
  Set<String> requestedFields = new HashSet<>();
  for (String p : params) {
    requestedFields.addAll(StrUtils.splitSmart(p, ','));
  }
  assertEquals("Number of requested fields do not match with expectations", expectedCount, requestedFields.size());
  for (String field : values) {
    if (!requestedFields.contains(field)) {
      fail("Field " + field + " not found in param: " + paramName + " request had " + paramName + "=" + requestedFields);
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:DistributedQueryComponentOptimizationTest.java

示例13: doQuery

import org.apache.solr.common.util.StrUtils; //导入依赖的package包/类
void doQuery(String expectedDocs, String... queryParams) throws Exception {

    List<String> strs = StrUtils.splitSmart(expectedDocs, ",", true);
    Map<String, Object> expectedIds = new HashMap<>();
    for (int i=0; i<strs.size(); i+=2) {
      String id = strs.get(i);
      String vS = strs.get(i+1);
      Long v = Long.valueOf(vS);
      expectedIds.put(id,v);
    }

    QueryResponse rsp = cloudClient.query(params(queryParams));
    Map<String, Object> obtainedIds = new HashMap<>();
    for (SolrDocument doc : rsp.getResults()) {
      obtainedIds.put((String) doc.get("id"), doc.get(vfield));
    }

    assertEquals(expectedIds, obtainedIds);
  }
 
开发者ID:europeana,项目名称:search,代码行数:20,代码来源:TestDistribDocBasedVersion.java

示例14: doRTG

import org.apache.solr.common.util.StrUtils; //导入依赖的package包/类
void doRTG(String ids, String versions) throws Exception {
  Map<String, Object> expectedIds = new HashMap<>();
  List<String> strs = StrUtils.splitSmart(ids, ",", true);
  List<String> verS = StrUtils.splitSmart(versions, ",", true);
  for (int i=0; i<strs.size(); i++) {
    expectedIds.put(strs.get(i), Long.valueOf(verS.get(i)));
  }

  ss.query(params("qt","/get", "ids",ids));

  QueryResponse rsp = cloudClient.query(params("qt","/get", "ids",ids));
  Map<String, Object> obtainedIds = new HashMap<>();
  for (SolrDocument doc : rsp.getResults()) {
    obtainedIds.put((String) doc.get("id"), doc.get(vfield));
  }

  assertEquals(expectedIds, obtainedIds);
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:TestDistribDocBasedVersion.java

示例15: process

import org.apache.solr.common.util.StrUtils; //导入依赖的package包/类
public NamedList<Object> process() throws IOException {
    if(this.docs == null){
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "No documents matched to build joint probabilities");
    }
    NamedList<Object> pivots = new NamedList<Object>();

    for(String sPivotList: this.fields) {
        List<String> lPivotList = StrUtils.splitSmart(sPivotList, ',');
        // ensure at least 2 items
        if(lPivotList.size() == 1){
            lPivotList.add(0, lPivotList.get(0));
        }
        Deque<String> queue = new LinkedList<String>(lPivotList);
        String fieldName = queue.removeFirst();
        NamedList<Integer> facetCounts = this.getTermCounts(fieldName, fieldName, minCount, limit, this.docs);
        pivots.add(fieldName, doPivots(facetCounts, fieldName, fieldName, queue, this.docs));
    }
    return pivots;
}
 
开发者ID:DiceTechJobs,项目名称:SolrPlugins,代码行数:20,代码来源:JointCounts.java


注:本文中的org.apache.solr.common.util.StrUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。