Java Code Examples for org.apache.solr.common.util.StrUtils#splitSmart()
The following examples show how to use
org.apache.solr.common.util.StrUtils#splitSmart() .
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: TestDistribDocBasedVersion.java From lucene-solr with Apache License 2.0 | 6 votes |
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))); } solrClient.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); }
Example 2
Source File: SolrPluginUtils.java From lucene-solr with Apache License 2.0 | 6 votes |
private static SolrParams applyParamSet(RequestParams requestParams, SolrParams defaults, String paramSets, String type) { if (paramSets == null) return defaults; List<String> paramSetList = paramSets.indexOf(',') == -1 ? singletonList(paramSets) : StrUtils.splitSmart(paramSets, ','); for (String name : paramSetList) { RequestParams.VersionedParams params = requestParams.getParams(name, type); if (params == null) return defaults; if (type.equals(DEFAULTS)) { defaults = SolrParams.wrapDefaults(params, defaults); } else if (type.equals(INVARIANTS)) { defaults = SolrParams.wrapAppended(params, defaults); } else { defaults = SolrParams.wrapAppended(params, defaults); } } return defaults; }
Example 3
Source File: SolrPluginUtils.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * 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, 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 = SortSpecParsing.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); } }
Example 4
Source File: QueryIndexAuthorizationComponent.java From incubator-sentry with Apache License 2.0 | 6 votes |
@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); } } }
Example 5
Source File: PackageStoreAPI.java From lucene-solr with Apache License 2.0 | 6 votes |
public static void validateName(String path, boolean failForTrusted) { if (path == null) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "empty path"); } List<String> parts = StrUtils.splitSmart(path, '/', true); for (String part : parts) { if (part.charAt(0) == '.') { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "cannot start with period"); } for (int i = 0; i < part.length(); i++) { for (int j = 0; j < INVALIDCHARS.length(); j++) { if (part.charAt(i) == INVALIDCHARS.charAt(j)) throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unsupported char in file name: " + part); } } } if (failForTrusted && TRUSTED_DIR.equals(parts.get(0))) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "trying to write into /_trusted_/ directory"); } }
Example 6
Source File: ConfigOverlay.java From lucene-solr with Apache License 2.0 | 6 votes |
@SuppressWarnings({"rawtypes"}) public static Class checkEditable(String path, boolean isXpath, List<String> hierarchy) { List<String> parts = StrUtils.splitSmart(path, isXpath ? '/' : '.'); Object obj = editable_prop_map; for (int i = 0; i < parts.size(); i++) { String part = parts.get(i); boolean isAttr = isXpath && part.startsWith("@"); if (isAttr) { part = part.substring(1); } if (hierarchy != null) hierarchy.add(part); if (obj == null) return null; if (i == parts.size() - 1) { if (obj instanceof Map) { Map map = (Map) obj; Object o = map.get(part); return checkType(o, isXpath, isAttr); } return null; } obj = ((Map) obj).get(part); } return null; }
Example 7
Source File: CollectionPerTimeFrameAssignmentStrategy.java From storm-solr with Apache License 2.0 | 5 votes |
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); }
Example 8
Source File: StandaloneReplicaSource.java From lucene-solr with Apache License 2.0 | 5 votes |
@SuppressWarnings({"unchecked", "rawtypes"}) public StandaloneReplicaSource(Builder builder) { List<String> list = StrUtils.splitSmart(builder.shardsParam, ",", true); replicas = new List[list.size()]; for (int i = 0; i < list.size(); i++) { replicas[i] = StrUtils.splitSmart(list.get(i), "|", true); // todo do we really not need to transform in non-cloud mode?! // builder.replicaListTransformer.transform(replicas[i]); builder.hostChecker.checkWhitelist(builder.shardsParam, replicas[i]); } }
Example 9
Source File: AtomicUpdateDocumentMerger.java From lucene-solr with Apache License 2.0 | 5 votes |
private static Pair<String, Integer> getPathAndIndexFromNestPath(String nestPath) { List<String> splitPath = StrUtils.splitSmart(nestPath, '#'); if(splitPath.size() == 1) { return Pair.of(splitPath.get(0), 0); } return Pair.of(splitPath.get(0), Integer.parseInt(splitPath.get(1))); }
Example 10
Source File: DistributedQueryComponentOptimizationTest.java From lucene-solr with Apache License 2.0 | 5 votes |
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<>(); if (params != null) { for (String p : params) { List<String> list = StrUtils.splitSmart(p, ','); for (String s : list) { // make sure field names aren't duplicated in the parameters assertTrue("Field name " + s + " was requested multiple times: params = " + requestAndParams.params, requestedFields.add(s)); } } } // if a wildcard ALL field is requested then we don't need to match exact number of params if (!requestedFields.contains("*")) { 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); } } } }
Example 11
Source File: DocRouter.java From lucene-solr with Apache License 2.0 | 5 votes |
/** 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; }
Example 12
Source File: PreferenceRule.java From lucene-solr with Apache License 2.0 | 5 votes |
public static List<PreferenceRule> from(String rules) { List<String> prefs = StrUtils.splitSmart(rules, ','); ArrayList<PreferenceRule> preferenceRules = new ArrayList<>(prefs.size()); prefs.forEach(rule -> { String[] parts = rule.split(":", 2); if (parts.length != 2) { throw new IllegalArgumentException("Invalid " + ShardParams.SHARDS_PREFERENCE + " rule: " + rule); } preferenceRules.add(new PreferenceRule(parts[0], parts[1])); }); return preferenceRules; }
Example 13
Source File: LegacyFacet.java From lucene-solr with Apache License 2.0 | 5 votes |
protected static Map<String, List<Subfacet>> parseSubFacets(SolrParams params) { Map<String,List<Subfacet>> map = new HashMap<>(); Iterator<String> iter = params.getParameterNamesIterator(); String SUBFACET="subfacet."; while (iter.hasNext()) { String key = iter.next(); if (key.startsWith(SUBFACET)) { List<String> parts = StrUtils.splitSmart(key, '.'); if (parts.size() != 3) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "expected subfacet parameter name of the form subfacet.mykey.field, got:" + key); } Subfacet sub = new Subfacet(); sub.parentKey = parts.get(1); sub.type = parts.get(2); sub.value = params.get(key); List<Subfacet> subs = map.get(sub.parentKey); if (subs == null) { subs = new ArrayList<>(1); } subs.add(sub); map.put(sub.parentKey, subs); } } return map; }
Example 14
Source File: CloudReplicaSource.java From lucene-solr with Apache License 2.0 | 5 votes |
@SuppressWarnings({"unchecked", "rawtypes"}) private void withClusterState(Builder builder, SolrParams params) { ClusterState clusterState = builder.zkStateReader.getClusterState(); String shardKeys = params.get(ShardParams._ROUTE_); // This will be the complete list of slices we need to query for this request. Map<String, Slice> sliceMap = new HashMap<>(); // we need to find out what collections this request is for. // A comma-separated list of specified collections. // Eg: "collection1,collection2,collection3" String collections = params.get("collection"); if (collections != null) { // If there were one or more collections specified in the query, split // each parameter and store as a separate member of a List. List<String> collectionList = StrUtils.splitSmart(collections, ",", true); // In turn, retrieve the slices that cover each collection from the // cloud state and add them to the Map 'slices'. for (String collectionName : collectionList) { // The original code produced <collection-name>_<shard-name> when the collections // parameter was specified (see ClientUtils.appendMap) // Is this necessary if ony one collection is specified? // i.e. should we change multiCollection to collectionList.size() > 1? addSlices(sliceMap, clusterState, params, collectionName, shardKeys, true); } } else { // just this collection addSlices(sliceMap, clusterState, params, builder.collection, shardKeys, false); } this.slices = sliceMap.keySet().toArray(new String[sliceMap.size()]); this.replicas = new List[slices.length]; for (int i = 0; i < slices.length; i++) { String sliceName = slices[i]; replicas[i] = findReplicas(builder, null, clusterState, sliceMap.get(sliceName)); } }
Example 15
Source File: FacetComponent.java From lucene-solr with Apache License 2.0 | 5 votes |
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,','); } } }
Example 16
Source File: Assign.java From lucene-solr with Apache License 2.0 | 4 votes |
@SuppressWarnings({"unchecked"}) public static List<ReplicaPosition> getNodesForNewReplicas(ClusterState clusterState, String collectionName, String shard, int nrtReplicas, int tlogReplicas, int pullReplicas, Object createNodeSet, SolrCloudManager cloudManager) throws IOException, InterruptedException, AssignmentException { log.debug("getNodesForNewReplicas() shard: {} , nrtReplicas : {} , tlogReplicas: {} , pullReplicas: {} , createNodeSet {}" , shard, nrtReplicas, tlogReplicas, pullReplicas, createNodeSet); DocCollection coll = clusterState.getCollection(collectionName); int maxShardsPerNode = coll.getMaxShardsPerNode() == -1 ? Integer.MAX_VALUE : coll.getMaxShardsPerNode(); List<String> createNodeList; if (createNodeSet instanceof List) { createNodeList = (List<String>) createNodeSet; } else { // deduplicate createNodeList = createNodeSet == null ? null : new ArrayList<>(new LinkedHashSet<>(StrUtils.splitSmart((String) createNodeSet, ",", true))); } // produces clear message when down nodes are the root cause, without this the user just // gets a log message of detail about the nodes that are up, and a message that policies could not // be satisfied which then requires study to diagnose the issue. checkLiveNodes(createNodeList,clusterState); if (createNodeList == null) { // We only care if we haven't been told to put new replicas on specific nodes. HashMap<String, ReplicaCount> nodeNameVsShardCount = getNodeNameVsShardCount(collectionName, clusterState, null); long availableSlots = 0; for (Map.Entry<String, ReplicaCount> ent : nodeNameVsShardCount.entrySet()) { //ADDREPLICA can put more than maxShardsPerNode on an instance, so this test is necessary. if (maxShardsPerNode > ent.getValue().thisCollectionNodes) { availableSlots += (maxShardsPerNode - ent.getValue().thisCollectionNodes); } } if (availableSlots < nrtReplicas + tlogReplicas + pullReplicas) { throw new AssignmentException( String.format(Locale.ROOT, "Cannot create %d new replicas for collection %s given the current number of eligible live nodes %d and a maxShardsPerNode of %d", nrtReplicas, collectionName, nodeNameVsShardCount.size(), maxShardsPerNode)); } } AssignRequest assignRequest = new AssignRequestBuilder() .forCollection(collectionName) .forShard(Collections.singletonList(shard)) .assignNrtReplicas(nrtReplicas) .assignTlogReplicas(tlogReplicas) .assignPullReplicas(pullReplicas) .onNodes(createNodeList) .build(); AssignStrategyFactory assignStrategyFactory = new AssignStrategyFactory(cloudManager); AssignStrategy assignStrategy = assignStrategyFactory.create(clusterState, coll); return assignStrategy.assign(cloudManager, assignRequest); }
Example 17
Source File: JSONTestUtil.java From lucene-solr with Apache License 2.0 | 4 votes |
@SuppressWarnings({"unchecked", "rawtypes"}) boolean matchMap() { Map<String,Object> expectedMap = (Map<String,Object>)expected; Map<String,Object> v = asMap(); if (v == null) return false; boolean ordered = false; String skipList = (String)expectedMap.get("_SKIP_"); String matchList = (String)expectedMap.get("_MATCH_"); Object orderedStr = expectedMap.get("_ORDERED_"); Object unorderedStr = expectedMap.get("_UNORDERED_"); if (orderedStr != null) ordered = true; if (unorderedStr != null) ordered = false; Set<String> match = null; if (matchList != null) { match = new HashSet(StrUtils.splitSmart(matchList,",",false)); } Set<String> skips = null; if (skipList != null) { skips = new HashSet(StrUtils.splitSmart(skipList,",",false)); } Set<String> keys = match != null ? match : expectedMap.keySet(); Set<String> visited = new HashSet<>(); Iterator<Map.Entry<String,Object>> iter = ordered ? v.entrySet().iterator() : null; int numExpected=0; pushPath(null); for (String expectedKey : keys) { if (reserved.contains(expectedKey)) continue; numExpected++; setPath(expectedKey); if (!v.containsKey(expectedKey)) { popPath(); setErr("expected key '" + expectedKey + "'"); return false; } expected = expectedMap.get(expectedKey); if (ordered) { Map.Entry<String,Object> entry; String foundKey; for(;;) { if (!iter.hasNext()) { popPath(); setErr("expected key '" + expectedKey + "' in ordered map"); return false; } entry = iter.next(); foundKey = entry.getKey(); if (skips != null && skips.contains(foundKey))continue; if (match != null && !match.contains(foundKey)) continue; break; } if (!entry.getKey().equals(expectedKey)) { popPath(); setErr("expected key '" + expectedKey + "' instead of '"+entry.getKey()+"' in ordered map"); return false; } val = entry.getValue(); } else { if (skips != null && skips.contains(expectedKey)) continue; val = v.get(expectedKey); } if (!match()) return false; } popPath(); // now check if there were any extra keys in the value (as long as there wasn't a specific list to include) if (match == null) { int skipped = 0; if (skips != null) { for (String skipStr : skips) if (v.containsKey(skipStr)) skipped++; } if (numExpected != (v.size() - skipped)) { HashSet<String> set = new HashSet<>(v.keySet()); set.removeAll(expectedMap.keySet()); setErr("unexpected map keys " + set); return false; } } return true; }
Example 18
Source File: TestIndexingPerformance.java From lucene-solr with Apache License 2.0 | 4 votes |
public void testIndexingPerf() throws IOException { int iter=1000; String iterS = System.getProperty("iter"); if (iterS != null) iter=Integer.parseInt(iterS); boolean overwrite = Boolean.parseBoolean(System.getProperty("overwrite","false")); String doc = System.getProperty("doc"); if (doc != null) { StrUtils.splitSmart(doc,",",true); } SolrQueryRequest req = lrf.makeRequest(); UpdateHandler updateHandler = req.getCore().getUpdateHandler(); String field = "textgap"; String[] fields = {field,"simple" ,field,"test" ,field,"how now brown cow" ,field,"what's that?" ,field,"radical!" ,field,"what's all this about, anyway?" ,field,"just how fast is this text indexing?" }; /*** String[] fields = { "a_i","1" ,"b_i","2" ,"c_i","3" ,"d_i","4" ,"e_i","5" ,"f_i","6" ,"g_i","7" ,"h_i","8" ,"i_i","9" ,"j_i","0" ,"k_i","0" }; ***/ final RTimer timer = new RTimer(); AddUpdateCommand add = new AddUpdateCommand(req); add.overwrite = overwrite; for (int i=0; i<iter; i++) { add.clear(); add.solrDoc = new SolrInputDocument(); add.solrDoc.addField("id", Integer.toString(i)); for (int j=0; j<fields.length; j+=2) { String f = fields[j]; String val = fields[j+1]; add.solrDoc.addField(f, val); } updateHandler.addDoc(add); } if (log.isInfoEnabled()) { log.info("doc={}", Arrays.toString(fields)); } double elapsed = timer.getTime(); if (log.isInfoEnabled()) { log.info("iter={} time={} throughput={}", iter, elapsed, ((long) iter * 1000) / elapsed); } //discard all the changes updateHandler.rollback(new RollbackUpdateCommand(req)); req.close(); }
Example 19
Source File: CSVLoaderBase.java From lucene-solr with Apache License 2.0 | 4 votes |
/** create the FieldAdders that control how each field is indexed */ void prepareFields() { // Possible future optimization: for really rapid incremental indexing // from a POST, one could cache all of this setup info based on the params. // The link from FieldAdder to this would need to be severed for that to happen. adders = new CSVLoaderBase.FieldAdder[fieldnames.length]; String skipStr = params.get(SKIP); List<String> skipFields = skipStr==null ? null : StrUtils.splitSmart(skipStr,','); CSVLoaderBase.FieldAdder adder = new CSVLoaderBase.FieldAdder(); CSVLoaderBase.FieldAdder adderKeepEmpty = new CSVLoaderBase.FieldAdderEmpty(); for (int i=0; i<fieldnames.length; i++) { String fname = fieldnames[i]; // to skip a field, leave the entries in fields and addrs null if (fname.length()==0 || (skipFields!=null && skipFields.contains(fname))) continue; boolean keepEmpty = params.getFieldBool(fname,EMPTY,false); adders[i] = keepEmpty ? adderKeepEmpty : adder; // Order that operations are applied: split -> trim -> map -> add // so create in reverse order. // Creation of FieldAdders could be optimized and shared among fields String[] fmap = params.getFieldParams(fname,MAP); if (fmap!=null) { for (String mapRule : fmap) { String[] mapArgs = colonSplit.split(mapRule,-1); if (mapArgs.length!=2) throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "Map rules must be of the form 'from:to' ,got '"+mapRule+"'"); adders[i] = new CSVLoaderBase.FieldMapperSingle(mapArgs[0], mapArgs[1], adders[i]); } } if (params.getFieldBool(fname,TRIM,false)) { adders[i] = new CSVLoaderBase.FieldTrimmer(adders[i]); } if (params.getFieldBool(fname,SPLIT,false)) { String sepStr = params.getFieldParam(fname,SEPARATOR); char fsep = sepStr==null || sepStr.length()==0 ? ',' : sepStr.charAt(0); String encStr = params.getFieldParam(fname,ENCAPSULATOR); char fenc = encStr==null || encStr.length()==0 ? (char)-2 : encStr.charAt(0); String escStr = params.getFieldParam(fname,ESCAPE); char fesc = escStr==null || escStr.length()==0 ? CSVStrategy.ESCAPE_DISABLED : escStr.charAt(0); CSVStrategy fstrat = new CSVStrategy (fsep, fenc, CSVStrategy.COMMENTS_DISABLED, fesc, false, false, false, false, "\n"); adders[i] = new CSVLoaderBase.FieldSplitter(fstrat, adders[i]); } } // look for any literal fields - literal.foo=xyzzy Iterator<String> paramNames = params.getParameterNamesIterator(); while (paramNames.hasNext()) { String pname = paramNames.next(); if (!pname.startsWith(LITERALS_PREFIX)) continue; String name = pname.substring(LITERALS_PREFIX.length()); literals.put(name, params.get(pname)); } }
Example 20
Source File: SchemaHandler.java From lucene-solr with Apache License 2.0 | 4 votes |
private void handleGET(SolrQueryRequest req, SolrQueryResponse rsp) { try { String path = (String) req.getContext().get("path"); switch (path) { case "/schema": rsp.add(IndexSchema.SCHEMA, req.getSchema().getNamedPropertyValues()); break; case "/schema/version": rsp.add(IndexSchema.VERSION, req.getSchema().getVersion()); break; case "/schema/uniquekey": rsp.add(IndexSchema.UNIQUE_KEY, req.getSchema().getUniqueKeyField().getName()); break; case "/schema/similarity": rsp.add(IndexSchema.SIMILARITY, req.getSchema().getSimilarityFactory().getNamedPropertyValues()); break; case "/schema/name": { final String schemaName = req.getSchema().getSchemaName(); if (null == schemaName) { String message = "Schema has no name"; throw new SolrException(SolrException.ErrorCode.NOT_FOUND, message); } rsp.add(IndexSchema.NAME, schemaName); break; } case "/schema/zkversion": { int refreshIfBelowVersion = req.getParams().getInt("refreshIfBelowVersion"); int zkVersion = -1; IndexSchema schema = req.getSchema(); if (schema instanceof ManagedIndexSchema) { ManagedIndexSchema managed = (ManagedIndexSchema) schema; zkVersion = managed.getSchemaZkVersion(); if (refreshIfBelowVersion != -1 && zkVersion < refreshIfBelowVersion) { log.info("REFRESHING SCHEMA (refreshIfBelowVersion={}, currentVersion={}) before returning version!" , refreshIfBelowVersion, zkVersion); ZkSolrResourceLoader zkSolrResourceLoader = (ZkSolrResourceLoader) req.getCore().getResourceLoader(); ZkIndexSchemaReader zkIndexSchemaReader = zkSolrResourceLoader.getZkIndexSchemaReader(); managed = zkIndexSchemaReader.refreshSchemaFromZk(refreshIfBelowVersion); zkVersion = managed.getSchemaZkVersion(); } } rsp.add("zkversion", zkVersion); break; } default: { List<String> parts = StrUtils.splitSmart(path, '/', true); if (parts.size() > 1 && level2.containsKey(parts.get(1))) { String realName = parts.get(1); String fieldName = IndexSchema.nameMapping.get(realName); String pathParam = level2.get(realName); if (parts.size() > 2) { req.setParams(SolrParams.wrapDefaults(new MapSolrParams(singletonMap(pathParam, parts.get(2))), req.getParams())); } @SuppressWarnings({"rawtypes"}) Map propertyValues = req.getSchema().getNamedPropertyValues(realName, req.getParams()); Object o = propertyValues.get(fieldName); if(parts.size()> 2) { String name = parts.get(2); if (o instanceof List) { @SuppressWarnings({"rawtypes"}) List list = (List) o; for (Object obj : list) { if (obj instanceof SimpleOrderedMap) { @SuppressWarnings({"rawtypes"}) SimpleOrderedMap simpleOrderedMap = (SimpleOrderedMap) obj; if(name.equals(simpleOrderedMap.get("name"))) { rsp.add(fieldName.substring(0, realName.length() - 1), simpleOrderedMap); return; } } } } throw new SolrException(SolrException.ErrorCode.NOT_FOUND, "No such path " + path); } else { rsp.add(fieldName, o); } return; } throw new SolrException(SolrException.ErrorCode.NOT_FOUND, "No such path " + path); } } } catch (Exception e) { rsp.setException(e); } }