diff --git a/changelog/unreleased/SOLR-18612-core-search.yml b/changelog/unreleased/SOLR-18612-core-search.yml new file mode 100644 index 000000000000..94b5078f35f7 --- /dev/null +++ b/changelog/unreleased/SOLR-18612-core-search.yml @@ -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, MoreLikeThis interestingTerms (details) and the SolrCloud + moreLikeThis section, the {!igain} featuredTerms 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 diff --git a/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java b/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java index fc44b4fa6ce4..c40fb1103734 100644 --- a/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java @@ -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; @@ -203,7 +204,7 @@ public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throw final List interesting = mlt.getInterestingTerms(mlt.getBoostedMLTQuery(), mlt.mlt.getMaxQueryTerms()); if (termStyle == TermStyle.DETAILS) { - NamedList it = new NamedList<>(); + NamedList it = new SimpleOrderedMap<>(); for (InterestingTerm t : interesting) { it.add(t.term.toString(), t.boost); } diff --git a/solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java index eb58059457e3..e1ad6ab1da7e 100644 --- a/solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java @@ -1234,7 +1234,7 @@ public void add(int[] buckets) { // TODO? should this be a list or a map? public NamedList toNamedList() { - NamedList nl = new NamedList<>(); + NamedList nl = new SimpleOrderedMap<>(); for (int bucket = 0; bucket <= _maxBucket; bucket++) { nl.add("" + (1 << bucket), _buckets[bucket]); } diff --git a/solr/core/src/java/org/apache/solr/handler/component/MoreLikeThisComponent.java b/solr/core/src/java/org/apache/solr/handler/component/MoreLikeThisComponent.java index 0103d7de8637..5f2c95fca41e 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/MoreLikeThisComponent.java +++ b/solr/core/src/java/org/apache/solr/handler/component/MoreLikeThisComponent.java @@ -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()); + rb.rsp.add("moreLikeThis", new SimpleOrderedMap()); return; } MoreLikeThisHandler.MoreLikeThisHelper mlt = new MoreLikeThisHandler.MoreLikeThisHelper(params, searcher); - NamedList> mltQueryByDocKey = new NamedList<>(); + NamedList> mltQueryByDocKey = new SimpleOrderedMap<>(); QueryLimits queryLimits = QueryLimits.getCurrentLimits(); SolrDocumentFetcher docFetcher = rb.req.getSearcher().getDocFetcher(); for (DocIterator results = rb.getResults().docList.iterator(); results.hasNext(); ) { @@ -142,7 +142,7 @@ private static NamedList mltViaQueryParams( List terms, String uniqueField, String uniqueVal) { - final NamedList mltQ = new NamedList<>(); + final NamedList mltQ = new SimpleOrderedMap<>(); StringBuilder q = new StringBuilder("{!bool"); q.append(" must_not=$"); int cnt = 0; @@ -291,7 +291,7 @@ public void modifyRequest(ResponseBuilder rb, SearchComponent who, ShardRequest /** Returns NamedList based on the order of resultIds.shardDoc.positionInResponse */ NamedList buildMoreLikeThisNamed( Map allMlt, Map resultIds) { - NamedList result = new NamedList<>(); + NamedList result = new SimpleOrderedMap<>(); TreeMap sortingMap = new TreeMap<>(); for (Entry next : resultIds.entrySet()) { sortingMap.put(next.getValue().positionInResponse, next.getKey()); diff --git a/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java b/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java index 62ec19cfca0c..975219746f36 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java @@ -787,8 +787,8 @@ private static void shortCircuitedResults(SolrQueryRequest req, ResponseBuilder } } if (rb.isDebug()) { - NamedList debug = new NamedList<>(); - debug.add("explain", new NamedList<>()); + NamedList debug = new SimpleOrderedMap<>(); + debug.add("explain", new SimpleOrderedMap<>()); rb.rsp.add("debug", debug); } rb.rsp.setPartialResults(rb.req); diff --git a/solr/core/src/java/org/apache/solr/handler/component/SpellCheckComponent.java b/solr/core/src/java/org/apache/solr/handler/component/SpellCheckComponent.java index 0221f720f4d8..23ac88351765 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/SpellCheckComponent.java +++ b/solr/core/src/java/org/apache/solr/handler/component/SpellCheckComponent.java @@ -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) cfg)); + addSpellChecker(core, hasDefault, toNamedList((Map) cfg)); } else if (cfg instanceof List) { for (Object o : (List) cfg) { if (o instanceof Map) { - addSpellChecker(core, hasDefault, new NamedList<>((Map) o)); + addSpellChecker(core, hasDefault, toNamedList((Map) o)); } } } @@ -734,6 +734,12 @@ public void inform(SolrCore core) { } } + private static NamedList toNamedList(Map config) { + NamedList 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"); diff --git a/solr/core/src/java/org/apache/solr/rest/ManagedResource.java b/solr/core/src/java/org/apache/solr/rest/ManagedResource.java index a297e698b415..64c2207fb704 100644 --- a/solr/core/src/java/org/apache/solr/rest/ManagedResource.java +++ b/solr/core/src/java/org/apache/solr/rest/ManagedResource.java @@ -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; @@ -140,6 +141,14 @@ public Class getServerResourceClass() { return RestManager.ManagedEndpoint.class; } + private static NamedList toInitArgs(Map initArgsMap) { + NamedList 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 @@ -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); } @@ -193,7 +202,7 @@ protected Object processStoredData(Object data) throws SolrException { Map jsonMap = (Map) data; @SuppressWarnings({"unchecked"}) Map initArgsMap = (Map) 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)) { @@ -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 initArgsMap = (Map) 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); diff --git a/solr/core/src/java/org/apache/solr/rest/RestManager.java b/solr/core/src/java/org/apache/solr/rest/RestManager.java index f175ca861b8d..83e98b0ea226 100644 --- a/solr/core/src/java/org/apache/solr/rest/RestManager.java +++ b/solr/core/src/java/org/apache/solr/rest/RestManager.java @@ -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); } diff --git a/solr/core/src/java/org/apache/solr/search/IGainTermsQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/IGainTermsQParserPlugin.java index eba8327360ad..374d75c9fc61 100644 --- a/solr/core/src/java/org/apache/solr/search/IGainTermsQParserPlugin.java +++ b/solr/core/src/java/org/apache/solr/search/IGainTermsQParserPlugin.java @@ -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; @@ -147,7 +148,7 @@ public void collect(int doc) throws IOException { @Override public void complete() throws IOException { - NamedList analytics = new NamedList<>(); + NamedList analytics = new SimpleOrderedMap<>(); NamedList topFreq = new NamedList<>(); NamedList allFreq = new NamedList<>(); diff --git a/solr/core/src/java/org/apache/solr/search/SignificantTermsQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/SignificantTermsQParserPlugin.java index 3fdb46ee5a2b..10fac51f334e 100644 --- a/solr/core/src/java/org/apache/solr/search/SignificantTermsQParserPlugin.java +++ b/solr/core/src/java/org/apache/solr/search/SignificantTermsQParserPlugin.java @@ -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; @@ -180,8 +181,8 @@ public void complete() throws IOException { List outQueryFreq = new ArrayList<>(); List scores = new ArrayList<>(); - NamedList allFreq = new NamedList<>(); - NamedList allQueryFreq = new NamedList<>(); + NamedList allFreq = new SimpleOrderedMap<>(); + NamedList allQueryFreq = new SimpleOrderedMap<>(); LinkedHashMap response = new LinkedHashMap<>(); diff --git a/solr/core/src/java/org/apache/solr/search/TextLogisticRegressionQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/TextLogisticRegressionQParserPlugin.java index 0f8142da3993..163d8c562413 100644 --- a/solr/core/src/java/org/apache/solr/search/TextLogisticRegressionQParserPlugin.java +++ b/solr/core/src/java/org/apache/solr/search/TextLogisticRegressionQParserPlugin.java @@ -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; @@ -216,7 +217,7 @@ public void complete() throws IOException { } } - NamedList analytics = new NamedList<>(); + NamedList analytics = new SimpleOrderedMap<>(); rbsp.rsp.add("logit", analytics); List outWeights = new ArrayList<>(); diff --git a/solr/core/src/java/org/apache/solr/search/facet/FacetParser.java b/solr/core/src/java/org/apache/solr/search/facet/FacetParser.java index 92d6ef2fb7d9..529355bc5ab3 100644 --- a/solr/core/src/java/org/apache/solr/search/facet/FacetParser.java +++ b/solr/core/src/java/org/apache/solr/search/facet/FacetParser.java @@ -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; @@ -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 nl = new NamedList<>(); + NamedList nl = new SimpleOrderedMap<>(); nl.addAll(jsonObject); return nl.toSolrParams(); } diff --git a/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/SearchGroupsResultTransformer.java b/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/SearchGroupsResultTransformer.java index b94863407a91..d9c40ec46c23 100644 --- a/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/SearchGroupsResultTransformer.java +++ b/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/SearchGroupsResultTransformer.java @@ -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; @@ -56,7 +57,7 @@ public SearchGroupsResultTransformer(SolrIndexSearcher searcher) { public NamedList> transform(List> data) throws IOException { final NamedList> result = new NamedList<>(data.size()); for (Command command : data) { - final NamedList commandResult = new NamedList<>(2); + final NamedList commandResult = new SimpleOrderedMap<>(2); if (command instanceof SearchGroupsFieldCommand fieldCommand) { final SearchGroupsFieldCommandResult fieldCommandResult = fieldCommand.result(); final Collection> searchGroups = fieldCommandResult.getSearchGroups(); @@ -150,7 +151,7 @@ private Object[] serializeOneSearchGroup( private NamedList serializeSearchGroup( Collection> data, SearchGroupsFieldCommand command) { - final NamedList result = new NamedList<>(data.size()); + final NamedList result = new SimpleOrderedMap<>(data.size()); SortField[] groupSortField = command.getGroupSort().getSort(); for (SearchGroup searchGroup : data) { diff --git a/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/TopGroupsResultTransformer.java b/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/TopGroupsResultTransformer.java index 2da4835b18ae..70bb96310aca 100644 --- a/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/TopGroupsResultTransformer.java +++ b/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/TopGroupsResultTransformer.java @@ -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; @@ -229,7 +230,7 @@ protected NamedList serializeTopGroups(TopGroups data, SchemaF final IndexSchema schema = rb.req.getSearcher().getSchema(); SchemaField uniqueField = schema.getUniqueKeyField(); for (GroupDocs searchGroup : data.groups) { - NamedList groupResult = new NamedList<>(); + NamedList groupResult = new SimpleOrderedMap<>(); assert searchGroup.totalHits().relation() == TotalHits.Relation.EQUAL_TO; groupResult.add("totalHits", searchGroup.totalHits().value()); if (!Float.isNaN(searchGroup.maxScore())) { @@ -239,7 +240,7 @@ protected NamedList serializeTopGroups(TopGroups data, SchemaF SolrDocumentFetcher docFetcher = rb.req.getSearcher().getDocFetcher(); List> documents = new ArrayList<>(); for (int i = 0; i < searchGroup.scoreDocs().length; i++) { - NamedList document = new NamedList<>(); + NamedList document = new SimpleOrderedMap<>(); documents.add(document); Document doc = retrieveDocument(uniqueField, searchGroup.scoreDocs()[i].doc, docFetcher); @@ -284,7 +285,7 @@ protected NamedList serializeTopGroups(TopGroups data, SchemaF } protected NamedList serializeTopDocs(QueryCommandResult result) throws IOException { - NamedList queryResult = new NamedList<>(); + NamedList queryResult = new SimpleOrderedMap<>(); queryResult.add("matches", result.getMatches()); TopDocs topDocs = result.getTopDocs(); assert topDocs.totalHits.relation() == TotalHits.Relation.EQUAL_TO; @@ -301,7 +302,7 @@ protected NamedList serializeTopDocs(QueryCommandResult result) throws I final IndexSchema schema = rb.req.getSearcher().getSchema(); SchemaField uniqueField = schema.getUniqueKeyField(); for (ScoreDoc scoreDoc : result.getTopDocs().scoreDocs) { - NamedList document = new NamedList<>(); + NamedList document = new SimpleOrderedMap<>(); documents.add(document); Document doc = retrieveDocument(uniqueField, scoreDoc.doc, docFetcher); diff --git a/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java b/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java index 76276228a86b..bcc159a07ffa 100644 --- a/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java +++ b/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java @@ -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; @@ -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 results = new NamedList<>(); + NamedList results = new SimpleOrderedMap<>(); try { splitter.split(results); cmd.rsp.addResponse(results); diff --git a/solr/solr-ref-guide/modules/query-guide/pages/morelikethis.adoc b/solr/solr-ref-guide/modules/query-guide/pages/morelikethis.adoc index 767876f1dfec..59ca60b96cb0 100644 --- a/solr/solr-ref-guide/modules/query-guide/pages/morelikethis.adoc +++ b/solr/solr-ref-guide/modules/query-guide/pages/morelikethis.adoc @@ -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. @@ -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", @@ -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", @@ -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", @@ -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 diff --git a/solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-11.adoc b/solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-11.adoc index 184aee185213..d7bccb3a6c94 100644 --- a/solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-11.adoc +++ b/solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-11.adoc @@ -62,3 +62,23 @@ Plugins that use them, for example custom request handlers or update processors, SolrJ clients write request content with `RequestWriter.ContentWriter` instead. The unused `ContentStreamBase.create(RequestWriter, SolrRequest)` and `ContentStreamBase.setSize(Long)` methods have been removed. + +== Response Format + +=== Some response sections are JSON objects regardless of json.nl + +Solr builds many response sections as a `NamedList`, which the JSON response writer renders according to the `json.nl` parameter (by default as a flat array of alternating names and values). +Sections whose names never repeat are now built as a `SimpleOrderedMap` instead, which the JSON writer always renders as a JSON object, exactly as `json.nl=map` did before. +Clients that read these sections with the default `json.nl=flat` (or with `arrarr` / `arrmap`) must now read a JSON object; clients using `json.nl=map` or XML see the same response shape. +SolrJ's javabin decoder now returns `SimpleOrderedMap` instances for these sections instead of plain `NamedList` instances. +Existing casts to `NamedList` remain valid, but code that depends on the concrete type or map behavior must account for the change. +The affected sections are: + +* Core Admin `SPLIT`: the `response` section (`timing`, `failed`) is an object. +* Luke request handler: a field's `histogram` is an object. (`topTerms` is unchanged: its readable keys can repeat for legacy Trie fields.) +* MoreLikeThis handler: `interestingTerms` with `mlt.interestingTerms=details` is an object keyed by term. +* MoreLikeThis component in SolrCloud: `moreLikeThis` is an object keyed by document, as it already was on a single node. +* The `logit` section of the `{!tlogit}` query parser and the `featuredTerms` section of the `{!igain}` query parser are objects. +* A `debug` section on an empty result (`explain` is then empty) is an object, as the normal `debug` section already was. + +Sections designed around repeated or user-controlled keys, such as classic facet counts (`facet_fields`, `facet_ranges`, `facet_pivot`), the terms component, spellcheck suggestions and collations, term vectors and `sort_values`, are unchanged and still follow `json.nl`. diff --git a/solr/webapp/web/js/angular/controllers/schema.js b/solr/webapp/web/js/angular/controllers/schema.js index 0e1741bab2be..5b2419aa4401 100644 --- a/solr/webapp/web/js/angular/controllers/schema.js +++ b/solr/webapp/web/js/angular/controllers/schema.js @@ -707,30 +707,52 @@ var getTermInfo = function(data) { if (data && data.topTerms) { termInfo.topTerms = []; - var currentGroup = {count: 0} - for (var i = 0; i < data.topTerms.length; i += 2) { - var count = data.topTerms[i + 1]; + var currentGroup = {count: 0}; + var topTerms = namedListEntries(data.topTerms) + .map(function(entry, index) { return {key: entry.key, value: entry.value, index: index}; }) + .sort(function(a, b) { return b.value - a.value || a.index - b.index; }); + for (var i = 0; i < topTerms.length; i++) { + var count = topTerms[i].value; if (currentGroup.count != count) { currentGroup = {count: count, terms: []}; termInfo.topTerms.push(currentGroup); } - currentGroup.terms.push(data.topTerms[i]); + currentGroup.terms.push(topTerms[i].key); } - termInfo.termCount = data.topTerms.length / 2; + termInfo.termCount = topTerms.length; termInfo.maxTerms = data.distinct; } - if(data && data.histogram) { - termInfo.histogram = []; + if (data && data.histogram) { + termInfo.histogram = namedListEntries(data.histogram); termInfo.histogramMax = 0; - for (var i = 0; i < data.histogram.length; i += 2) { - termInfo.histogram.push({key: data.histogram[i], value: data.histogram[i + 1]}); - termInfo.histogramMax = Math.max(termInfo.histogramMax, data.histogram[i + 1]); + for (var j = 0; j < termInfo.histogram.length; j++) { + termInfo.histogramMax = Math.max(termInfo.histogramMax, termInfo.histogram[j].value); } } return termInfo; }; +/** + * Luke renders topTerms and histogram as JSON objects since Solr 11; older servers rendered them + * as a flat [name, value, name, value, ...] array under the default json.nl. Accept both. + */ +var namedListEntries = function(namedList) { + var entries = []; + if (Array.isArray(namedList)) { + for (var i = 0; i < namedList.length; i += 2) { + entries.push({key: namedList[i], value: namedList[i + 1]}); + } + } else if (namedList) { + for (var key in namedList) { + if (Object.prototype.hasOwnProperty.call(namedList, key)) { + entries.push({key: key, value: namedList[key]}); + } + } + } + return entries; +}; + var getFieldTypeManipulationOptions = function() { return [ {