@Override public T remove(Object key) { return NamedList.this.remove((String) key); }
/** * NOTE: this runs in linear time (it scans starting at the * beginning of the list until it finds the first pair with * the specified name). */ public T remove(String name) { int idx = indexOf(name, 0); if(idx != -1) return remove(idx); return null; }
/** * NOTE: this runs in linear time (it scans starting at the * beginning of the list until it finds the first pair with * the specified name). */ public T remove(String name) { int idx = indexOf(name, 0); if(idx != -1) return remove(idx); return null; }
/** * Used for getting a boolean argument from a NamedList object. If the name * is not present, returns null. If there is more than one value with that * name, or if the value found is not a Boolean or a String, throws an * exception. If there is only one value present and it is a Boolean or a * String, the value is removed and returned as a Boolean. If an exception * is thrown, the NamedList is not modified. See {@link #removeAll(String)} * and {@link #removeConfigArgs(String)} for additional ways of gathering * configuration information from a NamedList. * * @param name * The key to look up in the NamedList. * @return The boolean value found. * @throws SolrException * If multiple values are found for the name or the value found is * not a Boolean or a String. */ public Boolean removeBooleanArg(final String name) { Boolean bool = getBooleanArg(name); if (null != bool) { remove(name); } return bool; }
/** * Removes all values matching the specified name * * @param name Name */ private void killAll(String name) { int sz = size(); // Go through the list backwards, removing matches as found. for (int i = sz - 1; i >= 0; i--) { String n = getName(i); if (name==n || (name!=null && name.equals(n))) { remove(i); } } }
/** * Removes all values matching the specified name * * @param name Name */ private void killAll(String name) { int sz = size(); // Go through the list backwards, removing matches as found. for (int i = sz - 1; i >= 0; i--) { String n = getName(i); if (name==n || (name!=null && name.equals(n))) { remove(i); } } }
private String parseStringParameter(NamedList mappingNamedList, String paramName) { Object obj = mappingNamedList.remove(paramName); if (obj == null) { return null; } if (!(obj instanceof CharSequence)) { throw new SolrException(SERVER_ERROR, "'" + paramName + "' parameter must be a <str>"); } if (mappingNamedList.get(paramName) != null) { throw new SolrException(SERVER_ERROR, "Each mapping must contain only one '" + paramName + "' <str>"); } return obj.toString(); }
void doFetch(SolrParams solrParams) { String masterUrl = solrParams == null ? null : solrParams.get(MASTER_URL); if (!snapPullLock.tryLock()) return; try { tempSnapPuller = snapPuller; if (masterUrl != null) { NamedList<Object> nl = solrParams.toNamedList(); nl.remove(SnapPuller.POLL_INTERVAL); tempSnapPuller = new SnapPuller(nl, this, core); } tempSnapPuller.fetchLatestIndex(core); } catch (Exception e) { LOG.error("SnapPull failed ", e); } finally { tempSnapPuller = snapPuller; snapPullLock.unlock(); } }
private FieldMapper parseJsonMapping(NamedList args) { List jsonParams = args.getAll(JSON_PARAM); if (jsonParams.size() > 1) { throw new SolrException(SERVER_ERROR, "Only one '" + JSON_PARAM + "' mapping is allowed"); } FieldMapper mapper = null; if (!jsonParams.isEmpty()) { NamedList jsonMappingNamedList = this.validateParameter(JSON_PARAM, jsonParams.get(0)); String fieldType = this.parseFieldTypeParameter(jsonMappingNamedList); mapper = new JsonFieldMapper(fieldType); args.remove(JSON_PARAM); } return mapper; }
private FieldMapper parseDefaultMapping(NamedList args) { List defaultParams = args.getAll(DEFAULT_PARAM); if (defaultParams.size() > 1) { throw new SolrException(SERVER_ERROR, "Only one '" + DEFAULT_PARAM + "' mapping is allowed"); } FieldMapper mapper = null; if (!defaultParams.isEmpty()) { NamedList defaultMappingNamedList = this.validateParameter(DEFAULT_PARAM, defaultParams.get(0)); String fieldType = this.parseFieldTypeParameter(defaultMappingNamedList); mapper = new DefaultFieldMapper(fieldType); args.remove(DEFAULT_PARAM); } return mapper; }
private String parseFieldTypeParameter(NamedList mappingNamedList) { Object fieldTypeObj = mappingNamedList.remove(FIELD_TYPE_PARAM); if (fieldTypeObj == null) { throw new SolrException(SERVER_ERROR, "Each mapping must contain a '" + FIELD_TYPE_PARAM + "' <str>"); } if (!(fieldTypeObj instanceof CharSequence)) { throw new SolrException(SERVER_ERROR, "'" + FIELD_TYPE_PARAM + "' parameter must be a <str>"); } if (mappingNamedList.get(FIELD_TYPE_PARAM) != null) { throw new SolrException(SERVER_ERROR, "Each mapping must contain only one '" + FIELD_TYPE_PARAM + "' <str>"); } return fieldTypeObj.toString(); }
public static SolrQueryRequest substituteField(SolrQueryRequest req){ SolrParams params = req.getParams(); String query = params.get("q"); System.out.println("query before ="+query); query = query.replace(' ', '_'); System.out.println("query after ="+query); NamedList values = params.toNamedList(); values.remove("q"); values.add("q", query); params = SolrParams.toSolrParams(values); req.setParams(params); return req; } }
public void writeResponse() throws IOException { Boolean omitHeader = req.getParams().getBool(CommonParams.OMIT_HEADER); if(omitHeader != null && omitHeader) rsp.getValues().remove("responseHeader"); writeNamedList(null, rsp.getValues()); }
public static SolrQueryRequest substituteField(SolrQueryRequest req, String newFieldName){ SolrParams params = req.getParams(); String query = params.get("q"); String currField = StringUtils.substringBetween(" "+query, " ", ":"); if ( currField !=null && newFieldName!=null) query = query.replace(currField, newFieldName); NamedList values = params.toNamedList(); values.remove("q"); values.add("q", query); params = SolrParams.toSolrParams(values); req.setParams(params); return req; }
/** * Create a new QParser for parsing an embedded nested query. * <p> * Remove the nested parameters from the original request to avoid infinite * recursion. */ @Override public QParser subQuery(final String q, final String defaultType) throws ParseException { final QParser nestedParser = super.subQuery(q, defaultType); final NamedList<Object> params = nestedParser.getParams().toNamedList(); params.remove("nested"); nestedParser.setParams(SolrParams.toSolrParams(params)); return nestedParser; }
/** * Create a new QParser for parsing an embedded nested query. * <p> * Remove the nested parameters from the original request to avoid infinite * recursion. */ @Override public QParser subQuery(final String q, final String defaultType) throws SyntaxError { final QParser nestedParser = super.subQuery(q, defaultType); final NamedList<Object> params = nestedParser.getParams().toNamedList(); params.remove("nested"); nestedParser.setParams(SolrParams.toSolrParams(params)); return nestedParser; }
private List<FieldMapper> parseMappings(NamedList args, String paramName) { List<FieldMapper> mappers = new ArrayList<>(); List params = args.getAll(paramName); if (!params.isEmpty()) { for (Object mapping : params) { NamedList mappingNamedList = this.validateParameter(paramName, mapping); String fieldType = this.parseFieldTypeParameter(mappingNamedList); String path = this.parseStringParameter(mappingNamedList, PATH_PARAM); String type = this.parseStringParameter(mappingNamedList, TYPE_PARAM); if ((path == null && type == null) || (path != null && type != null)) { throw new SolrException(SERVER_ERROR, "Each mapping must contain either a '" + PATH_PARAM + "' or a '" + TYPE_PARAM + "' sub-parameter"); } if (mappingNamedList.size() != 0) { throw new SolrException(SERVER_ERROR, "Unexpected '" + paramName + "' sub-parameter(s): '" + mappingNamedList.toString() + "'"); } if (path == null) { mappers.add(new TypeFieldMapper(type, fieldType)); } else { mappers.add(new PathFieldMapper(path, fieldType)); } } args.remove(paramName); } return mappers; }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public void writeResponse() throws IOException { writer.write(XML_PROCESSING_INSTR); final String stylesheet = req.getParams().get("stylesheet"); if (isNotNullOrEmptyString(stylesheet)) { writer.write(XML_STYLESHEET); escapeAttributeValue(stylesheet, writer); writer.write(XML_STYLESHEET_END); } writer.write(RESPONSE_ROOT_ELEMENT_START); final NamedList<?> responseValues = rsp.getValues(); if (req.getParams().getBool(CommonParams.OMIT_HEADER, false)) { responseValues.remove(RESPONSE_HEADER); } else { ((NamedList)responseValues.get(RESPONSE_HEADER)).add(Names.QUERY, responseValues.remove(Names.QUERY).toString()); } for (final Entry<String, ?> entry : responseValues) { writeValue(entry.getKey(), entry.getValue(), responseValues); } writer.write(RESPONSE_ROOT_ELEMENT_END); }
public void writeResponse() throws IOException { if(wrapperFunction!=null) { writer.write(wrapperFunction + "("); } Boolean omitHeader = req.getParams().getBool(CommonParams.OMIT_HEADER); if(omitHeader != null && omitHeader) rsp.getValues().remove("responseHeader"); writeNamedList(null, rsp.getValues()); if(wrapperFunction!=null) { writer.write(')'); } }
public void write(OutputStream out, SolrQueryRequest req, SolrQueryResponse response) throws IOException { Resolver resolver = new Resolver(req, response.getReturnFields()); Boolean omitHeader = req.getParams().getBool(CommonParams.OMIT_HEADER); if (omitHeader != null && omitHeader) response.getValues().remove("responseHeader"); JavaBinCodec codec = new JavaBinCodec(resolver); codec.marshal(response.getValues(), out); }