Search in sources :

Example 26 with FunctionValues

use of org.apache.lucene.queries.function.FunctionValues in project lucene-solr by apache.

the class DummyValueSourceParser method parse.

@Override
public ValueSource parse(FunctionQParser fp) throws SyntaxError {
    ValueSource source = fp.parseValueSource();
    ValueSource result = new SimpleFloatFunction(source) {

        @Override
        protected String name() {
            return "foo";
        }

        @Override
        protected float func(int doc, FunctionValues vals) {
            float result = 0;
            return result;
        }
    };
    return result;
}
Also used : ValueSource(org.apache.lucene.queries.function.ValueSource) SimpleFloatFunction(org.apache.lucene.queries.function.valuesource.SimpleFloatFunction) FunctionValues(org.apache.lucene.queries.function.FunctionValues)

Example 27 with FunctionValues

use of org.apache.lucene.queries.function.FunctionValues in project lucene-solr by apache.

the class NvlValueSourceParser method parse.

@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) throws IOException {
            float v = vals.floatVal(doc);
            if (v == nvlFloatValue) {
                return nvl;
            } else {
                return v;
            }
        }
    };
}
Also used : ValueSource(org.apache.lucene.queries.function.ValueSource) SimpleFloatFunction(org.apache.lucene.queries.function.valuesource.SimpleFloatFunction) FunctionValues(org.apache.lucene.queries.function.FunctionValues)

Example 28 with FunctionValues

use of org.apache.lucene.queries.function.FunctionValues in project lucene-solr by apache.

the class TestIndexSearcher method getStringVal.

private String getStringVal(SolrQueryRequest sqr, String field, int doc) throws IOException {
    SchemaField sf = sqr.getSchema().getField(field);
    ValueSource vs = sf.getType().getValueSource(sf, null);
    Map context = ValueSource.newContext(sqr.getSearcher());
    vs.createWeight(context, sqr.getSearcher());
    IndexReaderContext topReaderContext = sqr.getSearcher().getTopReaderContext();
    List<LeafReaderContext> leaves = topReaderContext.leaves();
    int idx = ReaderUtil.subIndex(doc, leaves);
    LeafReaderContext leaf = leaves.get(idx);
    FunctionValues vals = vs.getValues(context, leaf);
    return vals.strVal(doc - leaf.docBase);
}
Also used : SchemaField(org.apache.solr.schema.SchemaField) ValueSource(org.apache.lucene.queries.function.ValueSource) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) FunctionValues(org.apache.lucene.queries.function.FunctionValues) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) IndexReaderContext(org.apache.lucene.index.IndexReaderContext)

Example 29 with FunctionValues

use of org.apache.lucene.queries.function.FunctionValues in project lucene-solr by apache.

the class IndexFingerprint method getFingerprint.

public static IndexFingerprint getFingerprint(SolrIndexSearcher searcher, LeafReaderContext ctx, Long maxVersion) throws IOException {
    SchemaField versionField = VersionInfo.getAndCheckVersionField(searcher.getSchema());
    ValueSource vs = versionField.getType().getValueSource(versionField, null);
    Map funcContext = ValueSource.newContext(searcher);
    vs.createWeight(funcContext, searcher);
    IndexFingerprint f = new IndexFingerprint();
    f.maxVersionSpecified = maxVersion;
    f.maxDoc = ctx.reader().maxDoc();
    f.numDocs = ctx.reader().numDocs();
    int maxDoc = ctx.reader().maxDoc();
    Bits liveDocs = ctx.reader().getLiveDocs();
    FunctionValues fv = vs.getValues(funcContext, ctx);
    for (int doc = 0; doc < maxDoc; doc++) {
        if (liveDocs != null && !liveDocs.get(doc))
            continue;
        long v = fv.longVal(doc);
        f.maxVersionEncountered = Math.max(v, f.maxVersionEncountered);
        if (v <= f.maxVersionSpecified) {
            f.maxInHash = Math.max(v, f.maxInHash);
            f.versionsHash += Hash.fmix64(v);
            f.numVersions++;
        }
    }
    return f;
}
Also used : SchemaField(org.apache.solr.schema.SchemaField) ValueSource(org.apache.lucene.queries.function.ValueSource) Bits(org.apache.lucene.util.Bits) FunctionValues(org.apache.lucene.queries.function.FunctionValues) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 30 with FunctionValues

