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
This commit is contained in:
Simon Willnauer 2011-06-05 14:41:17 +00:00
parent f4da02857f
commit 451cc4079b
3 changed files with 34 additions and 11 deletions

View File

@ -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.
* <p>Note that all subreaders are closed if this ParallelReader is closed.</p>
@ -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<String,IndexDocValues> fields = new TreeMap<String,IndexDocValues>();
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<String> fields() {
return fields.keySet();
}
}
}

View File

@ -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

View File

@ -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);
}