From 65ce3aea57dfbbaed5e595134420e923f3998c19 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Fri, 26 Oct 2012 12:52:37 +0200 Subject: [PATCH] lucene 4: Upgraded the function/sort classes. --- .../DoubleFieldsFunctionDataComparator.java | 22 +++++++++++++------ .../StringFieldsFunctionDataComparator.java | 20 ++++++++++++----- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/elasticsearch/index/field/function/sort/DoubleFieldsFunctionDataComparator.java b/src/main/java/org/elasticsearch/index/field/function/sort/DoubleFieldsFunctionDataComparator.java index 6a567f9ab3b..d3aded6b2fa 100644 --- a/src/main/java/org/elasticsearch/index/field/function/sort/DoubleFieldsFunctionDataComparator.java +++ b/src/main/java/org/elasticsearch/index/field/function/sort/DoubleFieldsFunctionDataComparator.java @@ -19,7 +19,7 @@ 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.Scorer; import org.apache.lucene.search.SortField; @@ -32,7 +32,7 @@ import java.io.IOException; * */ // LUCENE MONITOR: Monitor against FieldComparator.Double -public class DoubleFieldsFunctionDataComparator extends FieldComparator { +public class DoubleFieldsFunctionDataComparator extends FieldComparator { public static FieldDataType.ExtendedFieldComparatorSource comparatorSource(SearchScript script) { return new InnerSource(script); @@ -53,7 +53,7 @@ public class DoubleFieldsFunctionDataComparator extends FieldComparator { @Override public SortField.Type reducedType() { - return SortField.DOUBLE; + return SortField.Type.DOUBLE; } } @@ -68,8 +68,9 @@ public class DoubleFieldsFunctionDataComparator extends FieldComparator { } @Override - public void setNextReader(IndexReader reader, int docBase) throws IOException { - script.setNextReader(reader); + public FieldComparator setNextReader(AtomicReaderContext context) throws IOException { + script.setNextReader(context.reader()); + return this; } @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 public void copy(int slot, int doc) { script.setNextDocId(doc); @@ -115,7 +123,7 @@ public class DoubleFieldsFunctionDataComparator extends FieldComparator { } @Override - public Comparable value(int slot) { - return Double.valueOf(values[slot]); + public Double value(int slot) { + return values[slot]; } } diff --git a/src/main/java/org/elasticsearch/index/field/function/sort/StringFieldsFunctionDataComparator.java b/src/main/java/org/elasticsearch/index/field/function/sort/StringFieldsFunctionDataComparator.java index ddf9eb81c25..20c8534910c 100644 --- a/src/main/java/org/elasticsearch/index/field/function/sort/StringFieldsFunctionDataComparator.java +++ b/src/main/java/org/elasticsearch/index/field/function/sort/StringFieldsFunctionDataComparator.java @@ -19,7 +19,7 @@ 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.Scorer; import org.apache.lucene.search.SortField; @@ -31,7 +31,7 @@ import java.io.IOException; /** * */ -public class StringFieldsFunctionDataComparator extends FieldComparator { +public class StringFieldsFunctionDataComparator extends FieldComparator { public static FieldDataType.ExtendedFieldComparatorSource comparatorSource(SearchScript script) { return new InnerSource(script); @@ -52,7 +52,7 @@ public class StringFieldsFunctionDataComparator extends FieldComparator { @Override public SortField.Type reducedType() { - return SortField.STRING; + return SortField.Type.STRING; } } @@ -68,8 +68,9 @@ public class StringFieldsFunctionDataComparator extends FieldComparator { } @Override - public void setNextReader(IndexReader reader, int docBase) throws IOException { - script.setNextReader(reader); + public FieldComparator setNextReader(AtomicReaderContext context) throws IOException { + script.setNextReader(context.reader()); + return this; } @Override @@ -108,6 +109,13 @@ public class StringFieldsFunctionDataComparator extends FieldComparator { 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 public void copy(int slot, int doc) { script.setNextDocId(doc); @@ -120,7 +128,7 @@ public class StringFieldsFunctionDataComparator extends FieldComparator { } @Override - public Comparable value(int slot) { + public String value(int slot) { return values[slot]; } }