Java Code Examples for org.apache.solr.common.params.SolrParams#getParams()
The following examples show how to use
org.apache.solr.common.params.SolrParams#getParams() .
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: RewriteFacetParametersComponent.java From SearchServices with GNU Lesser General Public License v3.0 | 6 votes |
/** * @param params * @param field * @return */ private boolean isMimetypeAndHasFQ(SolrParams params, String field) { if(!field.equals("mimetype()")) { return false; } else { String[] filterQueries = params.getParams("fq"); if(filterQueries != null) { for(String fq : filterQueries) { if(fq.startsWith("mimetype():")) { return true; } } } } return false; }
Example 2
Source File: MtasJoinQParser.java From mtas with Apache License 2.0 | 6 votes |
/** * Instantiates a new mtas join Q parser. * * @param qstr the qstr * @param localParams the local params * @param params the params * @param req the req */ public MtasJoinQParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) { super(qstr, localParams, params, req); if ((localParams.getParams(MTAS_JOIN_QPARSER_COLLECTION) != null) && (localParams.getParams(MTAS_JOIN_QPARSER_COLLECTION).length == 1)) { id = localParams.getParams(MTAS_JOIN_QPARSER_COLLECTION)[0]; } if ((localParams.getParams(MTAS_JOIN_QPARSER_FIELD) != null) && (localParams.getParams(MTAS_JOIN_QPARSER_FIELD).length > 0)) { fields = new String[localParams .getParams(MTAS_JOIN_QPARSER_FIELD).length]; System.arraycopy(localParams.getParams(MTAS_JOIN_QPARSER_FIELD), 0, fields, 0, localParams.getParams(MTAS_JOIN_QPARSER_FIELD).length); } }
Example 3
Source File: AsyncBuildSuggestComponent.java From SearchServices with GNU Lesser General Public License v3.0 | 5 votes |
private Set<String> getSuggesterNames(SolrParams params) { Set<String> suggesterNames = new HashSet<>(); String[] suggesterNamesFromParams = params.getParams(SUGGEST_DICT); if (suggesterNamesFromParams == null) { suggesterNames.add(DEFAULT_DICT_NAME); } else { for (String name : suggesterNamesFromParams) { suggesterNames.add(name); } } return suggesterNames; }
Example 4
Source File: FacetComponent.java From lucene-solr with Apache License 2.0 | 5 votes |
void parse(SolrParams params, ResponseBuilder rb) { queryFacets = new LinkedHashMap<>(); facets = new LinkedHashMap<>(); String[] facetQs = params.getParams(FacetParams.FACET_QUERY); if (facetQs != null) { for (String query : facetQs) { QueryFacet queryFacet = new QueryFacet(rb, query); queryFacets.put(queryFacet.getKey(), queryFacet); } } String[] facetFs = params.getParams(FacetParams.FACET_FIELD); if (facetFs != null) { for (String field : facetFs) { final DistribFieldFacet ff; if (params.getFieldBool(field, FacetParams.FACET_EXISTS, false)) { // cap facet count by 1 with this method ff = new DistribFacetExistsField(rb, field); } else { ff = new DistribFieldFacet(rb, field); } facets.put(ff.getKey(), ff); } } // Develop Pivot Facet Information String[] facetPFs = params.getParams(FacetParams.FACET_PIVOT); if (facetPFs != null) { for (String fieldGroup : facetPFs) { PivotFacet pf = new PivotFacet(rb, fieldGroup); pivotFacets.add(pf.getKey(), pf); } } heatmapFacets = SpatialHeatmapFacets.distribParse(params, rb); }
Example 5
Source File: DelegationTokenHttpSolrClient.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override protected HttpRequestBase createMethod(@SuppressWarnings({"rawtypes"})final SolrRequest request, String collection) throws IOException, SolrServerException { SolrParams params = request.getParams(); if (params != null && params.getParams(DELEGATION_TOKEN_PARAM) != null) { throw new IllegalArgumentException(DELEGATION_TOKEN_PARAM + " parameter not supported"); } return super.createMethod(request, collection); }
Example 6
Source File: TermsComponent.java From lucene-solr with Apache License 2.0 | 5 votes |
int resolveRegexpFlags(SolrParams params) { String[] flagParams = params.getParams(TermsParams.TERMS_REGEXP_FLAG); if (flagParams == null) { return 0; } int flags = 0; for (String flagParam : flagParams) { try { flags |= TermsParams.TermsRegexpFlag.valueOf(flagParam.toUpperCase(Locale.ROOT)).getValue(); } catch (IllegalArgumentException iae) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unknown terms regex flag '" + flagParam + "'"); } } return flags; }
Example 7
Source File: SpatialHeatmapFacets.java From lucene-solr with Apache License 2.0 | 5 votes |
/** Parses request to "HeatmapFacet" instances. */ public static LinkedHashMap<String,HeatmapFacet> distribParse(SolrParams params, ResponseBuilder rb) { final LinkedHashMap<String, HeatmapFacet> heatmapFacets = new LinkedHashMap<>(); final String[] heatmapFields = params.getParams(FacetParams.FACET_HEATMAP); if (heatmapFields != null) { for (String heatmapField : heatmapFields) { HeatmapFacet facet = new HeatmapFacet(rb, heatmapField); heatmapFacets.put(facet.getKey(), facet); } } return heatmapFacets; }
Example 8
Source File: SolrClientInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
private static final String toQueryString(SolrParams params) { final StringBuilder sb = new StringBuilder(128); boolean first = true; for (final Iterator<String> it = params.getParameterNamesIterator(); it.hasNext(); ) { final String name = it.next(); for (String val : params.getParams(name)) { sb.append(first ? '?' : '&').append(name).append('=').append(val); first = false; } } return sb.toString(); }
Example 9
Source File: SuggestComponent.java From lucene-solr with Apache License 2.0 | 5 votes |
private Set<String> getSuggesterNames(SolrParams params) { Set<String> suggesterNames = new HashSet<>(); String[] suggesterNamesFromParams = params.getParams(SUGGEST_DICT); if (suggesterNamesFromParams == null) { suggesterNames.add(DEFAULT_DICT_NAME); } else { for (String name : suggesterNamesFromParams) { suggesterNames.add(name); } } return suggesterNames; }
Example 10
Source File: DistributedUpdateProcessor.java From lucene-solr with Apache License 2.0 | 5 votes |
private void passParam(SolrParams params, ModifiableSolrParams fparams, String param) { String[] values = params.getParams(param); if (values != null) { for (String value : values) { fparams.add(param, value); } } }
Example 11
Source File: MetricsHandler.java From lucene-solr with Apache License 2.0 | 5 votes |
private MetricFilter parseMustMatchFilter(SolrParams params) { String[] prefixes = params.getParams(PREFIX_PARAM); MetricFilter prefixFilter = null; if (prefixes != null && prefixes.length > 0) { Set<String> prefixSet = new HashSet<>(); for (String prefix : prefixes) { prefixSet.addAll(StrUtils.splitSmart(prefix, ',')); } prefixFilter = new SolrMetricManager.PrefixFilter(prefixSet); } String[] regexes = params.getParams(REGEX_PARAM); MetricFilter regexFilter = null; if (regexes != null && regexes.length > 0) { regexFilter = new SolrMetricManager.RegexFilter(regexes); } MetricFilter mustMatchFilter; if (prefixFilter == null && regexFilter == null) { mustMatchFilter = MetricFilter.ALL; } else { if (prefixFilter == null) { mustMatchFilter = regexFilter; } else if (regexFilter == null) { mustMatchFilter = prefixFilter; } else { mustMatchFilter = new SolrMetricManager.OrFilter(prefixFilter, regexFilter); } } return mustMatchFilter; }
Example 12
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 13
Source File: CollectionsHandler.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Copy all params to the given map or if the given map is null create a new one */ static Map<String, Object> copy(SolrParams source, Map<String, Object> sink, Collection<String> paramNames) { if (sink == null) sink = new LinkedHashMap<>(); for (String param : paramNames) { String[] v = source.getParams(param); if (v != null && v.length > 0) { if (v.length == 1) { sink.put(param, v[0]); } else { sink.put(param, v); } } } return sink; }
Example 14
Source File: ShowFileRequestHandler.java From lucene-solr with Apache License 2.0 | 5 votes |
public static Set<String> initHidden(SolrParams invariants) { Set<String> hiddenRet = new HashSet<>(); // Build a list of hidden files if (invariants != null) { String[] hidden = invariants.getParams(HIDDEN); if (hidden != null) { for (String s : hidden) { hiddenRet.add(s.toUpperCase(Locale.ROOT)); } } } return hiddenRet; }
Example 15
Source File: TermsComponent.java From lucene-solr with Apache License 2.0 | 5 votes |
public void init(SolrParams params) { this.params = params; String[] fields = params.getParams(TermsParams.TERMS_FIELD); if (fields != null) { for (String field : fields) { // TODO: not sure 128 is the best starting size // It use it because that is what is used for facets fieldmap.put(field, new HashMap<String, TermsResponse.Term>(128)); } } }
Example 16
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 17
Source File: QueryParsing.java From lucene-solr with Apache License 2.0 | 4 votes |
/** * @param txt Text to parse * @param start Index into text for start of parsing * @param target Object to inject with parsed settings * @param params Additional existing parameters * @param startString String that indicates the start of a localParams section * @param endChar Character that indicates the end of a localParams section */ public static int parseLocalParams(String txt, int start, ModifiableSolrParams target, SolrParams params, String startString, char endChar) throws SyntaxError { int off = start; if (!txt.startsWith(startString, off)) return start; StrParser p = new StrParser(txt, start, txt.length()); p.pos += startString.length(); // skip over "{!" for (; ;) { /* if (p.pos>=txt.length()) { throw new SyntaxError("Missing '}' parsing local params '" + txt + '"'); } */ char ch = p.peek(); if (ch == endChar) { return p.pos + 1; } String id = p.getId(); if (id.length() == 0) { throw new SyntaxError("Expected ending character '" + endChar + "' parsing local params '" + txt + '"'); } String[] val = new String[1]; ch = p.peek(); if (ch != '=') { // single word... treat {!func} as type=func for easy lookup val[0] = id; id = TYPE; } else { // saw equals, so read value p.pos++; ch = p.peek(); boolean deref = false; if (ch == '$') { p.pos++; ch = p.peek(); deref = true; // dereference whatever value is read by treating it as a variable name } if (ch == '\"' || ch == '\'') { val[0] = p.getQuotedString(); } else { // read unquoted literal ended by whitespace or endChar (normally '}') // there is no escaping. int valStart = p.pos; for (; ;) { if (p.pos >= p.end) { throw new SyntaxError("Missing end to unquoted value starting at " + valStart + " str='" + txt + "'"); } char c = p.val.charAt(p.pos); if (c == endChar || Character.isWhitespace(c)) { val[0] = p.val.substring(valStart, p.pos); break; } p.pos++; } } if (deref) { // dereference parameter if (params != null) { val = params.getParams(val[0]); } } } if (target != null) target.add(id, val); } }
Example 18
Source File: DeepRandomStream.java From lucene-solr with Apache License 2.0 | 4 votes |
void init(String collectionName, String zkHost, SolrParams params) throws IOException { this.zkHost = zkHost; this.collection = collectionName; this.params = new ModifiableSolrParams(params); if (params.get("q") == null) { throw new IOException("q param expected for search function"); } if (params.getParams("fl") == null) { throw new IOException("fl param expected for search function"); } }
Example 19
Source File: RewriteFacetParametersComponent.java From SearchServices with GNU Lesser General Public License v3.0 | 4 votes |
/** * Update the facet fields to use Solr field names rather than ACS property names. * * @param fixed The updated params object. * @param params The original params object. * @param paramName The name of the mincount parameter to rewrite (e.g. "facet.mincount" or "facet.pivot.mincount"). * @param fieldMappings A list of mappings from Alfresco property names to Solr field names. * @param req The original request. * @return An array of the facet field names. */ private List<String> rewriteFacetFieldList(ModifiableSolrParams fixed, SolrParams params, String paramName, Map<String, String> fieldMappings, SolrQueryRequest req) { String shardPurpose = req.getParams().get(ShardParams.SHARDS_PURPOSE); boolean isRefinementRequest = false; //Fix for https://issues.alfresco.com/jira/browse/MNT-21015 if (shardPurpose != null) { int shardPurposeCode = Integer.parseInt(shardPurpose); log.debug("ShardPurpose: " + shardPurpose); isRefinementRequest = ((shardPurposeCode & ShardRequest.PURPOSE_REFINE_FACETS) != 0) || ((shardPurposeCode & ShardRequest.PURPOSE_REFINE_PIVOT_FACETS) != 0); } String[] facetFieldsOrig = params.getParams(paramName); List<String> facetFieldList = new ArrayList<>(); if(facetFieldsOrig != null) { ArrayList<String> newFacetFields = new ArrayList<String>(); for(String facetFields : facetFieldsOrig) { StringBuilder commaSeparated = new StringBuilder(); StringBuilder mapping = new StringBuilder(); StringBuilder unmapped = new StringBuilder(); String[] fields = parseFacetField(facetFields); for(String field : fields) { String prefix = ""; field = field.trim(); if(field.endsWith("()")) { // skip facet functions continue; } if(field.startsWith("{!") &&!(isRefinementRequest)) { int index = field.indexOf("}"); if((index > 0) && (index < (field.length() - 1))) { prefix = field.substring(0, index+1); field = field.substring(index+1); } } boolean noMappingIsRequired = req.getSchema().getFieldOrNull(field) != null|| isRefinementRequest; if(noMappingIsRequired) { if(commaSeparated.length() > 0) { commaSeparated.append(","); mapping.append(","); unmapped.append(","); } commaSeparated.append(prefix).append(field); mapping.append(field); unmapped.append(field); facetFieldList.add(field); } else { String mappedField = AlfrescoSolrDataModel.getInstance().mapProperty(field, FieldUse.FACET, req); if(commaSeparated.length() > 0) { commaSeparated.append(","); mapping.append(","); unmapped.append(","); } commaSeparated.append(prefix).append(mappedField); mapping.append(mappedField); unmapped.append(field); facetFieldList.add(mappedField); } } if(!facetFields.equals(commaSeparated.toString())) { fieldMappings.put(unmapped.toString(), mapping.toString()); } if(commaSeparated.length() > 0) { newFacetFields.add(commaSeparated.toString()); } } fixed.set(paramName, newFacetFields.toArray(new String[newFacetFields.size()])); } return facetFieldList; }
Example 20
Source File: AbstractSolrSentryTestBase.java From incubator-sentry with Apache License 2.0 | 4 votes |
/** * Method to populate the Solr params based on the collection admin being performed. * @param adminOp - Collection admin operation * @param collectionName - Name of the collection * @param params - SolrParams to use * @return - instance of QueryRequest. */ public QueryRequest populateCollectionAdminParams(CollectionAction adminOp, String collectionName, SolrParams params) { ModifiableSolrParams modParams = new ModifiableSolrParams(); modParams.set(CoreAdminParams.ACTION, adminOp.name()); switch (adminOp) { case CREATE: modParams.set("name", collectionName); modParams.set("numShards", 2); modParams.set("shards", "shard1,shard2"); modParams.set("replicationFactor", 1); break; case DELETE: modParams.set("name", collectionName); break; case RELOAD: modParams.set("name", collectionName); break; case SPLITSHARD: modParams.set("collection", collectionName); modParams.set("shard", "shard1"); break; case DELETESHARD: modParams.set("collection", collectionName); modParams.set("shard", "shard1"); break; case CREATEALIAS: modParams.set("name", collectionName); modParams.set("collections", collectionName + "_underlying1" + "," + collectionName + "_underlying2"); break; case DELETEALIAS: modParams.set("name", collectionName); break; default: throw new IllegalArgumentException("Admin operation: " + adminOp + " is not supported!"); } if (params != null) { Iterator<String> it = params.getParameterNamesIterator(); while (it.hasNext()) { String param = it.next(); String [] value = params.getParams(param); modParams.set(param, value); } } QueryRequest request = new QueryRequest(modParams); request.setPath("/admin/collections"); return request; }