本文整理汇总了Java中org.apache.solr.common.util.StrUtils.splitSmart方法的典型用法代码示例。如果您正苦于以下问题:Java StrUtils.splitSmart方法的具体用法?Java StrUtils.splitSmart怎么用?Java StrUtils.splitSmart使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.solr.common.util.StrUtils
的用法示例。
在下文中一共展示了StrUtils.splitSmart方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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);
}
示例4: 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);
}
}
}
示例5: 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);
}
示例6: 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;
}
示例7: 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;
}
示例8: 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);
}
示例9: 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.parseSort(commands.get(1), req);
}
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);
}
}
示例10: 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()]);
}
}
示例11: newExcludeBytesRefFilter
import org.apache.solr.common.util.StrUtils; //导入方法依赖的package包/类
protected Predicate<BytesRef> newExcludeBytesRefFilter(String field, SolrParams params) {
final String exclude = params.getFieldParam(field, FacetParams.FACET_EXCLUDETERMS);
if (exclude == null) {
return null;
}
final Set<String> excludeTerms = new HashSet<>(StrUtils.splitSmart(exclude, ",", true));
return new Predicate<BytesRef>() {
@Override
public boolean test(BytesRef bytesRef) {
return !excludeTerms.contains(bytesRef.utf8ToString());
}
};
}
示例12: modifyRequestForPivotFacets
import org.apache.solr.common.util.StrUtils; //导入方法依赖的package包/类
private void modifyRequestForPivotFacets(ResponseBuilder rb,
ShardRequest sreq,
SimpleOrderedMap<PivotFacet> pivotFacets) {
for (Entry<String,PivotFacet> pfwEntry : pivotFacets) {
PivotFacet pivot = pfwEntry.getValue();
for (String pivotField : StrUtils.splitSmart(pivot.getKey(), ',')) {
modifyRequestForIndividualPivotFacets(rb, sreq, pivotField);
}
}
}
示例13: FacetBase
import org.apache.solr.common.util.StrUtils; //导入方法依赖的package包/类
public FacetBase(ResponseBuilder rb, String facetType, String facetStr) {
this.facetType = facetType;
this.facetStr = facetStr;
try {
this.localParams = QueryParsing.getLocalParams(facetStr,
rb.req.getParams());
} catch (SyntaxError e) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
}
this.facetOn = facetStr;
this.key = facetStr;
if (localParams != null) {
// remove local params unless it's a query
if (!facetType.equals(FacetParams.FACET_QUERY)) {
facetOn = localParams.get(CommonParams.VALUE);
key = facetOn;
}
key = localParams.get(CommonParams.OUTPUT_KEY, key);
String tagStr = localParams.get(CommonParams.TAG);
this.tags = tagStr == null ? Collections.<String>emptyList() : StrUtils.splitSmart(tagStr,',');
String threadStr = localParams.get(CommonParams.THREADS);
this.threadCount = threadStr != null ? Integer.parseInt(threadStr) : -1;
String excludeStr = localParams.get(CommonParams.EXCLUDE);
if (StringUtils.isEmpty(excludeStr)) {
this.excludeTags = Collections.emptyList();
} else {
this.excludeTags = StrUtils.splitSmart(excludeStr,',');
}
}
}
示例14: getAliasList
import org.apache.solr.common.util.StrUtils; //导入方法依赖的package包/类
protected List<String> getAliasList(CloudSolrClient cloudSolrClient, String collectionAlias) {
ZkStateReader zkStateReader = cloudSolrClient.getZkStateReader();
Aliases aliases = zkStateReader.getAliases();
String collectionsInAlias = aliases.getCollectionAlias(collectionAlias);
log.info("Looked up collection list "+collectionsInAlias+" for collection collectionsInAlias: "+collectionAlias);
return (collectionsInAlias != null) ? StrUtils.splitSmart(collectionsInAlias, ",", true) : new ArrayList<String>(0);
}
示例15: doQuery
import org.apache.solr.common.util.StrUtils; //导入方法依赖的package包/类
public void doQuery(DocCollection coll, String id, String expectedShards) {
DocRouter router = coll.getRouter();
Collection<Slice> slices = router.getSearchSlices(id, null, coll);
List<String> expectedShardStr = StrUtils.splitSmart(expectedShards, ",", true);
HashSet<String> expectedSet = new HashSet<>(expectedShardStr);
HashSet<String> obtainedSet = new HashSet<>();
for (Slice slice : slices) {
obtainedSet.add(slice.getName());
}
assertEquals(slices.size(), obtainedSet.size()); // make sure no repeated slices
assertEquals(expectedSet, obtainedSet);
}