mirror of https://github.com/apache/lucene.git
LUCENE-2504: always access the latest generation of field comparators
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@997095 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c18ae60c8c
commit
0e9e44f10d
|
@ -52,8 +52,6 @@ public abstract class FieldValueHitQueue extends PriorityQueue<FieldValueHitQueu
|
||||||
* there is just one comparator.
|
* there is just one comparator.
|
||||||
*/
|
*/
|
||||||
private static final class OneComparatorFieldValueHitQueue extends FieldValueHitQueue {
|
private static final class OneComparatorFieldValueHitQueue extends FieldValueHitQueue {
|
||||||
|
|
||||||
private final FieldComparator comparator;
|
|
||||||
private final int oneReverseMul;
|
private final int oneReverseMul;
|
||||||
|
|
||||||
public OneComparatorFieldValueHitQueue(SortField[] fields, int size)
|
public OneComparatorFieldValueHitQueue(SortField[] fields, int size)
|
||||||
|
@ -64,10 +62,9 @@ public abstract class FieldValueHitQueue extends PriorityQueue<FieldValueHitQueu
|
||||||
}
|
}
|
||||||
|
|
||||||
SortField field = fields[0];
|
SortField field = fields[0];
|
||||||
comparator = field.getComparator(size, 0);
|
setComparator(0,field.getComparator(size, 0));
|
||||||
oneReverseMul = field.reverse ? -1 : 1;
|
oneReverseMul = field.reverse ? -1 : 1;
|
||||||
|
|
||||||
comparators[0] = comparator;
|
|
||||||
reverseMul[0] = oneReverseMul;
|
reverseMul[0] = oneReverseMul;
|
||||||
|
|
||||||
initialize(size);
|
initialize(size);
|
||||||
|
@ -85,7 +82,7 @@ public abstract class FieldValueHitQueue extends PriorityQueue<FieldValueHitQueu
|
||||||
assert hitA != hitB;
|
assert hitA != hitB;
|
||||||
assert hitA.slot != hitB.slot;
|
assert hitA.slot != hitB.slot;
|
||||||
|
|
||||||
final int c = oneReverseMul * comparator.compare(hitA.slot, hitB.slot);
|
final int c = oneReverseMul * firstComparator.compare(hitA.slot, hitB.slot);
|
||||||
if (c != 0) {
|
if (c != 0) {
|
||||||
return c > 0;
|
return c > 0;
|
||||||
}
|
}
|
||||||
|
@ -111,7 +108,7 @@ public abstract class FieldValueHitQueue extends PriorityQueue<FieldValueHitQueu
|
||||||
SortField field = fields[i];
|
SortField field = fields[i];
|
||||||
|
|
||||||
reverseMul[i] = field.reverse ? -1 : 1;
|
reverseMul[i] = field.reverse ? -1 : 1;
|
||||||
comparators[i] = field.getComparator(size, i);
|
setComparator(i, field.getComparator(size, i));
|
||||||
}
|
}
|
||||||
|
|
||||||
initialize(size);
|
initialize(size);
|
||||||
|
@ -182,9 +179,15 @@ public abstract class FieldValueHitQueue extends PriorityQueue<FieldValueHitQueu
|
||||||
|
|
||||||
int[] getReverseMul() { return reverseMul; }
|
int[] getReverseMul() { return reverseMul; }
|
||||||
|
|
||||||
|
protected void setComparator(int pos, FieldComparator comparator) {
|
||||||
|
if (pos==0) firstComparator = comparator;
|
||||||
|
comparators[pos] = comparator;
|
||||||
|
}
|
||||||
|
|
||||||
/** Stores the sort criteria being used. */
|
/** Stores the sort criteria being used. */
|
||||||
protected final SortField[] fields;
|
protected final SortField[] fields;
|
||||||
protected final FieldComparator[] comparators;
|
protected final FieldComparator[] comparators; // use setComparator to change this array
|
||||||
|
protected FieldComparator firstComparator; // this must always be equal to comparators[0]
|
||||||
protected final int[] reverseMul;
|
protected final int[] reverseMul;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -48,10 +48,12 @@ public abstract class TopFieldCollector extends TopDocsCollector<Entry> {
|
||||||
|
|
||||||
FieldComparator comparator;
|
FieldComparator comparator;
|
||||||
final int reverseMul;
|
final int reverseMul;
|
||||||
|
final FieldValueHitQueue queue;
|
||||||
|
|
||||||
public OneComparatorNonScoringCollector(FieldValueHitQueue queue,
|
public OneComparatorNonScoringCollector(FieldValueHitQueue queue,
|
||||||
int numHits, boolean fillFields) throws IOException {
|
int numHits, boolean fillFields) throws IOException {
|
||||||
super(queue, numHits, fillFields);
|
super(queue, numHits, fillFields);
|
||||||
|
this.queue = queue;
|
||||||
comparator = queue.getComparators()[0];
|
comparator = queue.getComparators()[0];
|
||||||
reverseMul = queue.getReverseMul()[0];
|
reverseMul = queue.getReverseMul()[0];
|
||||||
}
|
}
|
||||||
|
@ -92,7 +94,8 @@ public abstract class TopFieldCollector extends TopDocsCollector<Entry> {
|
||||||
@Override
|
@Override
|
||||||
public void setNextReader(IndexReader reader, int docBase) throws IOException {
|
public void setNextReader(IndexReader reader, int docBase) throws IOException {
|
||||||
this.docBase = docBase;
|
this.docBase = docBase;
|
||||||
comparator = comparator.setNextReader(reader, docBase);
|
queue.setComparator(0, comparator.setNextReader(reader, docBase));
|
||||||
|
comparator = queue.firstComparator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -381,10 +384,11 @@ public abstract class TopFieldCollector extends TopDocsCollector<Entry> {
|
||||||
|
|
||||||
final FieldComparator[] comparators;
|
final FieldComparator[] comparators;
|
||||||
final int[] reverseMul;
|
final int[] reverseMul;
|
||||||
|
final FieldValueHitQueue queue;
|
||||||
public MultiComparatorNonScoringCollector(FieldValueHitQueue queue,
|
public MultiComparatorNonScoringCollector(FieldValueHitQueue queue,
|
||||||
int numHits, boolean fillFields) throws IOException {
|
int numHits, boolean fillFields) throws IOException {
|
||||||
super(queue, numHits, fillFields);
|
super(queue, numHits, fillFields);
|
||||||
|
this.queue = queue;
|
||||||
comparators = queue.getComparators();
|
comparators = queue.getComparators();
|
||||||
reverseMul = queue.getReverseMul();
|
reverseMul = queue.getReverseMul();
|
||||||
}
|
}
|
||||||
|
@ -446,7 +450,7 @@ public abstract class TopFieldCollector extends TopDocsCollector<Entry> {
|
||||||
public void setNextReader(IndexReader reader, int docBase) throws IOException {
|
public void setNextReader(IndexReader reader, int docBase) throws IOException {
|
||||||
this.docBase = docBase;
|
this.docBase = docBase;
|
||||||
for (int i = 0; i < comparators.length; i++) {
|
for (int i = 0; i < comparators.length; i++) {
|
||||||
comparators[i] = comparators[i].setNextReader(reader, docBase);
|
queue.setComparator(i, comparators[i].setNextReader(reader, docBase));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue