diff --git a/solr/core/src/java/org/apache/solr/request/SimpleFacets.java b/solr/core/src/java/org/apache/solr/request/SimpleFacets.java index bc8c5e73080..03b09a5b180 100644 --- a/solr/core/src/java/org/apache/solr/request/SimpleFacets.java +++ b/solr/core/src/java/org/apache/solr/request/SimpleFacets.java @@ -871,12 +871,12 @@ public void execute(Runnable r) { * @see #getFieldMissingCount * @see #getFacetTermEnumCounts */ - public NamedList getFacetFieldCounts() throws IOException, SyntaxError { + public SimpleOrderedMap getFacetFieldCounts() throws IOException, SyntaxError { - NamedList res = new SimpleOrderedMap<>(); String[] facetFs = global.getParams(FacetParams.FACET_FIELD); + if (null == facetFs) { - return res; + return SimpleOrderedMap.of(); } // Passing a negative number for FACET_THREADS implies an unlimited number of threads is @@ -891,6 +891,7 @@ public NamedList getFacetFieldCounts() throws IOException, SyntaxError { fdebugParent.putInfoItem("maxThreads", maxThreads); } + SimpleOrderedMap res; try { // Loop over fields; submit to executor, keeping the future for (String f : facetFs) { @@ -914,10 +915,8 @@ public NamedList getFacetFieldCounts() throws IOException, SyntaxError { result.add(key, getTermCounts(facetValue, parsed)); } return result; - } catch (SolrException se) { + } catch (SolrException | ExitableDirectoryReader.ExitingReaderException se) { throw se; - } catch (ExitableDirectoryReader.ExitingReaderException timeout) { - throw timeout; } catch (Exception e) { throw new SolrException( ErrorCode.SERVER_ERROR, "Exception during facet.field: " + facetValue, e); @@ -932,6 +931,7 @@ public NamedList getFacetFieldCounts() throws IOException, SyntaxError { futures.add(runnableFuture); } // facetFs loop + res = new SimpleOrderedMap<>(); // Loop over futures to get the values. The order is the same as facetFs but shouldn't matter. for (Future> future : futures) { res.addAll(future.get()); diff --git a/solr/solrj/src/java/org/apache/solr/common/util/SimpleOrderedMap.java b/solr/solrj/src/java/org/apache/solr/common/util/SimpleOrderedMap.java index 6e6dd15438a..cd4eb3951fd 100644 --- a/solr/solrj/src/java/org/apache/solr/common/util/SimpleOrderedMap.java +++ b/solr/solrj/src/java/org/apache/solr/common/util/SimpleOrderedMap.java @@ -34,6 +34,8 @@ * serialized. It aims to minimize overhead and to be efficient at adding new elements. */ public class SimpleOrderedMap extends NamedList { + + private static final SimpleOrderedMap EMPTY = new SimpleOrderedMap<>(List.of()); /** Creates an empty instance */ public SimpleOrderedMap() { super(); @@ -67,4 +69,23 @@ public SimpleOrderedMap clone() { newList.addAll(nvPairs); return new SimpleOrderedMap<>(newList); } + + /** + * Returns a shared, empty, and immutable instance of SimpleOrderedMap. + * @return Empty SimpleOrderedMap (immutable) + */ + public static SimpleOrderedMap of() { + return EMPTY; + } + + /** + * Returns an immutable instance of SimpleOrderedMap with a single key-value pair. + * @return SimpleOrderedMap containing one key-value pair + */ + + public static SimpleOrderedMap of(String name, T val) + { + return new SimpleOrderedMap<>(List.of(name, val)); + } + }