use of org.apache.lucene.search.DoubleValues in project lucene-solr by apache.
the class ExpressionValueSource method explain.
@Override
public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException {
Explanation[] explanations = new Explanation[variables.length];
DoubleValues dv = getValues(ctx, DoubleValuesSource.constant(scoreExplanation.getValue()).getValues(ctx, null));
if (dv.advanceExact(docId) == false) {
return Explanation.noMatch(expression.sourceText);
}
int i = 0;
for (DoubleValuesSource var : variables) {
explanations[i++] = var.explain(ctx, docId, scoreExplanation);
}
return Explanation.match((float) dv.doubleValue(), expression.sourceText + ", computed from:", explanations);
}
use of org.apache.lucene.search.DoubleValues in project lucene-solr by apache.
the class JavascriptCompiler method unusedTestCompile.
/**
* This method is unused, it is just here to make sure that the function signatures don't change.
* If this method fails to compile, you also have to change the byte code generator to correctly
* use the FunctionValues class.
*/
@SuppressWarnings({ "unused", "null" })
private static void unusedTestCompile() throws IOException {
DoubleValues f = null;
double ret = f.doubleValue();
}
use of org.apache.lucene.search.DoubleValues in project lucene-solr by apache.
the class TestExpressionValueSource method testDoubleValuesSourceTypes.
public void testDoubleValuesSourceTypes() throws Exception {
Expression expr = JavascriptCompiler.compile("2*popularity + count");
SimpleBindings bindings = new SimpleBindings();
bindings.add(new SortField("popularity", SortField.Type.LONG));
bindings.add(new SortField("count", SortField.Type.LONG));
DoubleValuesSource vs = expr.getDoubleValuesSource(bindings);
assertEquals(1, reader.leaves().size());
LeafReaderContext leaf = reader.leaves().get(0);
DoubleValues values = vs.getValues(leaf, null);
assertTrue(values.advanceExact(0));
assertEquals(10, values.doubleValue(), 0);
assertTrue(values.advanceExact(1));
assertEquals(41, values.doubleValue(), 0);
assertTrue(values.advanceExact(2));
assertEquals(4, values.doubleValue(), 0);
}
use of org.apache.lucene.search.DoubleValues in project lucene-solr by apache.
the class TaxonomyFacetSumValueSource method sumValues.
private void sumValues(List<MatchingDocs> matchingDocs, boolean keepScores, DoubleValuesSource valueSource) throws IOException {
IntsRef scratch = new IntsRef();
for (MatchingDocs hits : matchingDocs) {
OrdinalsReader.OrdinalsSegmentReader ords = ordinalsReader.getReader(hits.context);
DoubleValues scores = keepScores ? scores(hits) : null;
DoubleValues functionValues = valueSource.getValues(hits.context, scores);
DocIdSetIterator docs = hits.bits.iterator();
int doc;
while ((doc = docs.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
ords.get(doc, scratch);
if (functionValues.advanceExact(doc)) {
float value = (float) functionValues.doubleValue();
for (int i = 0; i < scratch.length; i++) {
values[scratch.ints[i]] += value;
}
}
}
}
rollup();
}
use of org.apache.lucene.search.DoubleValues in project lucene-solr by apache.
the class ValueSource method asLongValuesSource.
/**
* Expose this ValueSource as a LongValuesSource
*/
public LongValuesSource asLongValuesSource() {
return new LongValuesSource() {
@Override
public LongValues getValues(LeafReaderContext ctx, DoubleValues scores) throws IOException {
Map context = new IdentityHashMap<>();
FakeScorer scorer = new FakeScorer();
context.put("scorer", scorer);
final FunctionValues fv = ValueSource.this.getValues(context, ctx);
return new LongValues() {
@Override
public long longValue() throws IOException {
return fv.longVal(scorer.current);
}
@Override
public boolean advanceExact(int doc) throws IOException {
scorer.current = doc;
if (scores != null && scores.advanceExact(doc))
scorer.score = (float) scores.doubleValue();
else
scorer.score = 0;
return fv.exists(doc);
}
};
}
@Override
public boolean needsScores() {
return false;
}
};
}
Aggregations