From 451cc4079b3cd08a4b6ff01d19ee3163f5922c9f Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Sun, 5 Jun 2011 14:41:17 +0000 Subject: [PATCH] LUCENE-3108: Removed missing value from FieldComparator and added PerDoc impl to ParallelReader git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/docvalues@1132424 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/lucene/index/ParallelReader.java | 33 +++++++++++++++++-- .../apache/lucene/search/FieldComparator.java | 8 ++--- .../org/apache/lucene/search/SortField.java | 4 +-- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/lucene/src/java/org/apache/lucene/index/ParallelReader.java b/lucene/src/java/org/apache/lucene/index/ParallelReader.java index 4b5d78d5682..d587b4a7b51 100644 --- a/lucene/src/java/org/apache/lucene/index/ParallelReader.java +++ b/lucene/src/java/org/apache/lucene/index/ParallelReader.java @@ -22,6 +22,7 @@ import org.apache.lucene.document.FieldSelector; import org.apache.lucene.document.FieldSelectorResult; import org.apache.lucene.document.Fieldable; import org.apache.lucene.index.codecs.PerDocValues; +import org.apache.lucene.index.values.IndexDocValues; import org.apache.lucene.util.Bits; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.MapBackedSet; @@ -61,7 +62,8 @@ public class ParallelReader extends IndexReader { private int numDocs; private boolean hasDeletions; - private ParallelFields fields = new ParallelFields(); + private final ParallelFields fields = new ParallelFields(); + private final ParallelPerDocs perDocs = new ParallelPerDocs(); /** Construct a ParallelReader. *

Note that all subreaders are closed if this ParallelReader is closed.

@@ -135,6 +137,7 @@ public class ParallelReader extends IndexReader { fieldToReader.put(field, reader); } this.fields.addField(field, reader); + this.perDocs.addField(field, reader); } if (!ignoreStoredFields) @@ -569,8 +572,32 @@ public class ParallelReader extends IndexReader { @Override public PerDocValues perDocValues() throws IOException { - // TODO Auto-generated method stub - return null; + return perDocs; + } + + // Single instance of this, per ParallelReader instance + private static final class ParallelPerDocs extends PerDocValues { + final TreeMap fields = new TreeMap(); + + void addField(String field, IndexReader r) throws IOException { + PerDocValues perDocs = MultiPerDocValues.getPerDocs(r); + fields.put(field, perDocs.docValues(field)); + } + + @Override + public void close() throws IOException { + // nothing to do here + } + + @Override + public IndexDocValues docValues(String field) throws IOException { + return fields.get(field); + } + + @Override + public Collection fields() { + return fields.keySet(); + } } } diff --git a/lucene/src/java/org/apache/lucene/search/FieldComparator.java b/lucene/src/java/org/apache/lucene/search/FieldComparator.java index 7ab0d4cd6c4..d7565317abe 100644 --- a/lucene/src/java/org/apache/lucene/search/FieldComparator.java +++ b/lucene/src/java/org/apache/lucene/search/FieldComparator.java @@ -335,12 +335,10 @@ public abstract class FieldComparator { private Source currentReaderValues; private final String field; private double bottom; - private final float missingValue; - FloatDocValuesComparator(int numHits, String field, Float missingValue) { + FloatDocValuesComparator(int numHits, String field) { values = new double[numHits]; this.field = field; - this.missingValue = missingValue == null ? 0 : missingValue.floatValue(); } @Override @@ -607,12 +605,10 @@ public abstract class FieldComparator { private Source currentReaderValues; private final String field; private long bottom; - private int missingValue; - IntDocValuesComparator(int numHits, String field, Integer missingValue) { + IntDocValuesComparator(int numHits, String field) { values = new long[numHits]; this.field = field; - this.missingValue = missingValue == null ? 0 : missingValue.intValue(); } @Override diff --git a/lucene/src/java/org/apache/lucene/search/SortField.java b/lucene/src/java/org/apache/lucene/search/SortField.java index 55e8425d600..8fdc66c36e8 100644 --- a/lucene/src/java/org/apache/lucene/search/SortField.java +++ b/lucene/src/java/org/apache/lucene/search/SortField.java @@ -442,14 +442,14 @@ public class SortField { case SortField.INT: if (useIndexValues) { - return new FieldComparator.IntDocValuesComparator(numHits, field, (Integer) missingValue); + return new FieldComparator.IntDocValuesComparator(numHits, field); } else { return new FieldComparator.IntComparator(numHits, (IntValuesCreator)creator, (Integer) missingValue); } case SortField.FLOAT: if (useIndexValues) { - return new FieldComparator.FloatDocValuesComparator(numHits, field, (Float) missingValue); + return new FieldComparator.FloatDocValuesComparator(numHits, field); } else { return new FieldComparator.FloatComparator(numHits, (FloatValuesCreator) creator, (Float) missingValue); }