@Override public void prepare(ResponseBuilder rb) throws IOException { if( SolandraComponent.prepare(rb) ) { ModifiableSolrParams params = new ModifiableSolrParams(rb.req.getParams()); if(params.get(ShardParams.SHARDS_QT) == null) { params.add(ShardParams.SHARDS_QT, "/terms"); } rb.req.setParams(params); } super.prepare(rb); } }
@Override public void setParams(final SolrParams params) { request.setParams(params); }
@Override public void setParams(final SolrParams params) { request.setParams(params); }
public void restoreContext(ResponseBuilder rb) { rb.req.setParams(params); rb.setQueryString(originalQueryString); }
private void configureSolrParameters(SolrQueryRequest req, ModifiableSolrParams params, String uniqueKeyField){ // default to the the edismax parser String defType = params.get(QueryParsing.DEFTYPE, EDISMAX); // allow useage of custom edismax implementations, such as our own if(defType.toLowerCase().contains(EDISMAX.toLowerCase())){ params.set(DisMaxParams.MM, 0); // edismax blows up without df field, even if you specify the field to match on in the query params.set(CommonParams.DF, uniqueKeyField); } params.set(QueryParsing.DEFTYPE, defType); req.setParams(params); }
private void configureSolrParameters(SolrQueryRequest req, ModifiableSolrParams params, String uniqueKeyField){ // default to the the edismax parser String defType = params.get(QueryParsing.DEFTYPE, EDISMAX); // allow useage of custom edismax implementations, such as our own if(defType.toLowerCase().contains(EDISMAX.toLowerCase())){ params.set(DisMaxParams.MM, 0); // edismax blows up without df field, even if you specify the field to match on in the query params.set(CommonParams.DF, uniqueKeyField); } params.set(QueryParsing.DEFTYPE, defType); req.setParams(params); }
/** * Sets the response format to JSON. * * @param req Original Solr request. */ private void formatResponseAsJson(SolrQueryRequest req) { // Return the result as JSON ModifiableSolrParams params = new ModifiableSolrParams(req.getParams()); params.set("wt", "json"); req.setParams(params); }
public SolrQueryResponse handleSuggestionResponseRequest(ReSearcherRequestContext ctx, ModifiableSolrParams params, String componentName, ResponseBuilder rb) throws Exception { params.set(componentName, "false"); rb.req.setParams(params); handleSuggestionRequest(ctx, rb, ctx.getQueryOnlyComponents(), false); return rb.rsp; }
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; } }
@Override public void prepare(ResponseBuilder rb) throws IOException { if (isEnabled(rb)) { rb.setNeedDocSet(true); // De-duplicate field list 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.equals(JointProbabilityParams.FIELDS)) { params.add(paramName, origParams.getParams(paramName)); continue; } HashSet<String> deDupe = new LinkedHashSet<String>(Arrays.asList(origParams.getParams(paramName))); params.add(paramName, deDupe.toArray(new String[deDupe.size()])); } rb.req.setParams(params); } }
/** * This request handler supports configuration options defined at the top level as well as * those in typical Solr 'defaults', 'appends', and 'invariants'. The top level ones are treated * as invariants. */ private void setTopInitArgsAsInvariants(SolrQueryRequest req) { // First convert top level initArgs to SolrParams HashMap<String,String> map = new HashMap<>(initArgs.size()); for (int i=0; i<initArgs.size(); i++) { Object val = initArgs.getVal(i); if (val != null && !(val instanceof NamedList)) map.put(initArgs.getName(i), val.toString()); } if (map.isEmpty()) return;//short circuit; nothing to do SolrParams topInvariants = new MapSolrParams(map); // By putting putting the top level into the 1st arg, it overrides request params in 2nd arg. req.setParams(SolrParams.wrapDefaults(topInvariants, req.getParams())); }
/** * This request handler supports configuration options defined at the top level as well as * those in typical Solr 'defaults', 'appends', and 'invariants'. The top level ones are treated * as invariants. */ private void setTopInitArgsAsInvariants(SolrQueryRequest req) { // First convert top level initArgs to SolrParams HashMap<String,String> map = new HashMap<>(initArgs.size()); for (int i=0; i<initArgs.size(); i++) { Object val = initArgs.getVal(i); if (val != null && !(val instanceof NamedList)) map.put(initArgs.getName(i), val.toString()); } if (map.isEmpty()) return;//short circuit; nothing to do SolrParams topInvariants = new MapSolrParams(map); // By putting putting the top level into the 1st arg, it overrides request params in 2nd arg. req.setParams(SolrParams.wrapDefaults(topInvariants, req.getParams())); }
private void addTreeFieldsToFacets(ResponseBuilder rb) throws SyntaxError { String[] ftFields = rb.req.getParams().getParams(FACET_TREE_FIELD); if (ftFields == null || ftFields.length == 0) { LOGGER.warn("No facet tree fields specified - ignoring facet trees"); } else { // Take a modifiable copy of the incoming params ModifiableSolrParams params = new ModifiableSolrParams(rb.req.getParams()); // Put the original facet fields (if any) into a Set Set<String> facetFields = new LinkedHashSet<>(); if (params.getParams(FacetParams.FACET_FIELD) != null) { facetFields.addAll(Arrays.asList(params.getParams(FacetParams.FACET_FIELD))); } // Add the facet tree fields for (String ftField : ftFields) { // Parse the facet tree field, so we only add the field value, // rather than the whole string (ensure it's unique) facetFields.add(QueryParsing.getLocalParams(ftField, params).get(QueryParsing.V)); } // Add the (possibly) new facet fields params.set(FacetParams.FACET_FIELD, facetFields.toArray(new String[facetFields.size()])); // Re-set the params in the request rb.req.setParams(params); } }
@Override public void prepare(ResponseBuilder rb) throws IOException { if (!enabled) { return; } String userName = sentryInstance.getUserName(rb.req); String superUser = System.getProperty("solr.authorization.superuser", "solr"); if (superUser.equals(userName)) { return; } Set<String> roles = sentryInstance.getRoles(userName); if (roles != null && roles.size() > 0) { String filterQuery = getFilterQueryStr(roles); ModifiableSolrParams newParams = new ModifiableSolrParams(rb.req.getParams()); newParams.add("fq", filterQuery); rb.req.setParams(newParams); } else { throw new SolrException(SolrException.ErrorCode.UNAUTHORIZED, "Request from user: " + userName + " rejected because user is not associated with any roles"); } }
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; }
/** * Set default-ish params on a SolrQueryRequest. * * RequestHandlers can use this method to ensure their defaults and * overrides are visible to other components such as the response writer * * @param req The request whose params we are interested i * @param defaults values to be used if no values are specified in the request params * @param appends values to be appended to those from the request (or defaults) when dealing with multi-val params, or treated as another layer of defaults for singl-val params. * @param invariants values which will be used instead of any request, or default values, regardless of context. */ public static void setDefaults(SolrQueryRequest req, SolrParams defaults, SolrParams appends, SolrParams invariants) { SolrParams p = req.getParams(); if (defaults != null) { p = new DefaultSolrParams(p,defaults); } if (appends != null) { p = new AppendedSolrParams(p,appends); } if (invariants != null) { p = new DefaultSolrParams(invariants,p); } req.setParams(p); }
req.setParams(xmlWriterTypeParams); String response = h.query(req);
/** Makes a query request and returns the JSON string response */ public static String JQ(SolrQueryRequest req) throws Exception { SolrParams params = req.getParams(); if (!"json".equals(params.get("wt","xml")) || params.get("indent")==null) { ModifiableSolrParams newParams = new ModifiableSolrParams(params); newParams.set("wt","json"); if (params.get("indent")==null) newParams.set("indent","true"); req.setParams(newParams); } String response; boolean failed=true; try { response = h.query(req); failed = false; } finally { if (failed) { log.error("REQUEST FAILED: " + req.getParamString()); } } return response; }
modifiableSolrParams.set(CommonParams.FL, requestedFields(fields, req.getSchema().getFields().keySet())); req.setParams(modifiableSolrParams);