Search in sources :

Example 6 with DoubleValues

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);
}
Also used : Explanation(org.apache.lucene.search.Explanation) DoubleValues(org.apache.lucene.search.DoubleValues) DoubleValuesSource(org.apache.lucene.search.DoubleValuesSource)

Example 7 with DoubleValues

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();
}
Also used : DoubleValues(org.apache.lucene.search.DoubleValues)

Example 8 with DoubleValues

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);
}
Also used : DoubleValues(org.apache.lucene.search.DoubleValues) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) SortField(org.apache.lucene.search.SortField) DoubleValuesSource(org.apache.lucene.search.DoubleValuesSource)

Example 9 with DoubleValues

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();
}
Also used : MatchingDocs(org.apache.lucene.facet.FacetsCollector.MatchingDocs) DoubleValues(org.apache.lucene.search.DoubleValues) IntsRef(org.apache.lucene.util.IntsRef) DocIdSetIterator(org.apache.lucene.search.DocIdSetIterator)

Example 10 with DoubleValues

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;
        }
    };
}
Also used : IdentityHashMap(java.util.IdentityHashMap) DoubleValues(org.apache.lucene.search.DoubleValues) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) LongValues(org.apache.lucene.search.LongValues) LongValuesSource(org.apache.lucene.search.LongValuesSource) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

DoubleValues (org.apache.lucene.search.DoubleValues)10 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)5 DoubleValuesSource (org.apache.lucene.search.DoubleValuesSource)4 HashMap (java.util.HashMap)3 DocIdSetIterator (org.apache.lucene.search.DocIdSetIterator)3 Explanation (org.apache.lucene.search.Explanation)3 IdentityHashMap (java.util.IdentityHashMap)2 Map (java.util.Map)2 MatchingDocs (org.apache.lucene.facet.FacetsCollector.MatchingDocs)2 IndexSearcher (org.apache.lucene.search.IndexSearcher)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Document (org.apache.lucene.document.Document)1 DrillDownQuery (org.apache.lucene.facet.DrillDownQuery)1 DrillSideways (org.apache.lucene.facet.DrillSideways)1 DrillSidewaysResult (org.apache.lucene.facet.DrillSideways.DrillSidewaysResult)1 Facets (org.apache.lucene.facet.Facets)1 FacetsCollector (org.apache.lucene.facet.FacetsCollector)1 FacetsConfig (org.apache.lucene.facet.FacetsConfig)1 MultiFacets (org.apache.lucene.facet.MultiFacets)1 IndexReader (org.apache.lucene.index.IndexReader)1