本文整理汇总了Java中org.apache.lucene.queries.function.FunctionValues类的典型用法代码示例。如果您正苦于以下问题:Java FunctionValues类的具体用法?Java FunctionValues怎么用?Java FunctionValues使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FunctionValues类属于org.apache.lucene.queries.function包,在下文中一共展示了FunctionValues类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getValues
import org.apache.lucene.queries.function.FunctionValues; //导入依赖的package包/类
@Override
@SuppressWarnings("rawtypes") // ValueSource uses a rawtype
public FunctionValues getValues(Map context, LeafReaderContext leaf) throws IOException {
AtomicGeoPointFieldData leafData = (AtomicGeoPointFieldData) fieldData.load(leaf);
final MultiGeoPointValues values = leafData.getGeoPointValues();
return new DoubleDocValues(this) {
@Override
public double doubleVal(int doc) {
values.setDocument(doc);
if (values.count() == 0) {
return 0.0;
} else {
return values.valueAt(0).getLon();
}
}
};
}
示例2: getValues
import org.apache.lucene.queries.function.FunctionValues; //导入依赖的package包/类
@Override
@SuppressWarnings("rawtypes") // ValueSource uses a rawtype
public FunctionValues getValues(Map context, LeafReaderContext leaf) throws IOException {
AtomicGeoPointFieldData leafData = (AtomicGeoPointFieldData) fieldData.load(leaf);
final MultiGeoPointValues values = leafData.getGeoPointValues();
return new DoubleDocValues(this) {
@Override
public double doubleVal(int doc) {
values.setDocument(doc);
if (values.count() == 0) {
return 0.0;
} else {
return values.valueAt(0).getLat();
}
}
};
}
示例3: getValues
import org.apache.lucene.queries.function.FunctionValues; //导入依赖的package包/类
@Override
@SuppressWarnings("rawtypes") // ValueSource uses a rawtype
public FunctionValues getValues(Map context, LeafReaderContext leaf) throws IOException {
AtomicNumericFieldData leafData = (AtomicNumericFieldData) fieldData.load(leaf);
final SortedNumericDoubleValues values = leafData.getDoubleValues();
return new DoubleDocValues(this) {
@Override
public double doubleVal(int doc) {
values.setDocument(doc);
if (values.count() == 0) {
return 1;
} else {
return 0;
}
}
};
}
示例4: getValues
import org.apache.lucene.queries.function.FunctionValues; //导入依赖的package包/类
@Override
@SuppressWarnings("rawtypes") // ValueSource uses a rawtype
public FunctionValues getValues(Map context, LeafReaderContext leaf) throws IOException {
AtomicGeoPointFieldData leafData = (AtomicGeoPointFieldData) fieldData.load(leaf);
final MultiGeoPointValues values = leafData.getGeoPointValues();
return new DoubleDocValues(this) {
@Override
public double doubleVal(int doc) {
values.setDocument(doc);
if (values.count() == 0) {
return 1;
} else {
return 0;
}
}
};
}
示例5: getValues
import org.apache.lucene.queries.function.FunctionValues; //导入依赖的package包/类
@Override
public FunctionValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
IndexSearcher searcher = (IndexSearcher)context.get("searcher");
final TFIDFSimilarity similarity = IDFValueSource.asTFIDF(searcher.getSimilarity(), field);
if (similarity == null) {
throw new UnsupportedOperationException("requires a TFIDFSimilarity (such as DefaultSimilarity)");
}
final NumericDocValues norms = readerContext.reader().getNormValues(field);
if (norms == null) {
return new ConstDoubleDocValues(0.0, this);
}
return new FloatDocValues(this) {
@Override
public float floatVal(int doc) {
return similarity.decodeNormValue(norms.get(doc));
}
};
}
示例6: getValues
import org.apache.lucene.queries.function.FunctionValues; //导入依赖的package包/类
@Override
public FunctionValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
final IndexReader topReader = ReaderUtil.getTopLevelContext(readerContext).reader();
final AtomicReader r = SlowCompositeReaderWrapper.wrap(topReader);
final int off = readerContext.docBase;
final SortedDocValues sindex = FieldCache.DEFAULT.getTermsIndex(r, field);
final int end = sindex.getValueCount();
return new IntDocValues(this) {
@Override
public int intVal(int doc) {
return (end - sindex.getOrd(doc+off) - 1);
}
};
}
示例7: getValues
import org.apache.lucene.queries.function.FunctionValues; //导入依赖的package包/类
@Override
public FunctionValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
Map<String, FunctionValues> valuesCache = (Map<String, FunctionValues>)context.get("valuesCache");
if (valuesCache == null) {
valuesCache = new HashMap<>();
context = new HashMap(context);
context.put("valuesCache", valuesCache);
}
FunctionValues[] externalValues = new FunctionValues[expression.variables.length];
for (int i = 0; i < variables.length; ++i) {
String externalName = expression.variables[i];
FunctionValues values = valuesCache.get(externalName);
if (values == null) {
values = variables[i].getValues(context, readerContext);
if (values == null) {
throw new RuntimeException("Internal error. External (" + externalName + ") does not exist.");
}
valuesCache.put(externalName, values);
}
externalValues[i] = values;
}
return new ExpressionFunctionValues(this, expression, externalValues);
}
示例8: testRangeScorer
import org.apache.lucene.queries.function.FunctionValues; //导入依赖的package包/类
public void testRangeScorer() throws Exception {
Expression expr = JavascriptCompiler.compile("2*popularity");
SimpleBindings bindings = new SimpleBindings();
bindings.add(new SortField("popularity", SortField.Type.LONG));
ValueSource vs = expr.getValueSource(bindings);
assertEquals(1, reader.leaves().size());
AtomicReaderContext leaf = reader.leaves().get(0);
FunctionValues values = vs.getValues(new HashMap<String,Object>(), leaf);
// everything
ValueSourceScorer scorer = values.getRangeScorer(leaf.reader(), "4", "40", true, true);
assertEquals(-1, scorer.docID());
assertEquals(0, scorer.nextDoc());
assertEquals(1, scorer.nextDoc());
assertEquals(2, scorer.nextDoc());
assertEquals(DocIdSetIterator.NO_MORE_DOCS, scorer.nextDoc());
// just the first doc
scorer = values.getRangeScorer(leaf.reader(), "4", "40", false, false);
assertEquals(-1, scorer.docID());
assertEquals(0, scorer.nextDoc());
assertEquals(DocIdSetIterator.NO_MORE_DOCS, scorer.nextDoc());
}
示例9: getValues
import org.apache.lucene.queries.function.FunctionValues; //导入依赖的package包/类
@Override
public FunctionValues getValues(@SuppressWarnings("rawtypes") Map context, AtomicReaderContext readerContext) throws IOException {
final Scorer scorer = (Scorer) context.get("scorer");
if (scorer == null) {
throw new IllegalStateException("scores are missing; be sure to pass keepScores=true to FacetsCollector");
}
return new DoubleDocValues(this) {
@Override
public double doubleVal(int document) {
try {
return scorer.score();
} catch (IOException exception) {
throw new RuntimeException(exception);
}
}
};
}
示例10: transform
import org.apache.lucene.queries.function.FunctionValues; //导入依赖的package包/类
@Override
public void transform(SolrDocument doc, int docid) {
// This is only good for random-access functions
try {
// TODO: calculate this stuff just once across diff functions
int idx = ReaderUtil.subIndex(docid, readerContexts);
AtomicReaderContext rcontext = readerContexts.get(idx);
FunctionValues values = docValuesArr[idx];
if (values == null) {
docValuesArr[idx] = values = valueSource.getValues(fcontext, rcontext);
}
int localId = docid - rcontext.docBase;
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);
}
}
示例11: getVersionFromIndex
import org.apache.lucene.queries.function.FunctionValues; //导入依赖的package包/类
public Long getVersionFromIndex(BytesRef idBytes) {
// TODO: we could cache much of this and invalidate during a commit.
// TODO: most DocValues classes are threadsafe - expose which.
RefCounted<SolrIndexSearcher> newestSearcher = ulog.uhandler.core.getRealtimeSearcher();
try {
SolrIndexSearcher searcher = newestSearcher.get();
long lookup = searcher.lookupId(idBytes);
if (lookup < 0) return null;
ValueSource vs = versionField.getType().getValueSource(versionField, null);
Map context = ValueSource.newContext(searcher);
vs.createWeight(context, searcher);
FunctionValues fv = vs.getValues(context, searcher.getTopReaderContext().leaves().get((int)(lookup>>32)));
long ver = fv.longVal((int)lookup);
return ver;
} catch (IOException e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error reading version from index", e);
} finally {
if (newestSearcher != null) {
newestSearcher.decref();
}
}
}
示例12: distance
import org.apache.lucene.queries.function.FunctionValues; //导入依赖的package包/类
/**
* @param doc The doc to score
* @return The haversine distance formula
*/
protected double distance(int doc, FunctionValues p1DV, FunctionValues p2DV) {
double[] p1D = new double[2];
double[] p2D = new double[2];
p1DV.doubleVal(doc, p1D);
p2DV.doubleVal(doc, p2D);
double y1;
double x1;
double y2;
double x2;
if (convertToRadians) {
y1 = p1D[0] * DistanceUtils.DEGREES_TO_RADIANS;
x1 = p1D[1] * DistanceUtils.DEGREES_TO_RADIANS;
y2 = p2D[0] * DistanceUtils.DEGREES_TO_RADIANS;
x2 = p2D[1] * DistanceUtils.DEGREES_TO_RADIANS;
} else {
y1 = p1D[0];
x1 = p1D[1];
y2 = p2D[0];
x2 = p2D[1];
}
return DistanceUtils.distHaversineRAD(y1,x1,y2,x2)*radius;
}
示例13: parse
import org.apache.lucene.queries.function.FunctionValues; //导入依赖的package包/类
@Override
public ValueSource parse(FunctionQParser fp) throws SyntaxError {
ValueSource a = fp.parseValueSource();
ValueSource b = fp.parseValueSource();
return new DualFloatFunction(a, b) {
@Override
protected String name() {
return "sub";
}
@Override
protected float func(int doc, FunctionValues aVals, FunctionValues bVals) {
return aVals.floatVal(doc) - bVals.floatVal(doc);
}
};
}
示例14: parse
import org.apache.lucene.queries.function.FunctionValues; //导入依赖的package包/类
@Override
public ValueSource parse(FunctionQParser fp) throws SyntaxError {
ValueSource source = fp.parseValueSource();
final float nvl = fp.parseFloat();
return new SimpleFloatFunction(source) {
@Override
protected String name() {
return "nvl";
}
@Override
protected float func(int doc, FunctionValues vals) {
float v = vals.floatVal(doc);
if (v == nvlFloatValue) {
return nvl;
} else {
return v;
}
}
};
}
示例15: getValues
import org.apache.lucene.queries.function.FunctionValues; //导入依赖的package包/类
@Override
public FunctionValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
Map<String, FunctionValues> valuesCache = (Map<String, FunctionValues>)context.get("valuesCache");
if (valuesCache == null) {
valuesCache = new HashMap<String, FunctionValues>();
context = new HashMap(context);
context.put("valuesCache", valuesCache);
}
FunctionValues[] externalValues = new FunctionValues[expression.variables.length];
for (int i = 0; i < variables.length; ++i) {
String externalName = expression.variables[i];
FunctionValues values = valuesCache.get(externalName);
if (values == null) {
values = variables[i].getValues(context, readerContext);
if (values == null) {
throw new RuntimeException("Internal error. External (" + externalName + ") does not exist.");
}
valuesCache.put(externalName, values);
}
externalValues[i] = values;
}
return new ExpressionFunctionValues(this, expression, externalValues);
}