lucene 4: Upgraded the function/sort classes.

This commit is contained in:
Martijn van Groningen 2012-10-26 12:52:37 +02:00 committed by Shay Banon
parent 48b8d0544f
commit 65ce3aea57
2 changed files with 29 additions and 13 deletions

View File

@ -19,7 +19,7 @@
package org.elasticsearch.index.field.function.sort; package org.elasticsearch.index.field.function.sort;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.search.FieldComparator; import org.apache.lucene.search.FieldComparator;
import org.apache.lucene.search.Scorer; import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.SortField; import org.apache.lucene.search.SortField;
@ -32,7 +32,7 @@ import java.io.IOException;
* *
*/ */
// LUCENE MONITOR: Monitor against FieldComparator.Double // LUCENE MONITOR: Monitor against FieldComparator.Double
public class DoubleFieldsFunctionDataComparator extends FieldComparator { public class DoubleFieldsFunctionDataComparator extends FieldComparator<Double> {
public static FieldDataType.ExtendedFieldComparatorSource comparatorSource(SearchScript script) { public static FieldDataType.ExtendedFieldComparatorSource comparatorSource(SearchScript script) {
return new InnerSource(script); return new InnerSource(script);
@ -53,7 +53,7 @@ public class DoubleFieldsFunctionDataComparator extends FieldComparator {
@Override @Override
public SortField.Type reducedType() { public SortField.Type reducedType() {
return SortField.DOUBLE; return SortField.Type.DOUBLE;
} }
} }
@ -68,8 +68,9 @@ public class DoubleFieldsFunctionDataComparator extends FieldComparator {
} }
@Override @Override
public void setNextReader(IndexReader reader, int docBase) throws IOException { public FieldComparator<Double> setNextReader(AtomicReaderContext context) throws IOException {
script.setNextReader(reader); script.setNextReader(context.reader());
return this;
} }
@Override @Override
@ -103,6 +104,13 @@ public class DoubleFieldsFunctionDataComparator extends FieldComparator {
} }
} }
@Override
public int compareDocToValue(int doc, Double val2) throws IOException {
script.setNextDocId(doc);
double val1 = script.runAsDouble();
return Double.compare(val1, val2);
}
@Override @Override
public void copy(int slot, int doc) { public void copy(int slot, int doc) {
script.setNextDocId(doc); script.setNextDocId(doc);
@ -115,7 +123,7 @@ public class DoubleFieldsFunctionDataComparator extends FieldComparator {
} }
@Override @Override
public Comparable value(int slot) { public Double value(int slot) {
return Double.valueOf(values[slot]); return values[slot];
} }
} }

View File

@ -19,7 +19,7 @@
package org.elasticsearch.index.field.function.sort; package org.elasticsearch.index.field.function.sort;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.search.FieldComparator; import org.apache.lucene.search.FieldComparator;
import org.apache.lucene.search.Scorer; import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.SortField; import org.apache.lucene.search.SortField;
@ -31,7 +31,7 @@ import java.io.IOException;
/** /**
* *
*/ */
public class StringFieldsFunctionDataComparator extends FieldComparator { public class StringFieldsFunctionDataComparator extends FieldComparator<String> {
public static FieldDataType.ExtendedFieldComparatorSource comparatorSource(SearchScript script) { public static FieldDataType.ExtendedFieldComparatorSource comparatorSource(SearchScript script) {
return new InnerSource(script); return new InnerSource(script);
@ -52,7 +52,7 @@ public class StringFieldsFunctionDataComparator extends FieldComparator {
@Override @Override
public SortField.Type reducedType() { public SortField.Type reducedType() {
return SortField.STRING; return SortField.Type.STRING;
} }
} }
@ -68,8 +68,9 @@ public class StringFieldsFunctionDataComparator extends FieldComparator {
} }
@Override @Override
public void setNextReader(IndexReader reader, int docBase) throws IOException { public FieldComparator<String> setNextReader(AtomicReaderContext context) throws IOException {
script.setNextReader(reader); script.setNextReader(context.reader());
return this;
} }
@Override @Override
@ -108,6 +109,13 @@ public class StringFieldsFunctionDataComparator extends FieldComparator {
return bottom.compareTo(val2); return bottom.compareTo(val2);
} }
@Override
public int compareDocToValue(int doc, String val2) throws IOException {
script.setNextDocId(doc);
String val1 = script.run().toString();
return val1.compareTo(val2);
}
@Override @Override
public void copy(int slot, int doc) { public void copy(int slot, int doc) {
script.setNextDocId(doc); script.setNextDocId(doc);
@ -120,7 +128,7 @@ public class StringFieldsFunctionDataComparator extends FieldComparator {
} }
@Override @Override
public Comparable value(int slot) { public String value(int slot) {
return values[slot]; return values[slot];
} }
} }