Search in sources :

Example 11 with DoubleDocValues

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

the class ShapeAreaValueSource method getValues.

@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
    final FunctionValues shapeValues = shapeValueSource.getValues(context, readerContext);
    return new DoubleDocValues(this) {

        @Override
        public double doubleVal(int doc) throws IOException {
            Shape shape = (Shape) shapeValues.objectVal(doc);
            if (shape == null || shape.isEmpty())
                //or NaN?
                return 0;
            //   assuming ctx.isGeo()
            return shape.getArea(geoArea ? ctx : null) * multiplier;
        }

        @Override
        public boolean exists(int doc) throws IOException {
            return shapeValues.exists(doc);
        }

        @Override
        public Explanation explain(int doc) throws IOException {
            Explanation exp = super.explain(doc);
            List<Explanation> details = new ArrayList<>(Arrays.asList(exp.getDetails()));
            details.add(shapeValues.explain(doc));
            return Explanation.match(exp.getValue(), exp.getDescription(), details);
        }
    };
}
Also used : Shape(org.locationtech.spatial4j.shape.Shape) Explanation(org.apache.lucene.search.Explanation) DoubleDocValues(org.apache.lucene.queries.function.docvalues.DoubleDocValues) ArrayList(java.util.ArrayList) FunctionValues(org.apache.lucene.queries.function.FunctionValues)

Example 12 with DoubleDocValues

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

the class BBoxSimilarityValueSource method getValues.

@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
    final FunctionValues shapeValues = bboxValueSource.getValues(context, readerContext);
    return new DoubleDocValues(this) {

        @Override
        public double doubleVal(int doc) throws IOException {
            //? limit to Rect or call getBoundingBox()? latter would encourage bad practice
            final Rectangle rect = (Rectangle) shapeValues.objectVal(doc);
            return rect == null ? 0 : score(rect, null);
        }

        @Override
        public boolean exists(int doc) throws IOException {
            return shapeValues.exists(doc);
        }

        @Override
        public Explanation explain(int doc) throws IOException {
            final Rectangle rect = (Rectangle) shapeValues.objectVal(doc);
            if (rect == null) {
                return Explanation.noMatch("no rect");
            }
            AtomicReference<Explanation> explanation = new AtomicReference<>();
            score(rect, explanation);
            return explanation.get();
        }
    };
}
Also used : Explanation(org.apache.lucene.search.Explanation) DoubleDocValues(org.apache.lucene.queries.function.docvalues.DoubleDocValues) Rectangle(org.locationtech.spatial4j.shape.Rectangle) FunctionValues(org.apache.lucene.queries.function.FunctionValues) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 13 with DoubleDocValues

use of org.apache.lucene.queries.function.docvalues.DoubleDocValues in project elasticsearch by elastic.

the class FieldDataValueSource method getValues.

@Override
// ValueSource uses a rawtype
@SuppressWarnings("rawtypes")
public FunctionValues getValues(Map context, LeafReaderContext leaf) throws IOException {
    AtomicNumericFieldData leafData = (AtomicNumericFieldData) fieldData.load(leaf);
    NumericDoubleValues docValues = multiValueMode.select(leafData.getDoubleValues(), 0d);
    return new DoubleDocValues(this) {

        @Override
        public double doubleVal(int doc) {
            return docValues.get(doc);
        }
    };
}
Also used : DoubleDocValues(org.apache.lucene.queries.function.docvalues.DoubleDocValues) NumericDoubleValues(org.elasticsearch.index.fielddata.NumericDoubleValues) AtomicNumericFieldData(org.elasticsearch.index.fielddata.AtomicNumericFieldData)

Example 14 with DoubleDocValues

use of org.apache.lucene.queries.function.docvalues.DoubleDocValues in project elasticsearch by elastic.

the class GeoEmptyValueSource method getValues.

@Override
// ValueSource uses a rawtype
@SuppressWarnings("rawtypes")
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;
            }
        }
    };
}
Also used : AtomicGeoPointFieldData(org.elasticsearch.index.fielddata.AtomicGeoPointFieldData) DoubleDocValues(org.apache.lucene.queries.function.docvalues.DoubleDocValues) MultiGeoPointValues(org.elasticsearch.index.fielddata.MultiGeoPointValues)

Example 15 with DoubleDocValues

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

the class DistanceToShapeValueSource method getValues.

@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
    final FunctionValues shapeValues = shapeValueSource.getValues(context, readerContext);
    return new DoubleDocValues(this) {

        @Override
        public double doubleVal(int doc) throws IOException {
            Shape shape = (Shape) shapeValues.objectVal(doc);
            if (shape == null || shape.isEmpty())
                return nullValue;
            Point pt = shape.getCenter();
            return distCalc.distance(queryPoint, pt) * multiplier;
        }

        @Override
        public Explanation explain(int doc) throws IOException {
            Explanation exp = super.explain(doc);
            List<Explanation> details = new ArrayList<>(Arrays.asList(exp.getDetails()));
            details.add(shapeValues.explain(doc));
            return Explanation.match(exp.getValue(), exp.getDescription(), details);
        }
    };
}
Also used : Shape(org.locationtech.spatial4j.shape.Shape) Explanation(org.apache.lucene.search.Explanation) DoubleDocValues(org.apache.lucene.queries.function.docvalues.DoubleDocValues) ArrayList(java.util.ArrayList) FunctionValues(org.apache.lucene.queries.function.FunctionValues) Point(org.locationtech.spatial4j.shape.Point)

Aggregations

DoubleDocValues (org.apache.lucene.queries.function.docvalues.DoubleDocValues)19 FunctionValues (org.apache.lucene.queries.function.FunctionValues)9 AtomicNumericFieldData (org.elasticsearch.index.fielddata.AtomicNumericFieldData)5 Explanation (org.apache.lucene.search.Explanation)3 AtomicGeoPointFieldData (org.elasticsearch.index.fielddata.AtomicGeoPointFieldData)3 MultiGeoPointValues (org.elasticsearch.index.fielddata.MultiGeoPointValues)3 NumericDoubleValues (org.elasticsearch.index.fielddata.NumericDoubleValues)3 ArrayList (java.util.ArrayList)2 MutableValueDouble (org.apache.lucene.util.mutable.MutableValueDouble)2 SortedNumericDoubleValues (org.elasticsearch.index.fielddata.SortedNumericDoubleValues)2 Shape (org.locationtech.spatial4j.shape.Shape)2 Calendar (java.util.Calendar)1 Map (java.util.Map)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)1 NumericDocValues (org.apache.lucene.index.NumericDocValues)1 SortedDocValues (org.apache.lucene.index.SortedDocValues)1 SortedSetDocValues (org.apache.lucene.index.SortedSetDocValues)1 SortedSetFieldSource (org.apache.lucene.queries.function.valuesource.SortedSetFieldSource)1 BytesRef (org.apache.lucene.util.BytesRef)1