Java Code Examples for org.apache.solr.common.params.SolrParams#getParameterNamesIterator()
The following examples show how to use
org.apache.solr.common.params.SolrParams#getParameterNamesIterator() .
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: StreamHandler.java From lucene-solr with Apache License 2.0 | 6 votes |
private Map<String, List<String>> getCollectionShards(SolrParams params) { Map<String, List<String>> collectionShards = new HashMap<>(); Iterator<String> paramsIt = params.getParameterNamesIterator(); while (paramsIt.hasNext()) { String param = paramsIt.next(); if (param.indexOf(".shards") > -1) { String collection = param.split("\\.")[0]; String shardString = params.get(param); String[] shards = shardString.split(","); @SuppressWarnings({"rawtypes"}) List<String> shardList = new ArrayList<>(); for (String shard : shards) { shardList.add(shard); } collectionShards.put(collection, shardList); } } if (collectionShards.size() > 0) { return collectionShards; } else { return null; } }
Example 2
Source File: RewriteFacetParametersComponent.java From SearchServices with GNU Lesser General Public License v3.0 | 6 votes |
/** * Update any existing facet parameters to use the Solr field names. * * @param fixed The updated params object. * @param params The original params object. * @param paramName The name of the parameter to rewrite (e.g. "facet.limit" or "f.fieldName.facet.limit"). * @param fieldMappings A list of mappings from Alfresco property names to Solr field names. */ private void rewriteFacetFieldOptions(ModifiableSolrParams fixed, SolrParams params, String paramName, Map<String, String> fieldMappings) { for(Iterator<String> originalParamsIterator = params.getParameterNamesIterator(); originalParamsIterator.hasNext(); /**/) { String originalSolrParam = originalParamsIterator.next(); //it contains the alfresco field name if(originalSolrParam.startsWith("f.")) { if(originalSolrParam.endsWith("."+paramName)) { String originalAlfrescoFieldName = originalSolrParam.substring(2, originalSolrParam.length() - paramName.length() - 1); if(fieldMappings.containsKey(originalAlfrescoFieldName)) { String solrFieldName = fieldMappings.get(originalAlfrescoFieldName); fixed.set("f."+ solrFieldName +"."+paramName, params.getParams(originalSolrParam)); } else { fixed.set(originalSolrParam, params.getParams(originalSolrParam)); } } } } }
Example 3
Source File: XJoinSearchComponent.java From BioSolr with Apache License 2.0 | 6 votes |
/** * Generate external process results (if they have not already been generated). */ @Override public void prepare(ResponseBuilder rb) throws IOException { SolrParams params = rb.req.getParams(); if (! params.getBool(getName(), false)) { return; } XJoinResults<?> results = (XJoinResults<?>)rb.req.getContext().get(getResultsTag()); if (results != null) { return; } // generate external process results, by passing 'external' prefixed parameters // from the query string to our factory String prefix = getName() + "." + XJoinParameters.EXTERNAL_PREFIX + "."; ModifiableSolrParams externalParams = new ModifiableSolrParams(); for (Iterator<String> it = params.getParameterNamesIterator(); it.hasNext(); ) { String name = it.next(); if (name.startsWith(prefix)) { externalParams.set(name.substring(prefix.length()), params.get(name)); } } results = factory.getResults(externalParams); rb.req.getContext().put(getResultsTag(), results); }
Example 4
Source File: Connection.java From BioSolr with Apache License 2.0 | 6 votes |
public Connection(String rootUrl, String accept, SolrParams params) throws IOException { StringBuilder sb = new StringBuilder("?"); for (Iterator<String> it = params.getParameterNamesIterator(); it.hasNext(); ) { String name = it.next(); for (String value : params.getParams(name)) { sb.append(name); sb.append("="); sb.append(value); sb.append("&"); } } url = rootUrl; if (sb.length() > 1) { url += sb.substring(0, sb.length() - 1); } cnx = new URL(url).openConnection(); cnx.setRequestProperty("Accept", accept); in = null; }
Example 5
Source File: XJoinSearchComponent.java From BioSolr with Apache License 2.0 | 6 votes |
/** * Generate external process results (if they have not already been generated). */ @Override public void prepare(ResponseBuilder rb) throws IOException { SolrParams params = rb.req.getParams(); if (! params.getBool(getName(), false)) { return; } XJoinResults<?> results = (XJoinResults<?>)rb.req.getContext().get(getResultsTag()); if (results != null) { return; } // generate external process results, by passing 'external' prefixed parameters // from the query string to our factory String prefix = getName() + "." + XJoinParameters.EXTERNAL_PREFIX + "."; ModifiableSolrParams externalParams = new ModifiableSolrParams(); for (Iterator<String> it = params.getParameterNamesIterator(); it.hasNext(); ) { String name = it.next(); if (name.startsWith(prefix)) { externalParams.set(name.substring(prefix.length()), params.get(name)); } } results = factory.getResults(externalParams); rb.req.getContext().put(getResultsTag(), results); }
Example 6
Source File: MtasSolrResultUtil.java From mtas with Apache License 2.0 | 6 votes |
/** * Gets the ids from parameters. * * @param params the params * @param prefix the prefix * @return the ids from parameters */ public static SortedSet<String> getIdsFromParameters(SolrParams params, String prefix) { SortedSet<String> ids = new TreeSet<>(); Iterator<String> it = params.getParameterNamesIterator(); Pattern pattern = Pattern .compile("^" + Pattern.quote(prefix) + "\\.([^\\.]+)(\\..*|$)"); while (it.hasNext()) { String item = it.next(); Matcher m = pattern.matcher(item); if (m.matches()) { ids.add(m.group(1)); } } return ids; }
Example 7
Source File: ParamUtil.java From solr-redis with Apache License 2.0 | 6 votes |
static String[] getStringByPrefix(final SolrParams params, final CharSequence prefix) { final Iterator<String> it = params.getParameterNamesIterator(); final ArrayList<String> keyList = new ArrayList<>(); while (it != null && it.hasNext()) { final String paramKey = it.next(); if (paramKey.length() < prefix.length() || !paramKey.substring(0, prefix.length()).equals(prefix)) { continue; } final String newKey = tryGetStringByName(params, paramKey, ""); if (!"".equals(newKey)) { keyList.add(newKey); } } return keyList.toArray(new String[keyList.size()]); }
Example 8
Source File: CollectionsHandler.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * Places all prefixed properties in the sink map (or a new map) using the prefix as the key and a map of * all prefixed properties as the value. The sub-map keys have the prefix removed. * * @param params The solr params from which to extract prefixed properties. * @param sink The map to add the properties too. * @param prefix The prefix to identify properties to be extracted * @return The sink map, or a new map if the sink map was null */ private static Map<String, Object> convertPrefixToMap(SolrParams params, Map<String, Object> sink, String prefix) { Map<String, Object> result = new LinkedHashMap<>(); Iterator<String> iter = params.getParameterNamesIterator(); while (iter.hasNext()) { String param = iter.next(); if (param.startsWith(prefix)) { result.put(param.substring(prefix.length() + 1), params.get(param)); } } if (sink == null) { sink = new LinkedHashMap<>(); } sink.put(prefix, result); return sink; }
Example 9
Source File: SubQueryAugmenterFactory.java From lucene-solr with Apache License 2.0 | 5 votes |
private SolrParams retainAndShiftPrefix(SolrParams params, String subPrefix) { ModifiableSolrParams out = new ModifiableSolrParams(); Iterator<String> baseKeyIt = params.getParameterNamesIterator(); while (baseKeyIt.hasNext()) { String key = baseKeyIt.next(); if (key.startsWith(subPrefix)) { out.set(key.substring(subPrefix.length()), params.getParams(key)); } } return out; }
Example 10
Source File: SystemLogListener.java From lucene-solr with Apache License 2.0 | 5 votes |
@SuppressWarnings({"rawtypes"}) private void addOperations(SolrInputDocument doc, List<SolrRequest> operations) { if (operations == null || operations.isEmpty()) { return; } Set<String> collections = new HashSet<>(); for (SolrRequest req : operations) { SolrParams params = req.getParams(); if (params == null) { continue; } if (params.get(CollectionAdminParams.COLLECTION) != null) { collections.add(params.get(CollectionAdminParams.COLLECTION)); } // build a whitespace-separated param string StringJoiner paramJoiner = new StringJoiner(" "); paramJoiner.setEmptyValue(""); for (Iterator<String> it = params.getParameterNamesIterator(); it.hasNext(); ) { final String name = it.next(); final String [] values = params.getParams(name); for (String value : values) { paramJoiner.add(name + "=" + value); } } String paramString = paramJoiner.toString(); if (!paramString.isEmpty()) { doc.addField("operations.params_ts", paramString); } } if (!collections.isEmpty()) { doc.addField(COLLECTIONS_FIELD, collections); } }
Example 11
Source File: FacetComponent.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public void prepare(ResponseBuilder rb) throws IOException { if (rb.req.getParams().getBool(FacetParams.FACET, false)) { rb.setNeedDocSet(true); rb.doFacets = true; // Deduplicate facet params ModifiableSolrParams params = new ModifiableSolrParams(); SolrParams origParams = rb.req.getParams(); Iterator<String> iter = origParams.getParameterNamesIterator(); while (iter.hasNext()) { String paramName = iter.next(); // Deduplicate the list with LinkedHashSet, but _only_ for facet params. if (!paramName.startsWith(FacetParams.FACET)) { params.add(paramName, origParams.getParams(paramName)); continue; } HashSet<String> deDupe = new LinkedHashSet<>(Arrays.asList(origParams.getParams(paramName))); params.add(paramName, deDupe.toArray(new String[deDupe.size()])); } rb.req.setParams(params); // Initialize context FacetContext.initContext(rb); } }
Example 12
Source File: RequestHandlerUtils.java From lucene-solr with Apache License 2.0 | 5 votes |
public static void validateCommitParams(SolrParams params) { Iterator<String> i = params.getParameterNamesIterator(); while (i.hasNext()) { String key = i.next(); if (!commitParams.contains(key)) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unknown commit parameter '" + key + "'"); } } }
Example 13
Source File: CoreAdminHandler.java From lucene-solr with Apache License 2.0 | 5 votes |
protected static Map<String, String> buildCoreParams(SolrParams params) { Map<String, String> coreParams = new HashMap<>(); // standard core create parameters for (Map.Entry<String, String> entry : paramToProp.entrySet()) { String value = params.get(entry.getKey(), null); if (StringUtils.isNotEmpty(value)) { coreParams.put(entry.getValue(), value); } } // extra properties Iterator<String> paramsIt = params.getParameterNamesIterator(); while (paramsIt.hasNext()) { String param = paramsIt.next(); if (param.startsWith(CoreAdminParams.PROPERTY_PREFIX)) { String propName = param.substring(CoreAdminParams.PROPERTY_PREFIX.length()); String propValue = params.get(param); coreParams.put(propName, propValue); } if (param.startsWith(ZkController.COLLECTION_PARAM_PREFIX)) { coreParams.put(param, params.get(param)); } } return coreParams; }
Example 14
Source File: CollectionsHandler.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Copy prefixed params into a map. There must only be one value for these parameters. * * @param params The source of params from which copies should be made * @param props The map into which param names and values should be copied as keys and values respectively * @param prefix The prefix to select. * @return the map supplied in the props parameter, modified to contain the prefixed params. */ private static Map<String, Object> copyPropertiesWithPrefix(SolrParams params, Map<String, Object> props, String prefix) { Iterator<String> iter = params.getParameterNamesIterator(); while (iter.hasNext()) { String param = iter.next(); if (param.startsWith(prefix)) { final String[] values = params.getParams(param); if (values.length != 1) { throw new SolrException(BAD_REQUEST, "Only one value can be present for parameter " + param); } props.put(param, values[0]); } } return props; }
Example 15
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 16
Source File: OldAnalyticsRequestConverter.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Convert the old olap-style Analytics Request in the given params to * an analytics request string using the current format. * * @param params to find the analytics request in * @return an analytics request string */ public static AnalyticsRequest convert(SolrParams params) { AnalyticsRequest request = new AnalyticsRequest(); request.expressions = new HashMap<>(); request.groupings = new HashMap<>(); Iterator<String> paramsIterator = params.getParameterNamesIterator(); while (paramsIterator.hasNext()) { String param = paramsIterator.next(); CharSequence paramSequence = param.subSequence(0, param.length()); parseParam(request, param, paramSequence, params); } return request; }
Example 17
Source File: CarrotClusteringEngine.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Extracts parameters that can possibly match some attributes of Carrot2 algorithms. */ private void extractCarrotAttributes(SolrParams solrParams, Map<String, Object> attributes) { // Extract all non-predefined parameters. This way, we'll be able to set all // parameters of Carrot2 algorithms without defining their names as constants. for (Iterator<String> paramNames = solrParams.getParameterNamesIterator(); paramNames .hasNext();) { String paramName = paramNames.next(); if (!CarrotParams.CARROT_PARAM_NAMES.contains(paramName)) { attributes.put(paramName, solrParams.get(paramName)); } } }
Example 18
Source File: CollectionAdminRequestRequiredParamsTest.java From lucene-solr with Apache License 2.0 | 5 votes |
private void assertContainsParams(SolrParams solrParams, String... requiredParams) { final Set<String> requiredParamsSet = Sets.newHashSet(requiredParams); final Set<String> solrParamsSet = Sets.newHashSet(); for (Iterator<String> iter = solrParams.getParameterNamesIterator(); iter.hasNext();) { solrParamsSet.add(iter.next()); } assertTrue("required params missing: required=" + requiredParamsSet + ", params=" + solrParamsSet, solrParamsSet.containsAll(requiredParamsSet)); assertTrue("extra parameters included in request: required=" + requiredParamsSet + ", params=" + solrParams, Sets.difference(solrParamsSet, requiredParamsSet).isEmpty()); }
Example 19
Source File: MtasCQLQParser.java From mtas with Apache License 2.0 | 4 votes |
/** * Instantiates a new mtas CQLQ parser. * * @param qstr the qstr * @param localParams the local params * @param params the params * @param req the req */ public MtasCQLQParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) { super(qstr, localParams, params, req); if ((localParams.getParams(MTAS_CQL_QPARSER_FIELD) != null) && (localParams.getParams(MTAS_CQL_QPARSER_FIELD).length == 1)) { field = localParams.getParams(MTAS_CQL_QPARSER_FIELD)[0]; } if ((localParams.getParams(MTAS_CQL_QPARSER_QUERY) != null) && (localParams.getParams(MTAS_CQL_QPARSER_QUERY).length == 1)) { cql = localParams.getParams(MTAS_CQL_QPARSER_QUERY)[0]; } if ((localParams.getParams(MTAS_CQL_QPARSER_IGNORE) != null) && (localParams.getParams(MTAS_CQL_QPARSER_IGNORE).length == 1)) { ignoreQuery = localParams.getParams(MTAS_CQL_QPARSER_IGNORE)[0]; } if ((localParams.getParams(MTAS_CQL_QPARSER_MAXIMUM_IGNORE_LENGTH) != null) && (localParams .getParams(MTAS_CQL_QPARSER_MAXIMUM_IGNORE_LENGTH).length == 1)) { try { maximumIgnoreLength = Integer.parseInt( localParams.getParams(MTAS_CQL_QPARSER_MAXIMUM_IGNORE_LENGTH)[0]); } catch (NumberFormatException e) { maximumIgnoreLength = null; } } if ((localParams.getParams(MTAS_CQL_QPARSER_PREFIX) != null) && (localParams.getParams(MTAS_CQL_QPARSER_PREFIX).length == 1)) { defaultPrefix = localParams.getParams(MTAS_CQL_QPARSER_PREFIX)[0]; } variables = new HashMap<>(); Iterator<String> it = localParams.getParameterNamesIterator(); while (it.hasNext()) { String item = it.next(); if (item.startsWith("variable_")) { if (localParams.getParams(item).length == 0 || (localParams.getParams(item).length == 1 && localParams.getParams(item)[0].isEmpty())) { variables.put(item.substring(9), new String[0]); } else { ArrayList<String> list = new ArrayList<>(); for (int i = 0; i < localParams.getParams(item).length; i++) { String[] subList = localParams.getParams(item)[i] .split("(?<!\\\\),"); for (int j = 0; j < subList.length; j++) { list.add(subList[j].replace("\\,", ",").replace("\\\\", "\\")); } } variables.put(item.substring(9), list.toArray(new String[list.size()])); } } } }
Example 20
Source File: RewriteFacetParametersComponent.java From SearchServices with GNU Lesser General Public License v3.0 | 4 votes |
private void fixFilterQueries(ModifiableSolrParams fixed, SolrParams params, ResponseBuilder rb) { for(Iterator<String> it = params.getParameterNamesIterator(); it.hasNext(); /**/) { String name = it.next(); if(name.equals("fq")) { String[] values = params.getParams(name); if(values != null) { String[] fixedValues = new String[values.length]; for(int i = 0; i < values.length; i++) { String value = values[i]; if(value.startsWith("{!")) { fixedValues[i] = value; } else { if(value.startsWith("contentSize():")) { value = "cm:content.size:" + removeQuotes(value.substring("contentSize():".length())); } else if(value.startsWith("mimetype():")) { value = removeQuotes(value.substring("mimetype():".length())); ArrayList<String> expand = MimetypeGroupingQParserPlugin.getReverseMappings().get(value); if(expand == null) { value = "cm:content.mimetype:\""+value+"\""; } else { StringBuilder builder = new StringBuilder(); builder.append("cm:content.mimetype:("); for(int j = 0; j < expand.size(); j++) { if(j > 0) { builder.append(" OR "); } builder.append('"'); builder.append(expand.get(j)); builder.append('"'); } builder.append(')'); value = builder.toString(); } } fixedValues[i] = "{!afts}"+value; } } fixed.add(name, fixedValues); } } } }