public static List<String> splitSmart(String s, char separator) { ArrayList<String> lst = new ArrayList<>(4); splitSmart(s, separator, lst); return lst; } /**
private static List<String> splitCollections(String collections) { return Collections.unmodifiableList(StrUtils.splitSmart(collections, ",", true)); }
public static List<String> getPathSegments(String path) { if (path == null || path.isEmpty()) return emptyList(); List<String> parts = new ArrayList<String>() { @Override public boolean add(String s) { if (s == null || s.isEmpty()) return false; return super.add(s); } }; StrUtils.splitSmart(path, '/', parts); return parts; }
public static boolean setObjectByPath(Object root, String hierarchy, Object value) { List<String> parts = StrUtils.splitSmart(hierarchy, '/'); if (parts.get(0).isEmpty()) parts.remove(0); return setObjectByPath(root, parts, value); }
public boolean seek(String seekPath) { if (path == null) return true; if (seekPath.startsWith("/")) { seekPath = seekPath.substring(1); } if (seekPath.endsWith("/")) { seekPath = seekPath.substring(0,seekPath.length()-1); } List<String> pathList = StrUtils.splitSmart(seekPath, "/", false); return seek(pathList); }
public static Object getObjectByPath(Map root, boolean onlyPrimitive, String hierarchy) { return getObjectByPath(root, onlyPrimitive, StrUtils.splitSmart(hierarchy, '/')); }
public static Object getObjectByPath(Object root, boolean onlyPrimitive, String hierarchy) { if (hierarchy == null) return getObjectByPath(root, onlyPrimitive, singletonList(null)); List<String> parts = StrUtils.splitSmart(hierarchy, '/'); if (parts.get(0).isEmpty()) parts.remove(0); return getObjectByPath(root, onlyPrimitive, parts); }
/** This method is consulted to determine what slices should be queried for a request when * an explicit shards parameter was not used. * This method accepts a multi-valued shardKeys parameter (normally comma separated from the shard.keys request parameter) * and aggregates the slices returned by getSearchSlicesSingle for each shardKey. **/ public Collection<Slice> getSearchSlices(String shardKeys, SolrParams params, DocCollection collection) { if (shardKeys == null || shardKeys.indexOf(',') < 0) { return getSearchSlicesSingle(shardKeys, params, collection); } List<String> shardKeyList = StrUtils.splitSmart(shardKeys, ",", true); HashSet<Slice> allSlices = new HashSet<>(); for (String shardKey : shardKeyList) { allSlices.addAll( getSearchSlicesSingle(shardKey, params, collection) ); } return allSlices; }
private static List<List<String>> getSynList(String str, String separator, TokenizerFactory tokFactory) { List<String> strList = StrUtils.splitSmart(str, separator, false); // now split on whitespace to get a list of token strings List<List<String>> synList = new ArrayList<List<String>>(); for (String toks : strList) { List<String> tokList = tokFactory == null ? StrUtils.splitWS(toks, true) : splitByTokenizer(toks, tokFactory); synList.add(tokList); } return synList; }
/** This method is consulted to determine what slices should be queried for a request when * an explicit shards parameter was not used. * This method accepts a multi-valued shardKeys parameter (normally comma separated from the shard.keys request parameter) * and aggregates the slices returned by getSearchSlicesSingle for each shardKey. **/ public Collection<Slice> getSearchSlices(String shardKeys, SolrParams params, DocCollection collection) { if (shardKeys == null || shardKeys.indexOf(',') < 0) { return getSearchSlicesSingle(shardKeys, params, collection); } List<String> shardKeyList = StrUtils.splitSmart(shardKeys, ",", true); HashSet<Slice> allSlices = new HashSet<>(); for (String shardKey : shardKeyList) { allSlices.addAll( getSearchSlicesSingle(shardKey, params, collection) ); } return allSlices; }
@Override public NamedList<Object> request(SolrRequest request, String collection) throws SolrServerException, IOException { // the collection parameter of the request overrides that of the parameter to this method String requestCollection = request.getCollection(); if (requestCollection != null) { collection = requestCollection; } else if (collection == null) { collection = defaultCollection; } List<String> inputCollections = collection == null ? Collections.emptyList() : StrUtils.splitSmart(collection, ",", true); return requestWithRetryOnStaleState(request, 0, inputCollections); }
private String checkForAlias(SolrZkClient zkClient, String collection) throws KeeperException, InterruptedException { byte[] aliasData = zkClient.getData(ZkStateReader.ALIASES, null, null, true); Aliases aliases = ClusterState.load(aliasData); String alias = aliases.getCollectionAlias(collection); if (alias != null) { List<String> aliasList = StrUtils.splitSmart(alias, ",", true); if (aliasList.size() > 1) { throw new IllegalArgumentException("collection cannot be an alias that maps to multiple collections"); } collection = aliasList.get(0); } return collection; }
private String checkForAlias(SolrZkClient zkClient, String collection) throws KeeperException, InterruptedException { byte[] aliasData = zkClient.getData(ZkStateReader.ALIASES, null, null, true); Aliases aliases = ClusterState.load(aliasData); String alias = aliases.getCollectionAlias(collection); if (alias != null) { List<String> aliasList = StrUtils.splitSmart(alias, ",", true); if (aliasList.size() > 1) { throw new IllegalArgumentException("collection cannot be an alias that maps to multiple collections"); } collection = aliasList.get(0); } return collection; }
/** * Executes a basic query in lucene syntax */ public static DocList doSimpleQuery(String sreq, SolrIndexSearcher searcher, IndexSchema schema, int start, int limit) throws IOException { List<String> commands = StrUtils.splitSmart(sreq,';'); String qs = commands.size() >= 1 ? commands.get(0) : ""; Query query = QueryParsing.parseQuery(qs, schema); // 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), schema); } DocList results = searcher.getDocList(query,(DocSet)null, sort, start, limit); return results; }
public ArrayList<String> getShardURLs (boolean includeSelf) { // String[] urls = new String[shards.length + (includeSelf ? 0 : -1)]; ArrayList<String> urls = new ArrayList<String> (); String shardId = core.getCoreDescriptor().getCloudDescriptor().getShardId(); for (int i = 0; i < shards.length; i++) { if (!includeSelf) { if (shardId.equals(slices[i])) { // exclude this shard continue; } } List<String> replicas = StrUtils.splitSmart(shards[i], "|", true); for (String replica : replicas) { urls .add("http://" + replica); } } return urls; }
void doQuery(String expectedDocs, String... queryParams) throws Exception { Set<String> expectedIds = new HashSet<>( StrUtils.splitSmart(expectedDocs, ",", true) ); QueryResponse rsp = cloudClient.query(params(queryParams)); Set<String> obtainedIds = new HashSet<>(); for (SolrDocument doc : rsp.getResults()) { obtainedIds.add((String) doc.get("id")); } assertEquals(expectedIds, obtainedIds); }
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; }
@Override public void prepare(ResponseBuilder rb) throws IOException { sentryInstance.authorizeCollectionAction( rb.req, EnumSet.of(SearchModelAction.QUERY), OPERATION_NAME); String collections = rb.req.getParams().get("collection"); if (collections != null) { List<String> collectionList = StrUtils.splitSmart(collections, ",", true); // this may be an alias request: check each collection listed in "collections". // NOTE1: this may involve checking a collection twice, because the collection // on which this component is running may also be in the collections list, // but this simplifies the logic. We don't want to only check the collections in the // list, because the user can spoof this by adding collections to non-alias requests. // NOTE2: we only need to do this for queries, not for updates, because updates are only // written to the first alias in the collection list, so are guaranteed to undergo the // correct sentry check for (String coll : collectionList) { sentryInstance.authorizeCollectionAction(rb.req, EnumSet.of(SearchModelAction.QUERY), OPERATION_NAME, coll, true); } } }
private NamedList getListedTermCounts(String field, String termList) throws IOException { FieldType ft = searcher.getSchema().getFieldType(field); List<String> terms = StrUtils.splitSmart(termList, ",", true); NamedList res = new NamedList(); Term t = new Term(field); for (String term : terms) { String internal = ft.toInternal(term); int count = searcher.numDocs(new TermQuery(t.createTerm(internal)), base); res.add(term, count); } return res; }
@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"); signatureTerm = new Term(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); } } }