本文整理汇总了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.
* &,=,%,+,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);
}
}
示例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;
}
示例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;
}
示例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();
}
示例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();
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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()]);
}
}
示例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);
}
示例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);
}
}
示例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);
}
}
}
示例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);
}
示例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);
}
示例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;
}