Ejemplo n.º 1
0
        protected virtual Query MakeQueryFromShape(IShape shape)
        {
            SpatialArgs args = new SpatialArgs(m_operation, shape);

            if (!double.IsNaN(m_distErrPct))
            {
                args.DistErrPct = m_distErrPct;
            }

            if (m_score)
            {
                ValueSource valueSource = m_strategy.MakeDistanceValueSource(shape.Center);
                return(new CustomScoreQuery(m_strategy.MakeQuery(args), new FunctionQuery(valueSource)));
            }
            else
            {
                //strategy.makeQuery() could potentially score (isn't well defined) so instead we call
                // makeFilter() and wrap

                Filter filter = m_strategy.MakeFilter(args);
                if (filter is QueryWrapperFilter queryWrapperFilter)
                {
                    return(queryWrapperFilter.Query);
                }
                else
                {
                    return(new ConstantScoreQuery(filter));
                }
            }
        }
Ejemplo n.º 2
0
        public Query MakeQuery(Query existingQuery, SpatialStrategy spatialStrategy, string shapeWKT, SpatialRelation relation,
                               double distanceErrorPct = 0.025, SpatialUnits?unitOverride = null)
        {
            SpatialOperation spatialOperation;
            var shape = ReadShape(shapeWKT, unitOverride);

            switch (relation)
            {
            case SpatialRelation.Within:
                spatialOperation = SpatialOperation.IsWithin;
                break;

            case SpatialRelation.Contains:
                spatialOperation = SpatialOperation.Contains;
                break;

            case SpatialRelation.Disjoint:
                spatialOperation = SpatialOperation.IsDisjointTo;
                break;

            case SpatialRelation.Intersects:
                spatialOperation = SpatialOperation.Intersects;
                break;

            case SpatialRelation.Nearby:
                // only sort by this, do not filter
                return(new FunctionQuery(spatialStrategy.MakeDistanceValueSource(shape.GetCenter())));

            default:
                throw new ArgumentOutOfRangeException("relation");
            }
            var args = new SpatialArgs(spatialOperation, shape)
            {
                DistErrPct = distanceErrorPct
            };

            if (existingQuery is MatchAllDocsQuery)
            {
                return(new CustomScoreQuery(spatialStrategy.MakeQuery(args), new ValueSourceQuery(spatialStrategy.MakeRecipDistanceValueSource(shape))));
            }
            return(spatialStrategy.MakeQuery(args));
        }
Ejemplo n.º 3
0
        public static Query MakeQuery(SpatialStrategy spatialStrategy, string shapeWKT, SpatialRelation relation,
                                      double distanceErrorPct = 0.025)
        {
            SpatialOperation spatialOperation;
            var shape = ReadShape(shapeWKT);

            switch (relation)
            {
            case SpatialRelation.Within:
                spatialOperation = SpatialOperation.IsWithin;
                break;

            case SpatialRelation.Contains:
                spatialOperation = SpatialOperation.Contains;
                break;

            case SpatialRelation.Disjoint:
                spatialOperation = SpatialOperation.IsDisjointTo;
                break;

            case SpatialRelation.Intersects:
                spatialOperation = SpatialOperation.Intersects;
                break;

            case SpatialRelation.Nearby:
                // only sort by this, do not filter
                return(new FunctionQuery(spatialStrategy.MakeDistanceValueSource(shape.GetCenter())));

            default:
                throw new ArgumentOutOfRangeException("relation");
            }
            var args = new SpatialArgs(spatialOperation, shape)
            {
                DistErrPct = distanceErrorPct
            };

            return(spatialStrategy.MakeQuery(args));
        }