SOLR-2469: remove saveCommitPoint for replicate on startup

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1092812 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2011-04-15 21:13:42 +00:00
parent 3db2d87b9f
commit 0742b30b72
47 changed files with 721 additions and 693 deletions

View File

@ -843,9 +843,13 @@ public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAw
indexCommitPoint = reader.getIndexCommit();
}
} finally {
// We don't need to save commit points for replication, the SolrDeletionPolicy
// always saves the last commit point (and the last optimized commit point, if needed)
/***
if(indexCommitPoint != null){
core.getDeletionPolicy().saveCommitPoint(indexCommitPoint.getVersion());
}
***/
}
}
if (core.getUpdateHandler() instanceof DirectUpdateHandler2) {

View File

@ -90,9 +90,10 @@ public class ValueSourceAugmenter extends DocTransformer
}
int localId = docid - rcontext.docBase;
float val = values.floatVal(localId); // TODO: handle all types -- see: SOLR-2443
doc.setField( name, val );
Object val = values.objectVal(localId);
if (val != null) {
doc.setField( name, val );
}
} catch (IOException e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "exception at docid " + docid + " for valuesource " + valueSource, e, false);
}

View File

@ -486,6 +486,17 @@ class DateFieldSource extends FieldCacheSource {
}
}
@Override
public Object objectVal(int doc) {
int ord=termsIndex.getOrd(doc);
if (ord == 0) {
return null;
} else {
BytesRef br = termsIndex.lookup(ord, new BytesRef());
return ft.toObject(null, br);
}
}
@Override
public String toString(int doc) {
return description() + '=' + intVal(doc);

View File

@ -28,6 +28,7 @@ import org.apache.lucene.util.ReaderUtil;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.search.QParser;
import org.apache.solr.search.function.DocValues;
import org.apache.solr.search.function.IntDocValues;
import org.apache.solr.search.function.ValueSource;
/**
@ -157,37 +158,12 @@ public class RandomSortField extends FieldType {
@Override
public DocValues getValues(Map context, final AtomicReaderContext readerContext) throws IOException {
return new DocValues() {
return new IntDocValues(this) {
private final int seed = getSeed(field, readerContext);
@Override
public float floatVal(int doc) {
return (float)hash(doc+seed);
}
@Override
public int intVal(int doc) {
return hash(doc+seed);
}
@Override
public long longVal(int doc) {
return (long)hash(doc+seed);
}
@Override
public double doubleVal(int doc) {
return (double)hash(doc+seed);
}
@Override
public String strVal(int doc) {
return Integer.toString(hash(doc+seed));
}
@Override
public String toString(int doc) {
return description() + '=' + intVal(doc);
}
};
}

View File

@ -148,6 +148,12 @@ class SortableDoubleFieldSource extends FieldCacheSource {
return Double.toString(doubleVal(doc));
}
@Override
public Object objectVal(int doc) {
int ord=termsIndex.getOrd(doc);
return ord==0 ? null : NumberUtils.SortableStr2double(termsIndex.lookup(ord, spare));
}
@Override
public String toString(int doc) {
return description() + '=' + doubleVal(doc);

View File

@ -153,6 +153,12 @@ class SortableFloatFieldSource extends FieldCacheSource {
return description() + '=' + floatVal(doc);
}
@Override
public Object objectVal(int doc) {
int ord=termsIndex.getOrd(doc);
return ord==0 ? null : NumberUtils.SortableStr2float(termsIndex.lookup(ord, spare));
}
@Override
public ValueFiller getValueFiller() {
return new ValueFiller() {

View File

@ -155,6 +155,12 @@ class SortableIntFieldSource extends FieldCacheSource {
return description() + '=' + intVal(doc);
}
@Override
public Object objectVal(int doc) {
int ord=termsIndex.getOrd(doc);
return ord==0 ? null : NumberUtils.SortableStr2int(termsIndex.lookup(ord, spare));
}
@Override
public ValueFiller getValueFiller() {
return new ValueFiller() {

View File

@ -149,6 +149,12 @@ class SortableLongFieldSource extends FieldCacheSource {
return Long.toString(longVal(doc));
}
@Override
public Object objectVal(int doc) {
int ord=termsIndex.getOrd(doc);
return ord==0 ? null : NumberUtils.SortableStr2long(termsIndex.lookup(ord, spare));
}
@Override
public String toString(int doc) {
return description() + '=' + longVal(doc);

View File

@ -19,9 +19,11 @@ package org.apache.solr.schema;
import org.apache.lucene.index.IndexReader.AtomicReaderContext;
import org.apache.lucene.util.BytesRef;
import org.apache.noggit.CharArr;
import org.apache.solr.search.function.DocValues;
import org.apache.solr.search.function.FieldCacheSource;
import org.apache.solr.search.function.StringIndexDocValues;
import org.apache.solr.util.ByteUtils;
import java.io.IOException;
import java.util.Map;
@ -40,32 +42,12 @@ public class StrFieldSource extends FieldCacheSource {
@Override
public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
return new StringIndexDocValues(this, readerContext, field) {
@Override
protected String toTerm(String readableValue) {
return readableValue;
}
@Override
public float floatVal(int doc) {
return (float)intVal(doc);
}
@Override
public int intVal(int doc) {
int ord=termsIndex.getOrd(doc);
return ord;
}
@Override
public long longVal(int doc) {
return (long)intVal(doc);
}
@Override
public double doubleVal(int doc) {
return (double)intVal(doc);
}
@Override
public int ordVal(int doc) {
return termsIndex.getOrd(doc);
@ -77,13 +59,8 @@ public class StrFieldSource extends FieldCacheSource {
}
@Override
public String strVal(int doc) {
int ord=termsIndex.getOrd(doc);
if (ord == 0) {
return null;
} else {
return termsIndex.lookup(ord, new BytesRef()).utf8ToString();
}
public Object objectVal(int doc) {
return strVal(doc);
}
@Override

View File

@ -538,6 +538,11 @@ class TrieDateFieldSource extends LongFieldSource {
return new MutableValueDate();
}
@Override
public Object longToObject(long val) {
return new Date(val);
}
@Override
public long externalToLong(String extVal) {
return TrieField.dateField.parseMath(null, extVal).getTime();

View File

@ -638,7 +638,11 @@ public class QueryParsing {
}
String v = val.substring(start,pos);
return flt ? Double.parseDouble(v) : Long.parseLong(v);
if (flt) {
return Double.parseDouble(v);
} else {
return Long.parseLong(v);
}
}
double getDouble() throws ParseException {

View File

@ -793,7 +793,7 @@ class LongConstValueSource extends ConstNumberSource {
@Override
public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
return new DocValues() {
return new LongDocValues(this) {
@Override
public float floatVal(int doc) {
return fv;
@ -814,11 +814,6 @@ class LongConstValueSource extends ConstNumberSource {
return dv;
}
@Override
public String strVal(int doc) {
return Long.toString(constant);
}
@Override
public String toString(int doc) {
return description();
@ -901,28 +896,12 @@ abstract class DoubleParser extends NamedParser {
@Override
public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
final DocValues vals = source.getValues(context, readerContext);
return new DocValues() {
@Override
public float floatVal(int doc) {
return (float)doubleVal(doc);
}
@Override
public int intVal(int doc) {
return (int)doubleVal(doc);
}
@Override
public long longVal(int doc) {
return (long)doubleVal(doc);
}
return new DoubleDocValues(this) {
@Override
public double doubleVal(int doc) {
return func(doc, vals);
}
@Override
public String strVal(int doc) {
return Double.toString(doubleVal(doc));
}
@Override
public String toString(int doc) {
return name() + '(' + vals.toString(doc) + ')';
}
@ -966,28 +945,12 @@ abstract class Double2Parser extends NamedParser {
public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
final DocValues aVals = a.getValues(context, readerContext);
final DocValues bVals = b.getValues(context, readerContext);
return new DocValues() {
@Override
public float floatVal(int doc) {
return (float)doubleVal(doc);
}
@Override
public int intVal(int doc) {
return (int)doubleVal(doc);
}
@Override
public long longVal(int doc) {
return (long)doubleVal(doc);
}
@Override
return new DoubleDocValues(this) {
@Override
public double doubleVal(int doc) {
return func(doc, aVals, bVals);
}
@Override
public String strVal(int doc) {
return Double.toString(doubleVal(doc));
}
@Override
public String toString(int doc) {
return name() + '(' + aVals.toString(doc) + ',' + bVals.toString(doc) + ')';
}

View File

@ -88,6 +88,11 @@ public class ByteFieldSource extends NumericFieldCacheSource<ByteValues> {
return description() + '=' + byteVal(doc);
}
@Override
public Object objectVal(int doc) {
return arr[doc]; // TODO: valid?
}
};
}
}

View File

@ -41,7 +41,7 @@ public class ConstValueSource extends ConstNumberSource {
@Override
public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
return new DocValues() {
return new FloatDocValues(this) {
@Override
public float floatVal(int doc) {
return constant;
@ -59,13 +59,13 @@ public class ConstValueSource extends ConstNumberSource {
return dv;
}
@Override
public String strVal(int doc) {
return Float.toString(constant);
}
@Override
public String toString(int doc) {
return description();
}
@Override
public Object objectVal(int doc) {
return constant;
}
};
}

View File

@ -21,14 +21,13 @@ import org.apache.lucene.index.IndexReader.AtomicReaderContext;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.util.BytesRef;
import org.apache.solr.search.MutableValueInt;
import org.apache.solr.search.MutableValue;
import org.apache.solr.search.*;
import java.io.IOException;
import java.util.Map;
class ConstIntDocValues extends DocValues {
class ConstIntDocValues extends IntDocValues {
final int ival;
final float fval;
final double dval;
@ -37,6 +36,7 @@ class ConstIntDocValues extends DocValues {
final ValueSource parent;
ConstIntDocValues(int val, ValueSource parent) {
super(parent);
ival = val;
fval = val;
dval = val;
@ -71,7 +71,7 @@ class ConstIntDocValues extends DocValues {
}
}
class ConstDoubleDocValues extends DocValues {
class ConstDoubleDocValues extends DoubleDocValues {
final int ival;
final float fval;
final double dval;
@ -80,6 +80,7 @@ class ConstDoubleDocValues extends DocValues {
final ValueSource parent;
ConstDoubleDocValues(double val, ValueSource parent) {
super(parent);
ival = (int)val;
fval = (float)val;
dval = val;
@ -114,115 +115,6 @@ class ConstDoubleDocValues extends DocValues {
}
}
abstract class FloatDocValues extends DocValues {
protected final ValueSource vs;
public FloatDocValues(ValueSource vs) {
this.vs = vs;
}
@Override
public byte byteVal(int doc) {
return (byte)floatVal(doc);
}
@Override
public short shortVal(int doc) {
return (short)floatVal(doc);
}
@Override
public abstract float floatVal(int doc);
@Override
public int intVal(int doc) {
return (int)floatVal(doc);
}
@Override
public long longVal(int doc) {
return (long)floatVal(doc);
}
@Override
public double doubleVal(int doc) {
return (double)floatVal(doc);
}
@Override
public String strVal(int doc) {
return Float.toString(floatVal(doc));
}
@Override
public String toString(int doc) {
return vs.description() + '=' + strVal(doc);
}
}
abstract class IntDocValues extends DocValues {
protected final ValueSource vs;
public IntDocValues(ValueSource vs) {
this.vs = vs;
}
@Override
public byte byteVal(int doc) {
return (byte)intVal(doc);
}
@Override
public short shortVal(int doc) {
return (short)intVal(doc);
}
@Override
public float floatVal(int doc) {
return (float)intVal(doc);
}
@Override
public abstract int intVal(int doc);
@Override
public long longVal(int doc) {
return (long)intVal(doc);
}
@Override
public double doubleVal(int doc) {
return (double)intVal(doc);
}
@Override
public String strVal(int doc) {
return Integer.toString(intVal(doc));
}
@Override
public String toString(int doc) {
return vs.description() + '=' + strVal(doc);
}
@Override
public ValueFiller getValueFiller() {
return new ValueFiller() {
private final MutableValueInt mval = new MutableValueInt();
@Override
public MutableValue getValue() {
return mval;
}
@Override
public void fillValue(int doc) {
mval.value = intVal(doc);
}
};
}
}
/**
* <code>DocFreqValueSource</code> returns the number of documents containing the term.

View File

@ -19,6 +19,7 @@ package org.apache.solr.search.function;
import org.apache.lucene.search.*;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.util.BytesRef;
import org.apache.solr.search.MutableValue;
import org.apache.solr.search.MutableValueFloat;
@ -47,6 +48,28 @@ public abstract class DocValues {
// TODO: should we make a termVal, returns BytesRef?
public String strVal(int doc) { throw new UnsupportedOperationException(); }
/** returns the bytes representation of the string val - TODO: should this return the indexed raw bytes not? */
public boolean bytesVal(int doc, BytesRef target) {
String s = strVal(doc);
if (s==null) {
target.length = 0;
return false;
}
target.copy(s);
return true;
};
/** Native Java Object representation of the value */
public Object objectVal(int doc) {
// most DocValues are functions, so by default return a Float()
return floatVal(doc);
}
/** Returns true if there is a value for this document */
public boolean exists(int doc) {
return true;
}
/**
* @param doc The doc to retrieve to sort ordinal for
* @return the sort ordinal for the specified doc

View File

@ -40,7 +40,7 @@ public class DoubleConstValueSource extends ConstNumberSource {
@Override
public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
return new DocValues() {
return new DoubleDocValues(this) {
@Override
public float floatVal(int doc) {
return fv;
@ -66,6 +66,11 @@ public class DoubleConstValueSource extends ConstNumberSource {
return Double.toString(constant);
}
@Override
public Object objectVal(int doc) {
return constant;
}
@Override
public String toString(int doc) {
return description();

View File

@ -0,0 +1,74 @@
package org.apache.solr.search.function;
import org.apache.solr.search.MutableValue;
import org.apache.solr.search.MutableValueDouble;
public abstract class DoubleDocValues extends DocValues {
protected final ValueSource vs;
public DoubleDocValues(ValueSource vs) {
this.vs = vs;
}
@Override
public byte byteVal(int doc) {
return (byte)doubleVal(doc);
}
@Override
public short shortVal(int doc) {
return (short)doubleVal(doc);
}
@Override
public float floatVal(int doc) {
return (float)doubleVal(doc);
}
@Override
public int intVal(int doc) {
return (int)doubleVal(doc);
}
@Override
public long longVal(int doc) {
return (long)doubleVal(doc);
}
@Override
public abstract double doubleVal(int doc);
@Override
public String strVal(int doc) {
return Double.toString(doubleVal(doc));
}
@Override
public Object objectVal(int doc) {
return exists(doc) ? doubleVal(doc) : null;
}
@Override
public String toString(int doc) {
return vs.description() + '=' + strVal(doc);
}
@Override
public ValueFiller getValueFiller() {
return new ValueFiller() {
private final MutableValueDouble mval = new MutableValueDouble();
@Override
public MutableValue getValue() {
return mval;
}
@Override
public void fillValue(int doc) {
mval.value = doubleVal(doc);
mval.exists = exists(doc);
}
};
}
}

View File

@ -51,7 +51,7 @@ public class DoubleFieldSource extends NumericFieldCacheSource<DoubleValues> {
public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
final DoubleValues vals = cache.getDoubles(readerContext.reader, field, creator);
final double[] arr = vals.values;
final Bits valid = vals.valid;
final Bits valid = vals.valid;
return new DocValues() {
@Override
@ -79,6 +79,11 @@ public class DoubleFieldSource extends NumericFieldCacheSource<DoubleValues> {
return Double.toString(arr[doc]);
}
@Override
public Object objectVal(int doc) {
return valid.get(doc) ? arr[doc] : null;
}
@Override
public String toString(int doc) {
return description() + '=' + doubleVal(doc);

View File

@ -48,28 +48,12 @@ public abstract class DualFloatFunction extends ValueSource {
public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
final DocValues aVals = a.getValues(context, readerContext);
final DocValues bVals = b.getValues(context, readerContext);
return new DocValues() {
return new FloatDocValues(this) {
@Override
public float floatVal(int doc) {
return func(doc, aVals, bVals);
}
@Override
public int intVal(int doc) {
return (int)floatVal(doc);
}
@Override
public long longVal(int doc) {
return (long)floatVal(doc);
}
@Override
public double doubleVal(int doc) {
return floatVal(doc);
}
@Override
public String strVal(int doc) {
return Float.toString(floatVal(doc));
}
@Override
public String toString(int doc) {
return name() + '(' + aVals.toString(doc) + ',' + bVals.toString(doc) + ')';
}

View File

@ -65,35 +65,15 @@ public class FileFloatSource extends ValueSource {
final int off = offset;
final float[] arr = getCachedFloats(topLevelContext.reader);
return new DocValues() {
return new FloatDocValues(this) {
@Override
public float floatVal(int doc) {
return arr[doc + off];
}
@Override
public int intVal(int doc) {
return (int)arr[doc + off];
}
@Override
public long longVal(int doc) {
return (long)arr[doc + off];
}
@Override
public double doubleVal(int doc) {
return (double)arr[doc + off];
}
@Override
public String strVal(int doc) {
return Float.toString(arr[doc + off]);
}
@Override
public String toString(int doc) {
return description() + '=' + floatVal(doc);
public Object objectVal(int doc) {
return floatVal(doc); // TODO: keep track of missing values
}
};
}

View File

@ -0,0 +1,73 @@
package org.apache.solr.search.function;
import org.apache.solr.search.MutableValue;
import org.apache.solr.search.MutableValueFloat;
public abstract class FloatDocValues extends DocValues {
protected final ValueSource vs;
public FloatDocValues(ValueSource vs) {
this.vs = vs;
}
@Override
public byte byteVal(int doc) {
return (byte)floatVal(doc);
}
@Override
public short shortVal(int doc) {
return (short)floatVal(doc);
}
@Override
public abstract float floatVal(int doc);
@Override
public int intVal(int doc) {
return (int)floatVal(doc);
}
@Override
public long longVal(int doc) {
return (long)floatVal(doc);
}
@Override
public double doubleVal(int doc) {
return (double)floatVal(doc);
}
@Override
public String strVal(int doc) {
return Float.toString(floatVal(doc));
}
@Override
public Object objectVal(int doc) {
return exists(doc) ? floatVal(doc) : null;
}
@Override
public String toString(int doc) {
return vs.description() + '=' + strVal(doc);
}
@Override
public ValueFiller getValueFiller() {
return new ValueFiller() {
private final MutableValueFloat mval = new MutableValueFloat();
@Override
public MutableValue getValue() {
return mval;
}
@Override
public void fillValue(int doc) {
mval.value = floatVal(doc);
mval.exists = exists(doc);
}
};
}
}

View File

@ -50,37 +50,22 @@ public class FloatFieldSource extends NumericFieldCacheSource<FloatValues> {
public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
final FloatValues vals = cache.getFloats(readerContext.reader, field, creator);
final float[] arr = vals.values;
final Bits valid = vals.valid;
final Bits valid = vals.valid;
return new DocValues() {
return new FloatDocValues(this) {
@Override
public float floatVal(int doc) {
return arr[doc];
}
@Override
public int intVal(int doc) {
return (int)arr[doc];
public Object objectVal(int doc) {
return valid.get(doc) ? arr[doc] : null;
}
@Override
public long longVal(int doc) {
return (long)arr[doc];
}
@Override
public double doubleVal(int doc) {
return (double)arr[doc];
}
@Override
public String strVal(int doc) {
return Float.toString(arr[doc]);
}
@Override
public String toString(int doc) {
return description() + '=' + floatVal(doc);
public boolean exists(int doc) {
return valid.get(doc);
}
@Override

View File

@ -0,0 +1,73 @@
package org.apache.solr.search.function;
import org.apache.solr.search.MutableValue;
import org.apache.solr.search.MutableValueInt;
public abstract class IntDocValues extends DocValues {
protected final ValueSource vs;
public IntDocValues(ValueSource vs) {
this.vs = vs;
}
@Override
public byte byteVal(int doc) {
return (byte)intVal(doc);
}
@Override
public short shortVal(int doc) {
return (short)intVal(doc);
}
@Override
public float floatVal(int doc) {
return (float)intVal(doc);
}
@Override
public abstract int intVal(int doc);
@Override
public long longVal(int doc) {
return (long)intVal(doc);
}
@Override
public double doubleVal(int doc) {
return (double)intVal(doc);
}
@Override
public String strVal(int doc) {
return Integer.toString(intVal(doc));
}
@Override
public Object objectVal(int doc) {
return exists(doc) ? intVal(doc) : null;
}
@Override
public String toString(int doc) {
return vs.description() + '=' + strVal(doc);
}
@Override
public ValueFiller getValueFiller() {
return new ValueFiller() {
private final MutableValueInt mval = new MutableValueInt();
@Override
public MutableValue getValue() {
return mval;
}
@Override
public void fillValue(int doc) {
mval.value = intVal(doc);
mval.exists = exists(doc);
}
};
}
}

View File

@ -51,9 +51,9 @@ public class IntFieldSource extends NumericFieldCacheSource<IntValues> {
public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
final IntValues vals = cache.getInts(readerContext.reader, field, creator);
final int[] arr = vals.values;
final Bits valid = vals.valid;
final Bits valid = vals.valid;
return new DocValues() {
return new IntDocValues(this) {
final MutableValueInt val = new MutableValueInt();
@Override
@ -81,6 +81,16 @@ public class IntFieldSource extends NumericFieldCacheSource<IntValues> {
return Float.toString(arr[doc]);
}
@Override
public Object objectVal(int doc) {
return valid.get(doc) ? arr[doc] : null;
}
@Override
public boolean exists(int doc) {
return valid.get(doc);
}
@Override
public String toString(int doc) {
return description() + '=' + intVal(doc);

View File

@ -54,7 +54,7 @@ public class JoinDocFreqValueSource extends FieldCacheSource {
final DocTerms terms = cache.getTerms(readerContext.reader, field, true );
final IndexReader top = ReaderUtil.getTopLevelContext(readerContext).reader;
return new DocValues() {
return new IntDocValues(this) {
BytesRef ref = new BytesRef();
@Override
@ -70,31 +70,6 @@ public class JoinDocFreqValueSource extends FieldCacheSource {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "caught exception in function "+description()+" : doc="+doc, e);
}
}
@Override
public float floatVal(int doc) {
return (float)intVal(doc);
}
@Override
public long longVal(int doc) {
return (long)intVal(doc);
}
@Override
public double doubleVal(int doc) {
return (double)intVal(doc);
}
@Override
public String strVal(int doc) {
return intVal(doc) + "";
}
@Override
public String toString(int doc) {
return description() + '=' + intVal(doc);
}
};
}

View File

@ -50,28 +50,12 @@ public class LinearFloatFunction extends ValueSource {
@Override
public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
final DocValues vals = source.getValues(context, readerContext);
return new DocValues() {
return new FloatDocValues(this) {
@Override
public float floatVal(int doc) {
return vals.floatVal(doc) * slope + intercept;
}
@Override
public int intVal(int doc) {
return (int)floatVal(doc);
}
@Override
public long longVal(int doc) {
return (long)floatVal(doc);
}
@Override
public double doubleVal(int doc) {
return (double)floatVal(doc);
}
@Override
public String strVal(int doc) {
return Float.toString(floatVal(doc));
}
@Override
public String toString(int doc) {
return slope + "*float(" + vals.toString(doc) + ")+" + intercept;
}

View File

@ -17,19 +17,23 @@ package org.apache.solr.search.function;
*/
import org.apache.lucene.index.IndexReader.AtomicReaderContext;
import org.apache.lucene.util.BytesRef;
import java.util.Map;
import java.io.IOException;
/**
* Pass a the field value through as a String, no matter the type
* Pass a the field value through as a String, no matter the type // Q: doesn't this mean it's a "string"?
*
**/
public class LiteralValueSource extends ValueSource {
protected final String string;
protected final BytesRef bytesRef;
public LiteralValueSource(String string) {
this.string = string;
this.bytesRef = new BytesRef(string);
}
/** returns the literal value */
@ -40,12 +44,18 @@ public class LiteralValueSource extends ValueSource {
@Override
public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
return new DocValues() {
return new StrDocValues(this) {
@Override
public String strVal(int doc) {
return string;
}
@Override
public boolean bytesVal(int doc, BytesRef target) {
target.copy(bytesRef);
return true;
}
@Override
public String toString(int doc) {
return string;

View File

@ -0,0 +1,73 @@
package org.apache.solr.search.function;
import org.apache.solr.search.MutableValue;
import org.apache.solr.search.MutableValueLong;
public abstract class LongDocValues extends DocValues {
protected final ValueSource vs;
public LongDocValues(ValueSource vs) {
this.vs = vs;
}
@Override
public byte byteVal(int doc) {
return (byte)longVal(doc);
}
@Override
public short shortVal(int doc) {
return (short)longVal(doc);
}
@Override
public float floatVal(int doc) {
return (float)longVal(doc);
}
@Override
public int intVal(int doc) {
return (int)longVal(doc);
}
@Override
public abstract long longVal(int doc);
@Override
public double doubleVal(int doc) {
return (double)longVal(doc);
}
@Override
public String strVal(int doc) {
return Long.toString(longVal(doc));
}
@Override
public Object objectVal(int doc) {
return exists(doc) ? longVal(doc) : null;
}
@Override
public String toString(int doc) {
return vs.description() + '=' + strVal(doc);
}
@Override
public ValueFiller getValueFiller() {
return new ValueFiller() {
private final MutableValueLong mval = new MutableValueLong();
@Override
public MutableValue getValue() {
return mval;
}
@Override
public void fillValue(int doc) {
mval.value = longVal(doc);
mval.exists = exists(doc);
}
};
}
}

View File

@ -52,41 +52,30 @@ public class LongFieldSource extends NumericFieldCacheSource<LongValues> {
return Long.parseLong(extVal);
}
public Object longToObject(long val) {
return val;
}
@Override
public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
final LongValues vals = cache.getLongs(readerContext.reader, field, creator);
final long[] arr = vals.values;
final Bits valid = vals.valid;
final Bits valid = vals.valid;
return new DocValues() {
@Override
public float floatVal(int doc) {
return (float) arr[doc];
}
@Override
public int intVal(int doc) {
return (int) arr[doc];
}
return new LongDocValues(this) {
@Override
public long longVal(int doc) {
return arr[doc];
}
@Override
public double doubleVal(int doc) {
return arr[doc];
public boolean exists(int doc) {
return valid.get(doc);
}
@Override
public String strVal(int doc) {
return Long.toString(arr[doc]);
}
@Override
public String toString(int doc) {
return description() + '=' + longVal(doc);
public Object objectVal(int doc) {
return valid.get(doc) ? longToObject(arr[doc]) : null;
}
@Override
@ -142,8 +131,6 @@ public class LongFieldSource extends NumericFieldCacheSource<LongValues> {
};
}
};
}

View File

@ -62,28 +62,12 @@ public abstract class MultiFloatFunction extends ValueSource {
valsArr[i] = sources[i].getValues(context, readerContext);
}
return new DocValues() {
return new FloatDocValues(this) {
@Override
public float floatVal(int doc) {
return func(doc, valsArr);
}
@Override
public int intVal(int doc) {
return (int)floatVal(doc);
}
@Override
public long longVal(int doc) {
return (long)floatVal(doc);
}
@Override
public double doubleVal(int doc) {
return (double)floatVal(doc);
}
@Override
public String strVal(int doc) {
return Float.toString(floatVal(doc));
}
@Override
@Override
public String toString(int doc) {
StringBuilder sb = new StringBuilder();
sb.append(name()).append('(');

View File

@ -63,53 +63,29 @@ public class OrdFieldSource extends ValueSource {
final int off = readerContext.docBase;
final IndexReader topReader = ReaderUtil.getTopLevelContext(readerContext).reader;
final FieldCache.DocTermsIndex sindex = FieldCache.DEFAULT.getTermsIndex(topReader, field);
return new DocValues() {
return new IntDocValues(this) {
protected String toTerm(String readableValue) {
return readableValue;
}
@Override
public float floatVal(int doc) {
return (float)sindex.getOrd(doc+off);
}
@Override
public int intVal(int doc) {
return sindex.getOrd(doc+off);
}
@Override
public long longVal(int doc) {
return (long)sindex.getOrd(doc+off);
}
@Override
public double doubleVal(int doc) {
return (double)sindex.getOrd(doc+off);
}
@Override
public int ordVal(int doc) {
return sindex.getOrd(doc+off);
}
@Override
public int numOrd() {
return sindex.numOrd();
}
@Override
public String strVal(int doc) {
// the string value of the ordinal, not the string itself
return Integer.toString(sindex.getOrd(doc+off));
public boolean exists(int doc) {
return sindex.getOrd(doc+off) != 0;
}
@Override
public String toString(int doc) {
return description() + '=' + intVal(doc);
}
@Override
public ValueFiller getValueFiller() {
return new ValueFiller() {
private final MutableValueInt mval = new MutableValueInt();

View File

@ -23,6 +23,8 @@ import org.apache.lucene.search.*;
import org.apache.lucene.search.Weight.ScorerContext;
import org.apache.lucene.util.ReaderUtil;
import org.apache.solr.common.SolrException;
import org.apache.solr.search.MutableValue;
import org.apache.solr.search.MutableValueFloat;
import java.io.IOException;
import java.util.Map;
@ -49,7 +51,7 @@ public class QueryValueSource extends ValueSource {
@Override
public DocValues getValues(Map fcontext, AtomicReaderContext readerContext) throws IOException {
return new QueryDocValues(readerContext, q, defVal, fcontext);
return new QueryDocValues(this, readerContext, fcontext);
}
@Override
@ -72,31 +74,31 @@ public class QueryValueSource extends ValueSource {
}
class QueryDocValues extends DocValues {
final Query q;
// final IndexReader reader;
class QueryDocValues extends FloatDocValues {
final AtomicReaderContext readerContext;
final Weight weight;
final float defVal;
final Map fcontext;
final Query q;
Scorer scorer;
int scorerDoc; // the document the scorer is on
boolean noMatches=false;
// the last document requested... start off with high value
// to trigger a scorer reset on first access.
int lastDocRequested=Integer.MAX_VALUE;
public QueryDocValues(AtomicReaderContext readerContext, Query q, float defVal, Map fcontext) throws IOException {
IndexReader reader = readerContext.reader;
public QueryDocValues(QueryValueSource vs, AtomicReaderContext readerContext, Map fcontext) throws IOException {
super(vs);
this.readerContext = readerContext;
this.q = q;
this.defVal = defVal;
this.defVal = vs.defVal;
this.q = vs.q;
this.fcontext = fcontext;
Weight w = fcontext==null ? null : (Weight)fcontext.get(q);
// TODO: sort by function doesn't weight (SOLR-1297 is open because of this bug)... so weightSearcher will currently be null
if (w == null) {
IndexSearcher weightSearcher;
if(fcontext == null) {
@ -116,8 +118,12 @@ class QueryDocValues extends DocValues {
public float floatVal(int doc) {
try {
if (doc < lastDocRequested) {
if (noMatches) return defVal;
scorer = weight.scorer(readerContext, ScorerContext.def());
if (scorer==null) return defVal;
if (scorer==null) {
noMatches = true;
return defVal;
}
scorerDoc = -1;
}
lastDocRequested = doc;
@ -137,24 +143,104 @@ class QueryDocValues extends DocValues {
} catch (IOException e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "caught exception in QueryDocVals("+q+") doc="+doc, e);
}
}
}
@Override
public int intVal(int doc) {
return (int)floatVal(doc);
public boolean exists(int doc) {
try {
if (doc < lastDocRequested) {
if (noMatches) return false;
scorer = weight.scorer(readerContext, ScorerContext.def());
scorerDoc = -1;
if (scorer==null) {
noMatches = true;
return false;
}
}
lastDocRequested = doc;
if (scorerDoc < doc) {
scorerDoc = scorer.advance(doc);
}
if (scorerDoc > doc) {
// query doesn't match this document... either because we hit the
// end, or because the next doc is after this doc.
return false;
}
// a match!
return true;
} catch (IOException e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "caught exception in QueryDocVals("+q+") doc="+doc, e);
}
}
@Override
public Object objectVal(int doc) {
try {
return exists(doc) ? scorer.score() : null;
} catch (IOException e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "caught exception in QueryDocVals("+q+") doc="+doc, e);
}
}
@Override
public long longVal(int doc) {
return (long)floatVal(doc);
}
@Override
public double doubleVal(int doc) {
return (double)floatVal(doc);
}
@Override
public String strVal(int doc) {
return Float.toString(floatVal(doc));
public ValueFiller getValueFiller() {
//
// TODO: if we want to support more than one value-filler or a value-filler in conjunction with
// the DocValues, then members like "scorer" should be per ValueFiller instance.
// Or we can say that the user should just instantiate multiple DocValues.
//
return new ValueFiller() {
private final MutableValueFloat mval = new MutableValueFloat();
@Override
public MutableValue getValue() {
return mval;
}
@Override
public void fillValue(int doc) {
try {
if (noMatches) {
mval.value = defVal;
mval.exists = false;
return;
}
scorer = weight.scorer(readerContext, ScorerContext.def());
scorerDoc = -1;
if (scorer==null) {
noMatches = true;
mval.value = defVal;
mval.exists = false;
return;
}
lastDocRequested = doc;
if (scorerDoc < doc) {
scorerDoc = scorer.advance(doc);
}
if (scorerDoc > doc) {
// query doesn't match this document... either because we hit the
// end, or because the next doc is after this doc.
mval.value = defVal;
mval.exists = false;
return;
}
// a match!
mval.value = scorer.score();
mval.exists = true;
return;
} catch (IOException e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "caught exception in QueryDocVals("+q+") doc="+doc, e);
}
}
};
}
@Override
public String toString(int doc) {
return "query(" + q + ",def=" + defVal + ")=" + floatVal(doc);

View File

@ -54,29 +54,13 @@ public class RangeMapFloatFunction extends ValueSource {
@Override
public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
final DocValues vals = source.getValues(context, readerContext);
return new DocValues() {
return new FloatDocValues(this) {
@Override
public float floatVal(int doc) {
float val = vals.floatVal(doc);
return (val>=min && val<=max) ? target : (defaultVal == null ? val : defaultVal);
}
@Override
public int intVal(int doc) {
return (int)floatVal(doc);
}
@Override
public long longVal(int doc) {
return (long)floatVal(doc);
}
@Override
public double doubleVal(int doc) {
return (double)floatVal(doc);
}
@Override
public String strVal(int doc) {
return Float.toString(floatVal(doc));
}
@Override
public String toString(int doc) {
return "map(" + vals.toString(doc) + ",min=" + min + ",max=" + max + ",target=" + target + ")";
}

View File

@ -60,28 +60,12 @@ public class ReciprocalFloatFunction extends ValueSource {
@Override
public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
final DocValues vals = source.getValues(context, readerContext);
return new DocValues() {
return new FloatDocValues(this) {
@Override
public float floatVal(int doc) {
return a/(m*vals.floatVal(doc) + b);
}
@Override
public int intVal(int doc) {
return (int)floatVal(doc);
}
@Override
public long longVal(int doc) {
return (long)floatVal(doc);
}
@Override
public double doubleVal(int doc) {
return (double)floatVal(doc);
}
@Override
public String strVal(int doc) {
return Float.toString(floatVal(doc));
}
@Override
public String toString(int doc) {
return Float.toString(a) + "/("
+ m + "*float(" + vals.toString(doc) + ')'

View File

@ -66,47 +66,11 @@ public class ReverseOrdFieldSource extends ValueSource {
final FieldCache.DocTermsIndex sindex = FieldCache.DEFAULT.getTermsIndex(topReader, field);
final int end = sindex.numOrd();
return new DocValues() {
@Override
public float floatVal(int doc) {
return (float)(end - sindex.getOrd(doc+off));
}
@Override
return new IntDocValues(this) {
@Override
public int intVal(int doc) {
return (end - sindex.getOrd(doc+off));
}
@Override
public long longVal(int doc) {
return (long)(end - sindex.getOrd(doc+off));
}
@Override
public int ordVal(int doc) {
return (end - sindex.getOrd(doc+off));
}
@Override
public int numOrd() {
return end;
}
@Override
public double doubleVal(int doc) {
return (double)(end - sindex.getOrd(doc+off));
}
@Override
public String strVal(int doc) {
// the string value of the ordinal, not the string itself
return Integer.toString((end - sindex.getOrd(doc+off)));
}
@Override
public String toString(int doc) {
return description() + '=' + strVal(doc);
}
};
}

View File

@ -108,28 +108,12 @@ public class ScaleFloatFunction extends ValueSource {
final DocValues vals = source.getValues(context, readerContext);
return new DocValues() {
return new FloatDocValues(this) {
@Override
public float floatVal(int doc) {
return (vals.floatVal(doc) - minSource) * scale + min;
}
@Override
public int intVal(int doc) {
return (int)floatVal(doc);
}
@Override
public long longVal(int doc) {
return (long)floatVal(doc);
}
@Override
public double doubleVal(int doc) {
return (double)floatVal(doc);
}
@Override
public String strVal(int doc) {
return Float.toString(floatVal(doc));
}
@Override
public String toString(int doc) {
return "scale(" + vals.toString(doc) + ",toMin=" + min + ",toMax=" + max
+ ",fromMin=" + minSource

View File

@ -34,28 +34,12 @@ import java.util.Map;
@Override
public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
final DocValues vals = source.getValues(context, readerContext);
return new DocValues() {
return new FloatDocValues(this) {
@Override
public float floatVal(int doc) {
return func(doc, vals);
}
@Override
public int intVal(int doc) {
return (int)floatVal(doc);
}
@Override
public long longVal(int doc) {
return (long)floatVal(doc);
}
@Override
public double doubleVal(int doc) {
return (double)floatVal(doc);
}
@Override
public String strVal(int doc) {
return Float.toString(floatVal(doc));
}
@Override
public String toString(int doc) {
return name() + '(' + vals.toString(doc) + ')';
}

View File

@ -0,0 +1,45 @@
package org.apache.solr.search.function;
import org.apache.lucene.util.BytesRef;
import org.apache.noggit.CharArr;
import org.apache.solr.search.MutableValue;
import org.apache.solr.search.MutableValueFloat;
import org.apache.solr.search.MutableValueStr;
public abstract class StrDocValues extends DocValues {
protected final ValueSource vs;
public StrDocValues(ValueSource vs) {
this.vs = vs;
}
@Override
public abstract String strVal(int doc);
@Override
public Object objectVal(int doc) {
return exists(doc) ? strVal(doc) : null;
}
@Override
public String toString(int doc) {
return vs.description() + "='" + strVal(doc) + "'";
}
@Override
public ValueFiller getValueFiller() {
return new ValueFiller() {
private final MutableValueStr mval = new MutableValueStr();
@Override
public MutableValue getValue() {
return mval;
}
@Override
public void fillValue(int doc) {
mval.exists = bytesVal(doc, mval.value);
}
};
}
}

View File

@ -21,8 +21,10 @@ import org.apache.lucene.search.FieldCache;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexReader.AtomicReaderContext;
import org.apache.lucene.util.BytesRef;
import org.apache.noggit.CharArr;
import org.apache.solr.search.MutableValue;
import org.apache.solr.search.MutableValueStr;
import org.apache.solr.util.ByteUtils;
import java.io.IOException;
@ -30,65 +32,98 @@ import java.io.IOException;
* Serves as base class for DocValues based on StringIndex
**/
public abstract class StringIndexDocValues extends DocValues {
protected final FieldCache.DocTermsIndex termsIndex;
protected final ValueSource vs;
protected final MutableValueStr val = new MutableValueStr();
protected final FieldCache.DocTermsIndex termsIndex;
protected final ValueSource vs;
protected final MutableValueStr val = new MutableValueStr();
protected final BytesRef spare = new BytesRef();
protected final CharArr spareChars = new CharArr();
public StringIndexDocValues(ValueSource vs, AtomicReaderContext context, String field) throws IOException {
try {
termsIndex = FieldCache.DEFAULT.getTermsIndex(context.reader, field);
} catch (RuntimeException e) {
throw new StringIndexException(field, e);
public StringIndexDocValues(ValueSource vs, AtomicReaderContext context, String field) throws IOException {
try {
termsIndex = FieldCache.DEFAULT.getTermsIndex(context.reader, field);
} catch (RuntimeException e) {
throw new StringIndexException(field, e);
}
this.vs = vs;
}
public FieldCache.DocTermsIndex getDocTermsIndex() {
return termsIndex;
}
protected abstract String toTerm(String readableValue);
@Override
public boolean exists(int doc) {
return termsIndex.getOrd(doc) != 0;
}
@Override
public boolean bytesVal(int doc, BytesRef target) {
int ord=termsIndex.getOrd(doc);
if (ord==0) {
target.length = 0;
return false;
}
termsIndex.lookup(ord, target);
return true;
}
@Override
public String strVal(int doc) {
int ord=termsIndex.getOrd(doc);
if (ord==0) return null;
termsIndex.lookup(ord, spare);
spareChars.reset();
ByteUtils.UTF8toUTF16(spare, spareChars);
return spareChars.toString();
}
@Override
public abstract Object objectVal(int doc); // force subclasses to override
@Override
public ValueSourceScorer getRangeScorer(IndexReader reader, String lowerVal, String upperVal, boolean includeLower, boolean includeUpper) {
// TODO: are lowerVal and upperVal in indexed form or not?
lowerVal = lowerVal == null ? null : toTerm(lowerVal);
upperVal = upperVal == null ? null : toTerm(upperVal);
final BytesRef spare = new BytesRef();
int lower = Integer.MIN_VALUE;
if (lowerVal != null) {
lower = termsIndex.binarySearchLookup(new BytesRef(lowerVal), spare);
if (lower < 0) {
lower = -lower-1;
} else if (!includeLower) {
lower++;
}
this.vs = vs;
}
public FieldCache.DocTermsIndex getDocTermsIndex() {
return termsIndex;
}
protected abstract String toTerm(String readableValue);
@Override
public ValueSourceScorer getRangeScorer(IndexReader reader, String lowerVal, String upperVal, boolean includeLower, boolean includeUpper) {
// TODO: are lowerVal and upperVal in indexed form or not?
lowerVal = lowerVal == null ? null : toTerm(lowerVal);
upperVal = upperVal == null ? null : toTerm(upperVal);
final BytesRef spare = new BytesRef();
int lower = Integer.MIN_VALUE;
if (lowerVal != null) {
lower = termsIndex.binarySearchLookup(new BytesRef(lowerVal), spare);
if (lower < 0) {
lower = -lower-1;
} else if (!includeLower) {
lower++;
}
int upper = Integer.MAX_VALUE;
if (upperVal != null) {
upper = termsIndex.binarySearchLookup(new BytesRef(upperVal), spare);
if (upper < 0) {
upper = -upper-2;
} else if (!includeUpper) {
upper--;
}
int upper = Integer.MAX_VALUE;
if (upperVal != null) {
upper = termsIndex.binarySearchLookup(new BytesRef(upperVal), spare);
if (upper < 0) {
upper = -upper-2;
} else if (!includeUpper) {
upper--;
}
}
final int ll = lower;
final int uu = upper;
return new ValueSourceScorer(reader, this) {
@Override
public boolean matchesValue(int doc) {
int ord = termsIndex.getOrd(doc);
return ord >= ll && ord <= uu;
}
};
}
final int ll = lower;
final int uu = upper;
return new ValueSourceScorer(reader, this) {
@Override
public boolean matchesValue(int doc) {
int ord = termsIndex.getOrd(doc);
return ord >= ll && ord <= uu;
}
};
}
@Override
public String toString(int doc) {
return vs.description() + '=' + strVal(doc);
@ -117,7 +152,7 @@ public abstract class StringIndexDocValues extends DocValues {
public StringIndexException(final String fieldName,
final RuntimeException cause) {
super("Can't initialize StringIndex to generate (function) " +
"DocValues for field: " + fieldName, cause);
"DocValues for field: " + fieldName, cause);
}
}

View File

@ -18,6 +18,7 @@ package org.apache.solr.search.function.distance;
import org.apache.lucene.spatial.DistanceUtils;
import org.apache.solr.search.function.DoubleDocValues;
import org.apache.solr.search.function.ValueSource;
import org.apache.solr.search.function.DocValues;
import org.apache.lucene.index.IndexReader.AtomicReaderContext;
@ -58,32 +59,11 @@ public class GeohashHaversineFunction extends ValueSource {
final DocValues gh1DV = geoHash1.getValues(context, readerContext);
final DocValues gh2DV = geoHash2.getValues(context, readerContext);
return new DocValues() {
@Override
public float floatVal(int doc) {
return (float) doubleVal(doc);
}
@Override
public int intVal(int doc) {
return (int) doubleVal(doc);
}
@Override
public long longVal(int doc) {
return (long) doubleVal(doc);
}
return new DoubleDocValues(this) {
@Override
public double doubleVal(int doc) {
return distance(doc, gh1DV, gh2DV);
}
@Override
public String strVal(int doc) {
return Double.toString(doubleVal(doc));
}
@Override
public String toString(int doc) {
StringBuilder sb = new StringBuilder();

View File

@ -198,22 +198,7 @@ public class HaversineConstFunction extends ValueSource {
final double lonCenterRad = this.lonCenter * DistanceUtils.DEGREES_TO_RADIANS;
final double latCenterRad_cos = this.latCenterRad_cos;
return new DocValues() {
@Override
public float floatVal(int doc) {
return (float) doubleVal(doc);
}
@Override
public int intVal(int doc) {
return (int) doubleVal(doc);
}
@Override
public long longVal(int doc) {
return (long) doubleVal(doc);
}
return new DoubleDocValues(this) {
@Override
public double doubleVal(int doc) {
double latRad = latVals.doubleVal(doc) * DistanceUtils.DEGREES_TO_RADIANS;
@ -226,12 +211,6 @@ public class HaversineConstFunction extends ValueSource {
(latCenterRad_cos * Math.cos(latRad) * hsinY * hsinY);
return (EARTH_MEAN_DIAMETER * Math.atan2(Math.sqrt(h), Math.sqrt(1 - h)));
}
@Override
public String strVal(int doc) {
return Double.toString(doubleVal(doc));
}
@Override
public String toString(int doc) {
return name() + '(' + latVals.toString(doc) + ',' + lonVals.toString(doc) + ',' + latCenter + ',' + lonCenter + ')';

View File

@ -20,6 +20,7 @@ import org.apache.lucene.index.IndexReader.AtomicReaderContext;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.spatial.DistanceUtils;
import org.apache.solr.common.SolrException;
import org.apache.solr.search.function.DoubleDocValues;
import org.apache.solr.search.function.MultiValueSource;
import org.apache.solr.search.function.DocValues;
import org.apache.solr.search.function.ValueSource;
@ -99,32 +100,11 @@ public class HaversineFunction extends ValueSource {
final DocValues vals1 = p1.getValues(context, readerContext);
final DocValues vals2 = p2.getValues(context, readerContext);
return new DocValues() {
@Override
public float floatVal(int doc) {
return (float) doubleVal(doc);
}
@Override
public int intVal(int doc) {
return (int) doubleVal(doc);
}
@Override
public long longVal(int doc) {
return (long) doubleVal(doc);
}
return new DoubleDocValues(this) {
@Override
public double doubleVal(int doc) {
return distance(doc, vals1, vals2);
}
@Override
public String strVal(int doc) {
return Double.toString(doubleVal(doc));
}
@Override
public String toString(int doc) {
StringBuilder sb = new StringBuilder();

View File

@ -20,6 +20,7 @@ package org.apache.solr.search.function.distance;
import org.apache.lucene.index.IndexReader.AtomicReaderContext;
import org.apache.lucene.search.spell.StringDistance;
import org.apache.solr.search.function.DocValues;
import org.apache.solr.search.function.FloatDocValues;
import org.apache.solr.search.function.ValueSource;
import java.io.IOException;
@ -51,28 +52,13 @@ public class StringDistanceFunction extends ValueSource {
public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
final DocValues str1DV = str1.getValues(context, readerContext);
final DocValues str2DV = str2.getValues(context, readerContext);
return new DocValues() {
return new FloatDocValues(this) {
@Override
public float floatVal(int doc) {
return dist.getDistance(str1DV.strVal(doc), str2DV.strVal(doc));
}
@Override
public int intVal(int doc) {
return (int) doubleVal(doc);
}
@Override
public long longVal(int doc) {
return (long) doubleVal(doc);
}
@Override
public double doubleVal(int doc) {
return (double) floatVal(doc);
}
@Override
public String toString(int doc) {
StringBuilder sb = new StringBuilder();

View File

@ -21,6 +21,7 @@ import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.spatial.DistanceUtils;
import org.apache.solr.common.SolrException;
import org.apache.solr.search.function.DocValues;
import org.apache.solr.search.function.DoubleDocValues;
import org.apache.solr.search.function.MultiValueSource;
import org.apache.solr.search.function.ValueSource;
@ -85,42 +86,13 @@ public class VectorDistanceFunction extends ValueSource {
final DocValues vals2 = source2.getValues(context, readerContext);
return new DocValues() {
@Override
public byte byteVal(int doc) {
return (byte) doubleVal(doc);
}
@Override
public short shortVal(int doc) {
return (short) doubleVal(doc);
}
@Override
public float floatVal(int doc) {
return (float) doubleVal(doc);
}
@Override
public int intVal(int doc) {
return (int) doubleVal(doc);
}
@Override
public long longVal(int doc) {
return (long) doubleVal(doc);
}
return new DoubleDocValues(this) {
@Override
public double doubleVal(int doc) {
return distance(doc, vals1, vals2);
}
@Override
public String strVal(int doc) {
return Double.toString(doubleVal(doc));
}
@Override
public String toString(int doc) {
StringBuilder sb = new StringBuilder();

View File

@ -99,15 +99,15 @@ public class QueryParsingTest extends SolrTestCaseJ4 {
assertEquals(flds[0].getType(), SortField.CUSTOM);
//Not thrilled about the fragility of string matching here, but...
//the value sources get wrapped, so the out field is different than the input
assertEquals(flds[0].getField(), "pow(float(weight),const(2.0))");
assertEquals(flds[0].getField(), "pow(float(weight),const(2))");
//test functions (more deep)
sort = QueryParsing.parseSort("sum(product(r_f1,sum(d_f1,t_f1,1)),a_f1) asc", req);
sort = QueryParsing.parseSort("sum(product(r_f1,sum(d_f1,t_f1,1.0)),a_f1) asc", req);
flds = sort.getSort();
assertEquals(flds[0].getType(), SortField.CUSTOM);
assertEquals(flds[0].getField(), "sum(product(float(r_f1),sum(float(d_f1),float(t_f1),const(1.0))),float(a_f1))");
sort = QueryParsing.parseSort("pow(weight, 2) desc", req);
sort = QueryParsing.parseSort("pow(weight, 2.0) desc", req);
flds = sort.getSort();
assertEquals(flds[0].getType(), SortField.CUSTOM);
//Not thrilled about the fragility of string matching here, but...
@ -115,7 +115,7 @@ public class QueryParsingTest extends SolrTestCaseJ4 {
assertEquals(flds[0].getField(), "pow(float(weight),const(2.0))");
sort = QueryParsing.parseSort("pow(weight, 2) desc, weight desc, bday asc", req);
sort = QueryParsing.parseSort("pow(weight, 2.0) desc, weight desc, bday asc", req);
flds = sort.getSort();
assertEquals(flds[0].getType(), SortField.CUSTOM);

View File

@ -43,6 +43,7 @@ public class TestQueryTypes extends AbstractSolrTestCase {
public void testQueryTypes() {
assertU(adoc("id","0"));
assertU(adoc("id","1", "v_t","Hello Dude"));
assertU(adoc("id","2", "v_t","Hello Yonik"));
assertU(adoc("id","3", "v_s","{!literal}"));
@ -120,6 +121,7 @@ public class TestQueryTypes extends AbstractSolrTestCase {
);
// function query... just make sure it doesn't throw an exception
if ("v_s".equals(f)) continue; // in this context, functions must be able to be interpreted as a float
assertQ(req( "q", "+id:999 _val_:\"" + f + "\"")
,"//result[@numFound='1']"
);