Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions changelog/unreleased/SOLR-18612-core-search.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc

title: >
Some search-side response sections whose keys never repeat are now JSON objects regardless of
json.nl: Luke's per-field histogram and topTerms, MoreLikeThis interestingTerms (details) and the
SolrCloud moreLikeThis section, managed-resource initArgs, the {!igain} featuredTerms/docFreq and
{!tlogit} logit sections, the Core Admin SPLIT response, and the debug section of an empty result.
The Admin UI Schema Browser reads both the old and the new form. Clients using json.nl=map or XML
see the same response shape; SolrJ decodes these sections as SimpleOrderedMap instances, which
remain NamedList instances.
type: changed
authors:
- name: Ivan Šarić
nick: isaric
links:
- name: SOLR-18612
url: https://issues.apache.org/jira/browse/SOLR-18612
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.CollectionUtil;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.common.util.StrUtils;
import org.apache.solr.handler.admin.api.MoreLikeThisAPI;
import org.apache.solr.handler.component.DebugComponent;
Expand Down Expand Up @@ -203,7 +204,7 @@ public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throw
final List<InterestingTerm> interesting =
mlt.getInterestingTerms(mlt.getBoostedMLTQuery(), mlt.mlt.getMaxQueryTerms());
if (termStyle == TermStyle.DETAILS) {
NamedList<Float> it = new NamedList<>();
NamedList<Float> it = new SimpleOrderedMap<>();
for (InterestingTerm t : interesting) {
it.add(t.term.toString(), t.boost);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ public void add(int[] buckets) {

// TODO? should this be a list or a map?
public NamedList<Integer> toNamedList() {
NamedList<Integer> nl = new NamedList<>();
NamedList<Integer> nl = new SimpleOrderedMap<>();
for (int bucket = 0; bucket <= _maxBucket; bucket++) {
nl.add("" + (1 << bucket), _buckets[bucket]);
}
Expand Down Expand Up @@ -1276,7 +1276,7 @@ public NamedList<Integer> toNamedList(IndexSchema schema) {
aslist.add(0, pop());
}

NamedList<Integer> list = new NamedList<>();
NamedList<Integer> list = new SimpleOrderedMap<>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI text below 🤖

Could we keep topTerms as a NamedList? The queue holds distinct indexed terms, but the response uses indexedToReadable() as the key. A legacy TrieIntField with multiple precision levels can have several indexed terms that all decode to "0", with different document frequencies. The old flat response keeps each entry. JSON clients parsing the new object can only see one. The histogram can still move to a map independently.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed; indexedToReadable() isn't injective for Trie precision terms. topTerms stays a NamedList, histogram moves (1d3c635).

for (TermInfo i : aslist) {
String txt = i.term.text();
SchemaField ft = schema.getFieldOrNull(i.term.field());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ public void process(ResponseBuilder rb) throws IOException {
if (params.get(MoreLikeThisComponent.DIST_DOC_ID) == null) {
if (rb.getResults().docList.size() == 0) {
// return empty response
rb.rsp.add("moreLikeThis", new NamedList<DocList>());
rb.rsp.add("moreLikeThis", new SimpleOrderedMap<DocList>());
return;
}
MoreLikeThisHandler.MoreLikeThisHelper mlt =
new MoreLikeThisHandler.MoreLikeThisHelper(params, searcher);
NamedList<NamedList<?>> mltQueryByDocKey = new NamedList<>();
NamedList<NamedList<?>> mltQueryByDocKey = new SimpleOrderedMap<>();
QueryLimits queryLimits = QueryLimits.getCurrentLimits();
SolrDocumentFetcher docFetcher = rb.req.getSearcher().getDocFetcher();
for (DocIterator results = rb.getResults().docList.iterator(); results.hasNext(); ) {
Expand Down Expand Up @@ -142,7 +142,7 @@ private static NamedList<String> mltViaQueryParams(
List<MoreLikeThisHandler.InterestingTerm> terms,
String uniqueField,
String uniqueVal) {
final NamedList<String> mltQ = new NamedList<>();
final NamedList<String> mltQ = new SimpleOrderedMap<>();
StringBuilder q = new StringBuilder("{!bool");
q.append(" must_not=$");
int cnt = 0;
Expand Down Expand Up @@ -291,7 +291,7 @@ public void modifyRequest(ResponseBuilder rb, SearchComponent who, ShardRequest
/** Returns NamedList based on the order of resultIds.shardDoc.positionInResponse */
NamedList<SolrDocumentList> buildMoreLikeThisNamed(
Map<Object, SolrDocumentList> allMlt, Map<Object, ShardDoc> resultIds) {
NamedList<SolrDocumentList> result = new NamedList<>();
NamedList<SolrDocumentList> result = new SimpleOrderedMap<>();
TreeMap<Integer, Object> sortingMap = new TreeMap<>();
for (Entry<Object, ShardDoc> next : resultIds.entrySet()) {
sortingMap.put(next.getValue().positionInResponse, next.getKey());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -787,8 +787,8 @@ private static void shortCircuitedResults(SolrQueryRequest req, ResponseBuilder
}
}
if (rb.isDebug()) {
NamedList<Object> debug = new NamedList<>();
debug.add("explain", new NamedList<>());
NamedList<Object> debug = new SimpleOrderedMap<>();
debug.add("explain", new SimpleOrderedMap<>());
rb.rsp.add("debug", debug);
}
rb.rsp.setPartialResults(rb.req);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -700,11 +700,11 @@ public void inform(SolrCore core) {
if (cfg instanceof NamedList) {
addSpellChecker(core, hasDefault, (NamedList<?>) cfg);
} else if (cfg instanceof Map) {
addSpellChecker(core, hasDefault, new NamedList<>((Map<String, ?>) cfg));
addSpellChecker(core, hasDefault, toNamedList((Map<String, ?>) cfg));
} else if (cfg instanceof List) {
for (Object o : (List<?>) cfg) {
if (o instanceof Map) {
addSpellChecker(core, hasDefault, new NamedList<>((Map<String, ?>) o));
addSpellChecker(core, hasDefault, toNamedList((Map<String, ?>) o));
}
}
}
Expand Down Expand Up @@ -734,6 +734,12 @@ public void inform(SolrCore core) {
}
}

private static NamedList<?> toNamedList(Map<String, ?> config) {
NamedList<Object> nl = new SimpleOrderedMap<>();
config.forEach(nl::add);
return nl;
}

private boolean addSpellChecker(SolrCore core, boolean hasDefault, NamedList<?> spellchecker) {
String className = (String) spellchecker.get("classname");
if (className == null) className = (String) spellchecker.get("class");
Expand Down
15 changes: 12 additions & 3 deletions solr/core/src/java/org/apache/solr/rest/ManagedResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.core.SolrResourceLoader;
import org.apache.solr.rest.ManagedResourceStorage.StorageIO;
import org.slf4j.Logger;
Expand Down Expand Up @@ -140,6 +141,14 @@ public Class<? extends BaseSolrResource> getServerResourceClass() {
return RestManager.ManagedEndpoint.class;
}

private static NamedList<Object> toInitArgs(Map<String, Object> initArgsMap) {
NamedList<Object> initArgs = new SimpleOrderedMap<>();
if (initArgsMap != null) {
initArgs.addAll(initArgsMap);
}
return initArgs;
}

/**
* Called from {@link #doPut(BaseSolrResource,Object)} to update this resource's init args using
* the given updatedArgs
Expand Down Expand Up @@ -174,7 +183,7 @@ protected synchronized void reloadFromStorage() throws SolrException {

Object managedData = processStoredData(data);

if (managedInitArgs == null) managedInitArgs = new NamedList<>();
if (managedInitArgs == null) managedInitArgs = new SimpleOrderedMap<>();

onManagedDataLoadedFromStorage(managedInitArgs, managedData);
}
Expand All @@ -193,7 +202,7 @@ protected Object processStoredData(Object data) throws SolrException {
Map<String, Object> jsonMap = (Map<String, Object>) data;
@SuppressWarnings({"unchecked"})
Map<String, Object> initArgsMap = (Map<String, Object>) jsonMap.get(INIT_ARGS_JSON_FIELD);
managedInitArgs = new NamedList<>(initArgsMap);
managedInitArgs = toInitArgs(initArgsMap);
log.info("Loaded initArgs {} for {}", managedInitArgs, resourceId);

if (jsonMap.containsKey(MANAGED_JSON_LIST_FIELD)) {
Expand Down Expand Up @@ -361,7 +370,7 @@ public synchronized void doPut(BaseSolrResource endpoint, Object json) {
|| jsonMap.containsKey(MANAGED_JSON_LIST_FIELD)
|| jsonMap.containsKey(MANAGED_JSON_MAP_FIELD)) {
Map<String, Object> initArgsMap = (Map<String, Object>) jsonMap.get(INIT_ARGS_JSON_FIELD);
updatedInitArgs = updateInitArgs(new NamedList<>(initArgsMap));
updatedInitArgs = updateInitArgs(toInitArgs(initArgsMap));

if (jsonMap.containsKey(MANAGED_JSON_LIST_FIELD)) {
managedData = jsonMap.get(MANAGED_JSON_LIST_FIELD);
Expand Down
2 changes: 1 addition & 1 deletion solr/core/src/java/org/apache/solr/rest/RestManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ protected synchronized void reloadFromStorage() throws SolrException {

Object managedData = processStoredData(data);

if (managedInitArgs == null) managedInitArgs = new NamedList<>();
if (managedInitArgs == null) managedInitArgs = new SimpleOrderedMap<>();

if (managedData != null) onManagedDataLoadedFromStorage(managedInitArgs, managedData);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.lucene.util.SparseFixedBitSet;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.handler.component.ResponseBuilder;
import org.apache.solr.request.SolrQueryRequest;

Expand Down Expand Up @@ -147,9 +148,9 @@ public void collect(int doc) throws IOException {

@Override
public void complete() throws IOException {
NamedList<Double> analytics = new NamedList<>();
NamedList<Integer> topFreq = new NamedList<>();
NamedList<Integer> allFreq = new NamedList<>();
NamedList<Double> analytics = new SimpleOrderedMap<>();
NamedList<Integer> topFreq = new SimpleOrderedMap<>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI text below 🤖

Could we leave docFreq as a NamedList in this slice? The producer adds each term’s real frequency to topFreq, then adds each featured term a second time using allFreq.get(...). Nothing populates allFreq, so that second value is null. The old flat response preserves both entries; the new object writes duplicate properties, and a last-wins parser like JSON.parse returns null for the featured term. If we want to convert this section, could we fix the duplicate-producing code first and add a JSON test that checks the featured term’s frequency?

@isaric isaric Nov 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, and a pre-existing bug: allFreq is never filled, so every featured term gets a second, null entry. Left docFreq as a NamedList in this slice (1d3c635); filed SOLR-18677 for the duplicate entries.

NamedList<Integer> allFreq = new SimpleOrderedMap<>();

rb.rsp.add("featuredTerms", analytics);
rb.rsp.add("docFreq", topFreq);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.lucene.util.SparseFixedBitSet;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.handler.component.ResponseBuilder;
import org.apache.solr.request.SolrQueryRequest;

Expand Down Expand Up @@ -180,8 +181,8 @@ public void complete() throws IOException {
List<Integer> outQueryFreq = new ArrayList<>();
List<Double> scores = new ArrayList<>();

NamedList<Integer> allFreq = new NamedList<>();
NamedList<Integer> allQueryFreq = new NamedList<>();
NamedList<Integer> allFreq = new SimpleOrderedMap<>();
NamedList<Integer> allQueryFreq = new SimpleOrderedMap<>();

LinkedHashMap<String, Object> response = new LinkedHashMap<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.solr.client.solrj.io.ClassificationEvaluation;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.handler.component.ResponseBuilder;
import org.apache.solr.request.SolrQueryRequest;

Expand Down Expand Up @@ -216,7 +217,7 @@ public void complete() throws IOException {
}
}

NamedList<Object> analytics = new NamedList<>();
NamedList<Object> analytics = new SimpleOrderedMap<>();
rbsp.rsp.add("logit", analytics);

List<Double> outWeights = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.common.util.StrUtils;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.schema.IndexSchema;
Expand Down Expand Up @@ -452,7 +453,7 @@ public SolrQueryRequest getSolrRequest() {
@SuppressWarnings({"unchecked", "rawtypes"})
public static SolrParams jsonToSolrParams(Map jsonObject) {
// HACK, but NamedList already handles the list processing for us...
NamedList<String> nl = new NamedList<>();
NamedList<String> nl = new SimpleOrderedMap<>();
nl.addAll(jsonObject);
return nl.toSolrParams();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.lucene.util.CharsRefBuilder;
import org.apache.solr.common.util.CollectionUtil;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.schema.SchemaField;
import org.apache.solr.search.SolrIndexSearcher;
import org.apache.solr.search.grouping.Command;
Expand Down Expand Up @@ -56,7 +57,7 @@ public SearchGroupsResultTransformer(SolrIndexSearcher searcher) {
public NamedList<NamedList<Object>> transform(List<Command<?>> data) throws IOException {
final NamedList<NamedList<Object>> result = new NamedList<>(data.size());
for (Command<?> command : data) {
final NamedList<Object> commandResult = new NamedList<>(2);
final NamedList<Object> commandResult = new SimpleOrderedMap<>(2);
if (command instanceof SearchGroupsFieldCommand fieldCommand) {
final SearchGroupsFieldCommandResult fieldCommandResult = fieldCommand.result();
final Collection<SearchGroup<BytesRef>> searchGroups = fieldCommandResult.getSearchGroups();
Expand Down Expand Up @@ -150,7 +151,7 @@ private Object[] serializeOneSearchGroup(

private NamedList<Object[]> serializeSearchGroup(
Collection<SearchGroup<BytesRef>> data, SearchGroupsFieldCommand command) {
final NamedList<Object[]> result = new NamedList<>(data.size());
final NamedList<Object[]> result = new SimpleOrderedMap<>(data.size());

SortField[] groupSortField = command.getGroupSort().getSort();
for (SearchGroup<BytesRef> searchGroup : data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.CharsRefBuilder;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.handler.component.ResponseBuilder;
import org.apache.solr.handler.component.ShardDoc;
import org.apache.solr.schema.FieldType;
Expand Down Expand Up @@ -229,7 +230,7 @@ protected NamedList<Object> serializeTopGroups(TopGroups<BytesRef> data, SchemaF
final IndexSchema schema = rb.req.getSearcher().getSchema();
SchemaField uniqueField = schema.getUniqueKeyField();
for (GroupDocs<BytesRef> searchGroup : data.groups) {
NamedList<Object> groupResult = new NamedList<>();
NamedList<Object> groupResult = new SimpleOrderedMap<>();
assert searchGroup.totalHits().relation() == TotalHits.Relation.EQUAL_TO;
groupResult.add("totalHits", searchGroup.totalHits().value());
if (!Float.isNaN(searchGroup.maxScore())) {
Expand All @@ -239,7 +240,7 @@ protected NamedList<Object> serializeTopGroups(TopGroups<BytesRef> data, SchemaF
SolrDocumentFetcher docFetcher = rb.req.getSearcher().getDocFetcher();
List<NamedList<Object>> documents = new ArrayList<>();
for (int i = 0; i < searchGroup.scoreDocs().length; i++) {
NamedList<Object> document = new NamedList<>();
NamedList<Object> document = new SimpleOrderedMap<>();
documents.add(document);

Document doc = retrieveDocument(uniqueField, searchGroup.scoreDocs()[i].doc, docFetcher);
Expand Down Expand Up @@ -284,7 +285,7 @@ protected NamedList<Object> serializeTopGroups(TopGroups<BytesRef> data, SchemaF
}

protected NamedList<Object> serializeTopDocs(QueryCommandResult result) throws IOException {
NamedList<Object> queryResult = new NamedList<>();
NamedList<Object> queryResult = new SimpleOrderedMap<>();
queryResult.add("matches", result.getMatches());
TopDocs topDocs = result.getTopDocs();
assert topDocs.totalHits.relation() == TotalHits.Relation.EQUAL_TO;
Expand All @@ -301,7 +302,7 @@ protected NamedList<Object> serializeTopDocs(QueryCommandResult result) throws I
final IndexSchema schema = rb.req.getSearcher().getSchema();
SchemaField uniqueField = schema.getUniqueKeyField();
for (ScoreDoc scoreDoc : result.getTopDocs().scoreDocs) {
NamedList<Object> document = new NamedList<>();
NamedList<Object> document = new SimpleOrderedMap<>();
documents.add(document);

Document doc = retrieveDocument(uniqueField, scoreDoc.doc, docFetcher);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.apache.solr.common.cloud.Replica;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.core.SolrConfig.UpdateHandlerInfo;
import org.apache.solr.core.SolrCore;
import org.apache.solr.metrics.SolrMetricProducer;
Expand Down Expand Up @@ -1126,7 +1127,7 @@ public void split(SplitIndexCommand cmd) throws IOException {
commit(new CommitUpdateCommand(cmd.req, false));
SolrIndexSplitter splitter = new SolrIndexSplitter(cmd);
splitCommands.inc();
NamedList<Object> results = new NamedList<>();
NamedList<Object> results = new SimpleOrderedMap<>();
try {
splitter.split(results);
cmd.rsp.addResponse(results);
Expand Down
18 changes: 9 additions & 9 deletions solr/solr-ref-guide/modules/query-guide/pages/morelikethis.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,10 @@ Because we did not also specify `mlt.boost`, the boost values shown for the inte
"genre_s":"fantasy",
"_version_":1693062911095734272}]
},
"interestingTerms":[
"author:r.r",1.0,
"author:george",1.0,
"author:martin",1.0]}
"interestingTerms":{
"author:r.r":1.0,
"author:george":1.0,
"author:martin":1.0}}
----

If we had not requested `mlt.match.include=true`, the response would not have included the `match` section.
Expand Down Expand Up @@ -440,8 +440,8 @@ Each of these documents are similar to the document in the result list to varyin
"genre_s":"fantasy",
"_version_":1693062911095734272}]
},
"moreLikeThis":[
"0553573403",{"numFound":6,"start":0,"maxScore":1.6554483,"numFoundExact":true,
"moreLikeThis":{
"0553573403":{"numFound":6,"start":0,"maxScore":1.6554483,"numFoundExact":true,
"docs":[
{
"id":"055357342X",
Expand All @@ -459,7 +459,7 @@ Each of these documents are similar to the document in the result list to varyin
"id":"978-1423103349",
"score":0.7652973}]
},
"0553579908",{"numFound":5,"start":0,"maxScore":1.6554483,"numFoundExact":true,
"0553579908":{"numFound":5,"start":0,"maxScore":1.6554483,"numFoundExact":true,
"docs":[
{
"id":"055357342X",
Expand All @@ -477,7 +477,7 @@ Each of these documents are similar to the document in the result list to varyin
"id":"VDBDB1A16",
"score":0.68205893}]
},
"055357342X",{"numFound":5,"start":0,"maxScore":1.6554483,"numFoundExact":true,
"055357342X":{"numFound":5,"start":0,"maxScore":1.6554483,"numFoundExact":true,
"docs":[
{
"id":"0553579908",
Expand All @@ -494,7 +494,7 @@ Each of these documents are similar to the document in the result list to varyin
{
"id":"VDBDB1A16",
"score":0.68205893}]
}]}
}}}
----

== MoreLikeThis Query Parser
Expand Down
Loading