Apache Lucene open-source search software
LUCENE-5304: SingletonSortedSetDocValues can now return the wrapped SortedDocValues
Adrien Grandd49ba41f5415
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 133c2ce12ca..e1800d23443 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -120,6 +120,9 @@ New Features* LUCENE-5274: FastVectorHighlighter now supports highlighting against severalindexed fields. (Nik Everett via Adrien Grand)+* LUCENE-5304: SingletonSortedSetDocValues can now return the wrapped+ SortedDocValues (Robert Muir, Adrien Grand)+Bug Fixes* LUCENE-4998: Fixed a few places to pass IOContext.READONCE insteaddiff --git a/lucene/core/src/java/org/apache/lucene/index/SingletonSortedSetDocValues.java b/lucene/core/src/java/org/apache/lucene/index/SingletonSortedSetDocValues.javaindex d44bb817c7b..061b9bbcc9d 100644--- a/lucene/core/src/java/org/apache/lucene/index/SingletonSortedSetDocValues.java+++ b/lucene/core/src/java/org/apache/lucene/index/SingletonSortedSetDocValues.java@@ -37,6 +37,11 @@ public class SingletonSortedSetDocValues extends SortedSetDocValues {assert NO_MORE_ORDS == -1; // this allows our nextOrd() to work for missing values without a check}+ /** Return the wrapped {@link SortedDocValues} */+ public SortedDocValues getSortedDocValues() {+ return in;+ }+@Overridepublic long nextOrd() {if (set) {diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 8195e2ca6f7..f6b1d9f06a1 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -141,6 +141,9 @@ Optimizations* SOLR-5370: Requests to recover when an update fails should be done inbackground threads. (Mark Miller)++* LUCENE-5300,LUCENE-5304: Specialized faceting for fields which are declared as+ multi-valued in the schema but are actually single-valued. (Adrien Grand)Security----------------------diff --git a/solr/core/src/java/org/apache/solr/request/DocValuesFacets.java b/solr/core/src/java/org/apache/solr/request/DocValuesFacets.javaindex fb424fdee8b..98a2140759c 100644--- a/solr/core/src/java/org/apache/solr/request/DocValuesFacets.java+++ b/solr/core/src/java/org/apache/solr/request/DocValuesFacets.java@@ -131,7 +131,13 @@ public class DocValuesFacets {if (sub == null) {sub = SortedSetDocValues.EMPTY;}- accumMulti(counts, startTermIndex, sub, disi, subIndex, ordinalMap);+ if (sub instanceof SingletonSortedSetDocValues) {+ // some codecs may optimize SORTED_SET storage for single-valued fields+ final SortedDocValues values = ((SingletonSortedSetDocValues) sub).getSortedDocValues();+ accumSingle(counts, startTermIndex, values, disi, subIndex, ordinalMap);+ } else {+ accumMulti(counts, startTermIndex, sub, disi, subIndex, ordinalMap);+ }} else {SortedDocValues sub = leaf.reader().getSortedDocValues(fieldName);if (sub == null) {diff --git a/solr/core/src/test/org/apache/solr/TestRandomDVFaceting.java b/solr/core/src/test/org/apache/solr/TestRandomDVFaceting.javaindex b6581af49bf..19d945b0d4f 100644--- a/solr/core/src/test/org/apache/solr/TestRandomDVFaceting.java+++ b/solr/core/src/test/org/apache/solr/TestRandomDVFaceting.java@@ -66,6 +66,7 @@ public class TestRandomDVFaceting extends SolrTestCaseJ4 {types.add(new FldType("small2_s",ZERO_ONE, new SVal('a',(char)('c'+indexSize/3),1,1)));types.add(new FldType("small2_ss",ZERO_TWO, new SVal('a',(char)('c'+indexSize/3),1,1)));types.add(new FldType("small3_ss",new IRange(0,25), new SVal('A','z',1,1)));+ types.add(new FldType("small4_ss",ZERO_ONE, new SVal('a',(char)('c'+indexSize/3),1,1))); // to test specialization when a multi-valued field is actually single-valuedtypes.add(new FldType("small_i",ZERO_ONE, new IRange(0,5+indexSize/3)));types.add(new FldType("small2_i",ZERO_ONE, new IRange(0,5+indexSize/3)));types.add(new FldType("small2_is",ZERO_TWO, new IRange(0,5+indexSize/3)));