use of org.apache.lucene.queries.function.FunctionValues in project lucene-solr by apache.

the class BBoxValueSource method getValues.

@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
    LeafReader reader = readerContext.reader();
    final NumericDocValues minX = DocValues.getNumeric(reader, strategy.field_minX);
    final NumericDocValues minY = DocValues.getNumeric(reader, strategy.field_minY);
    final NumericDocValues maxX = DocValues.getNumeric(reader, strategy.field_maxX);
    final NumericDocValues maxY = DocValues.getNumeric(reader, strategy.field_maxY);
    //reused
    final Rectangle rect = strategy.getSpatialContext().makeRectangle(0, 0, 0, 0);
    return new FunctionValues() {

        private int lastDocID = -1;

        private double getDocValue(NumericDocValues values, int doc) throws IOException {
            int curDocID = values.docID();
            if (doc > curDocID) {
                curDocID = values.advance(doc);
            }
            if (doc == curDocID) {
                return Double.longBitsToDouble(values.longValue());
            } else {
                return 0.0;
            }
        }

        @Override
        public Object objectVal(int doc) throws IOException {
            if (doc < lastDocID) {
                throw new AssertionError("docs were sent out-of-order: lastDocID=" + lastDocID + " vs doc=" + doc);
            }
            lastDocID = doc;
            double minXValue = getDocValue(minX, doc);
            if (minX.docID() != doc) {
                return null;
            } else {
                double minYValue = getDocValue(minY, doc);
                double maxXValue = getDocValue(maxX, doc);
                double maxYValue = getDocValue(maxY, doc);
                rect.reset(minXValue, maxXValue, minYValue, maxYValue);
                return rect;
            }
        }

        @Override
        public String strVal(int doc) throws IOException {
            //TODO support WKT output once Spatial4j does
            Object v = objectVal(doc);
            return v == null ? null : v.toString();
        }

        @Override
        public boolean exists(int doc) throws IOException {
            getDocValue(minX, doc);
            return minX.docID() == doc;
        }

        @Override
        public Explanation explain(int doc) throws IOException {
            return Explanation.match(Float.NaN, toString(doc));
        }

        @Override
        public String toString(int doc) throws IOException {
            return description() + '=' + strVal(doc);
        }
    };
}
Also used : NumericDocValues(org.apache.lucene.index.NumericDocValues) LeafReader(org.apache.lucene.index.LeafReader) Rectangle(org.locationtech.spatial4j.shape.Rectangle) FunctionValues(org.apache.lucene.queries.function.FunctionValues)

Aggregations

FunctionValues (org.apache.lucene.queries.function.FunctionValues)45 ValueSource (org.apache.lucene.queries.function.ValueSource)10 DoubleDocValues (org.apache.lucene.queries.function.docvalues.DoubleDocValues)9 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)7 Map (java.util.Map)6 LeafReader (org.apache.lucene.index.LeafReader)6 NumericDocValues (org.apache.lucene.index.NumericDocValues)6 IOException (java.io.IOException)5 FloatDocValues (org.apache.lucene.queries.function.docvalues.FloatDocValues)5 Explanation (org.apache.lucene.search.Explanation)4 ArrayList (java.util.ArrayList)3 Terms (org.apache.lucene.index.Terms)3 BoolDocValues (org.apache.lucene.queries.function.docvalues.BoolDocValues)3 BytesRef (org.apache.lucene.util.BytesRef)3 BytesRefBuilder (org.apache.lucene.util.BytesRefBuilder)3 Point (org.locationtech.spatial4j.shape.Point)3 Rectangle (org.locationtech.spatial4j.shape.Rectangle)3 Date (java.util.Date)2 TermsEnum (org.apache.lucene.index.TermsEnum)2 SimpleFloatFunction (org.apache.lucene.queries.function.valuesource.SimpleFloatFunction)2