Skip to content

Commit

Permalink
Also clarify SolrRequest.getParams nad QParser params
Browse files Browse the repository at this point in the history
  • Loading branch information
dsmiley committed Feb 2, 2025
1 parent 010ae6f commit 44a83b0
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ public static void squashIntoNamedListWithoutHeader(
}

public static String getMediaTypeFromWtParam(SolrParams params, String defaultMediaType) {
if (params == null) {
return defaultMediaType;
}
final String wtParam = params.get(WT);
if (StrUtils.isBlank(wtParam)) return defaultMediaType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static boolean disallowPartialResults(SolrParams params) {
return !allowPartialResults(params);
}

/** returns the current request parameters */
/** The parameters for this request; never null. Use {@link #setParams(SolrParams)} to change. */
SolrParams getParams();

/**
Expand All @@ -88,8 +88,8 @@ static boolean disallowPartialResults(SolrParams params) {
Iterable<ContentStream> getContentStreams();

/**
* Returns the original request parameters. As this does not normally include configured defaults
* it's more suitable for logging.
* The original request parameters; never null. As this does not normally include configured
* defaults, it's more suitable for logging.
*/
SolrParams getOriginalParams();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.apache.solr.api.ApiBag;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.SolrParams;
Expand Down Expand Up @@ -62,8 +63,8 @@ public abstract class SolrQueryRequestBase implements SolrQueryRequest, Closeabl
public SolrQueryRequestBase(SolrCore core, SolrParams params, RTimerTree requestTimer) {
this.core = core;
this.schema = null == core ? null : core.getLatestSchema();
this.params = this.origParams = params;
this.requestTimer = requestTimer;
this.params = this.origParams = Objects.requireNonNull(params);
this.requestTimer = Objects.requireNonNull(requestTimer);
this.startTime = System.currentTimeMillis();
}

Expand All @@ -90,7 +91,7 @@ public SolrParams getOriginalParams() {

@Override
public void setParams(SolrParams params) {
this.params = params;
this.params = Objects.requireNonNull(params);
}

// Get the start time of this request in milliseconds
Expand Down
12 changes: 7 additions & 5 deletions solr/core/src/java/org/apache/solr/search/QParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.apache.lucene.search.Query;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CommonParams;
Expand Down Expand Up @@ -62,10 +63,11 @@ public abstract class QParser {
/**
* Constructor for the QParser
*
* @param qstr The part of the query string specific to this parser
* @param localParams The set of parameters that are specific to this QParser. See
* @param qstr The query string to be parsed
* @param localParams Params scoped to this query, customizing the parsing. Null if none. Most
* params the parser needs are resolved here first, overlaying the request. See
* https://solr.apache.org/guide/solr/latest/query-guide/local-params.html
* @param params The rest of the {@link org.apache.solr.common.params.SolrParams}
* @param params Params for the request, taken from {@link SolrQueryRequest#getParams()}; not null
* @param req The original {@link org.apache.solr.request.SolrQueryRequest}.
*/
public QParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) {
Expand Down Expand Up @@ -97,7 +99,7 @@ public QParser(String qstr, SolrParams localParams, SolrParams params, SolrQuery
}
}

this.params = params;
this.params = Objects.requireNonNull(params);
this.req = req;
}

Expand Down Expand Up @@ -160,7 +162,7 @@ public SolrParams getParams() {
}

public void setParams(SolrParams params) {
this.params = params;
this.params = Objects.requireNonNull(params);
}

public SolrQueryRequest getReq() {
Expand Down
6 changes: 5 additions & 1 deletion solr/core/src/java/org/apache/solr/search/QParserPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ public abstract class QParserPlugin implements NamedListInitializedPlugin, SolrI
standardPlugins = Collections.unmodifiableMap(map);
}

/** return a {@link QParser} */
/**
* Creates the {@link QParser}.
*
* @see QParser#QParser(String, SolrParams, SolrParams, SolrQueryRequest)
*/
public abstract QParser createParser(
String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import jakarta.ws.rs.core.MediaType;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SolrParams;
import org.junit.Test;

public class V2ApiUtilsTest extends SolrTestCaseJ4 {
Expand All @@ -44,9 +45,7 @@ public void testReadsDisableV2ApiSysprop() {

@Test
public void testConvertsWtToMediaTypeString() {
assertEquals(
"someDefault",
V2ApiUtils.getMediaTypeFromWtParam(new ModifiableSolrParams(), "someDefault"));
assertEquals("someDefault", V2ApiUtils.getMediaTypeFromWtParam(SolrParams.of(), "someDefault"));

var params = new ModifiableSolrParams();
params.add("wt", "json");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ public MockAuthorizationContext(Map<String, Object> values) {
@Override
public SolrParams getParams() {
SolrParams params = (SolrParams) values.get("params");
return params == null ? new MapSolrParams(new HashMap<>()) : params;
return params == null ? SolrParams.of() : params;
}

@Override
Expand Down

0 comments on commit 44a83b0

Please sign in to comment.