From a415009d08de3a3d0947cf479893ae08b825d924 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Sat, 15 Jun 2013 15:38:15 +0000 Subject: [PATCH 1/2] fix NPE on empty index git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1493381 13f79535-47bb-0310-9956-ffa450edef68 --- .../lucene/facet/search/DrillSidewaysQuery.java | 4 ++-- .../lucene/facet/search/DrillSidewaysScorer.java | 16 ++++++---------- .../lucene/facet/search/TestDrillSideways.java | 1 - 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/lucene/facet/src/java/org/apache/lucene/facet/search/DrillSidewaysQuery.java b/lucene/facet/src/java/org/apache/lucene/facet/search/DrillSidewaysQuery.java index afa0906808c..cbc74a22f35 100644 --- a/lucene/facet/src/java/org/apache/lucene/facet/search/DrillSidewaysQuery.java +++ b/lucene/facet/src/java/org/apache/lucene/facet/search/DrillSidewaysQuery.java @@ -122,11 +122,11 @@ class DrillSidewaysQuery extends Query { } lastField = field; } + dims[dim].docsEnums = new DocsEnum[drillDownTerms[dim].length]; if (termsEnum == null) { nullCount++; continue; } - dims[dim].docsEnums = new DocsEnum[drillDownTerms[dim].length]; for(int i=0;i 1) { + if (nullCount > 1 || (nullCount == 1 && dims.length == 1)) { return null; } diff --git a/lucene/facet/src/java/org/apache/lucene/facet/search/DrillSidewaysScorer.java b/lucene/facet/src/java/org/apache/lucene/facet/search/DrillSidewaysScorer.java index c3f2eecd2ed..42f53905935 100644 --- a/lucene/facet/src/java/org/apache/lucene/facet/search/DrillSidewaysScorer.java +++ b/lucene/facet/src/java/org/apache/lucene/facet/search/DrillSidewaysScorer.java @@ -80,11 +80,9 @@ class DrillSidewaysScorer extends Scorer { // Position all scorers to their first matching doc: baseScorer.nextDoc(); for(DocsEnumsAndFreq dim : dims) { - if (dim.docsEnums != null) { - for (DocsEnum docsEnum : dim.docsEnums) { - if (docsEnum != null) { - docsEnum.nextDoc(); - } + for (DocsEnum docsEnum : dim.docsEnums) { + if (docsEnum != null) { + docsEnum.nextDoc(); } } } @@ -97,11 +95,9 @@ class DrillSidewaysScorer extends Scorer { for(int dim=0;dim Date: Sat, 15 Jun 2013 16:21:35 +0000 Subject: [PATCH 2/2] fix test failure git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1493391 13f79535-47bb-0310-9956-ffa450edef68 --- .../lucene/facet/search/TestDrillSideways.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lucene/facet/src/test/org/apache/lucene/facet/search/TestDrillSideways.java b/lucene/facet/src/test/org/apache/lucene/facet/search/TestDrillSideways.java index 4e3e1bccde3..9772f90d44d 100644 --- a/lucene/facet/src/test/org/apache/lucene/facet/search/TestDrillSideways.java +++ b/lucene/facet/src/test/org/apache/lucene/facet/search/TestDrillSideways.java @@ -28,11 +28,15 @@ import java.util.Map; import java.util.Set; import org.apache.lucene.analysis.MockAnalyzer; +import org.apache.lucene.codecs.Codec; +import org.apache.lucene.codecs.DocValuesFormat; +import org.apache.lucene.codecs.perfield.PerFieldDocValuesFormat; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.StringField; import org.apache.lucene.facet.FacetTestCase; import org.apache.lucene.facet.FacetTestUtils; +import org.apache.lucene.facet.codecs.facet42.Facet42DocValuesFormat; import org.apache.lucene.facet.index.FacetFields; import org.apache.lucene.facet.params.FacetIndexingParams; import org.apache.lucene.facet.params.FacetSearchParams; @@ -58,8 +62,8 @@ import org.apache.lucene.search.Query; import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.Scorer; import org.apache.lucene.search.Sort; -import org.apache.lucene.search.SortField; import org.apache.lucene.search.SortField.Type; +import org.apache.lucene.search.SortField; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.TopDocs; import org.apache.lucene.store.Directory; @@ -429,6 +433,16 @@ public class TestDrillSideways extends FacetTestCase { boolean canUseDV = defaultCodecSupportsSortedSet(); + // TestRuleSetupAndRestoreClassEnv can sometimes + // randomly pick the non-general Facet42DocValuesFormat: + DocValuesFormat dvf = Codec.getDefault().docValuesFormat(); + if (dvf instanceof PerFieldDocValuesFormat) { + dvf = ((PerFieldDocValuesFormat) dvf).getDocValuesFormatForField("$facets"); + } + if (dvf instanceof Facet42DocValuesFormat) { + canUseDV = false; + } + while (aChance == 0.0) { aChance = random().nextDouble(); }