Exemplo n.º 1
0
        //-------------------------------------------------------------------------------
        //
        //-------------------------------------------------------------------------------

        /// <summary>
        /// Constructs a query to retrieve documents that fully contain the input envelope.
        /// </summary>
        /// <param name="bbox"></param>
        /// <returns>The spatial query</returns>
        protected Query MakeContains(Rectangle bbox)
        {
            // general case
            // docMinX <= queryExtent.GetMinX() AND docMinY <= queryExtent.GetMinY() AND docMaxX >= queryExtent.GetMaxX() AND docMaxY >= queryExtent.GetMaxY()

            // Y conditions
            // docMinY <= queryExtent.GetMinY() AND docMaxY >= queryExtent.GetMaxY()
            Query qMinY       = NumericRangeQueryHelper.NewDoubleRange(field_minY, precisionStep, null, bbox.GetMinY(), false, true);
            Query qMaxY       = NumericRangeQueryHelper.NewDoubleRange(field_maxY, precisionStep, bbox.GetMaxY(), null, true, false);
            Query yConditions = this.MakeQuery(new Query[] { qMinY, qMaxY }, BooleanClause.Occur.MUST);

            // X conditions
            Query xConditions = null;

            // queries that do not cross the date line
            if (!bbox.GetCrossesDateLine())
            {
                // X Conditions for documents that do not cross the date line,
                // documents that contain the min X and max X of the query envelope,
                // docMinX <= queryExtent.GetMinX() AND docMaxX >= queryExtent.GetMaxX()
                Query qMinX   = NumericRangeQueryHelper.NewDoubleRange(field_minX, precisionStep, null, bbox.GetMinX(), false, true);
                Query qMaxX   = NumericRangeQueryHelper.NewDoubleRange(field_maxX, precisionStep, bbox.GetMaxX(), null, true, false);
                Query qMinMax = this.MakeQuery(new Query[] { qMinX, qMaxX }, BooleanClause.Occur.MUST);
                Query qNonXDL = this.MakeXDL(false, qMinMax);

                // X Conditions for documents that cross the date line,
                // the left portion of the document contains the min X of the query
                // OR the right portion of the document contains the max X of the query,
                // docMinXLeft <= queryExtent.GetMinX() OR docMaxXRight >= queryExtent.GetMaxX()
                Query qXDLLeft      = NumericRangeQueryHelper.NewDoubleRange(field_minX, precisionStep, null, bbox.GetMinX(), false, true);
                Query qXDLRight     = NumericRangeQueryHelper.NewDoubleRange(field_maxX, precisionStep, bbox.GetMaxX(), null, true, false);
                Query qXDLLeftRight = this.MakeQuery(new Query[] { qXDLLeft, qXDLRight }, BooleanClause.Occur.SHOULD);
                Query qXDL          = this.MakeXDL(true, qXDLLeftRight);

                // apply the non-XDL and XDL conditions
                xConditions = this.MakeQuery(new Query[] { qNonXDL, qXDL }, BooleanClause.Occur.SHOULD);

                // queries that cross the date line
            }
            else
            {
                // No need to search for documents that do not cross the date line

                // X Conditions for documents that cross the date line,
                // the left portion of the document contains the min X of the query
                // AND the right portion of the document contains the max X of the query,
                // docMinXLeft <= queryExtent.GetMinX() AND docMaxXRight >= queryExtent.GetMaxX()
                Query qXDLLeft      = NumericRangeQueryHelper.NewDoubleRange(field_minX, precisionStep, null, bbox.GetMinX(), false, true);
                Query qXDLRight     = NumericRangeQueryHelper.NewDoubleRange(field_maxX, precisionStep, bbox.GetMaxX(), null, true, false);
                Query qXDLLeftRight = this.MakeQuery(new Query[] { qXDLLeft, qXDLRight }, BooleanClause.Occur.MUST);

                xConditions = this.MakeXDL(true, qXDLLeftRight);
            }

            // both X and Y conditions must occur
            return(this.MakeQuery(new Query[] { xConditions, yConditions }, BooleanClause.Occur.MUST));
        }
 private NumericRangeQuery RangeQuery(String fieldName, double?min, double?max)
 {
     return(NumericRangeQueryHelper.NewDoubleRange(
                fieldName,
                precisionStep,
                min,
                max,
                true,
                true)); //inclusive
 }
Exemplo n.º 3
0
        /*
         * Constructs a query to retrieve documents that equal the input envelope.
         *
         * @return the spatial query
         */
        public Query MakeEquals(Rectangle bbox)
        {
            // docMinX = queryExtent.GetMinX() AND docMinY = queryExtent.GetMinY() AND docMaxX = queryExtent.GetMaxX() AND docMaxY = queryExtent.GetMaxY()
            Query qMinX = NumericRangeQueryHelper.NewDoubleRange(field_minX, precisionStep, bbox.GetMinX(), bbox.GetMinX(), true, true);
            Query qMinY = NumericRangeQueryHelper.NewDoubleRange(field_minY, precisionStep, bbox.GetMinY(), bbox.GetMinY(), true, true);
            Query qMaxX = NumericRangeQueryHelper.NewDoubleRange(field_maxX, precisionStep, bbox.GetMaxX(), bbox.GetMaxX(), true, true);
            Query qMaxY = NumericRangeQueryHelper.NewDoubleRange(field_maxY, precisionStep, bbox.GetMaxY(), bbox.GetMaxY(), true, true);

            var bq = new BooleanQuery();

            bq.Add(qMinX, BooleanClause.Occur.MUST);
            bq.Add(qMinY, BooleanClause.Occur.MUST);
            bq.Add(qMaxX, BooleanClause.Occur.MUST);
            bq.Add(qMaxY, BooleanClause.Occur.MUST);

            return(bq);
        }
Exemplo n.º 4
0
        /*
         * Constructs a query to retrieve documents are fully within the input envelope.
         *
         * @return the spatial query
         */
        Query MakeWithin(Rectangle bbox)
        {
            // general case
            // docMinX >= queryExtent.GetMinX() AND docMinY >= queryExtent.GetMinY() AND docMaxX <= queryExtent.GetMaxX() AND docMaxY <= queryExtent.GetMaxY()

            // Y conditions
            // docMinY >= queryExtent.GetMinY() AND docMaxY <= queryExtent.GetMaxY()

            Query qMinY       = NumericRangeQueryHelper.NewDoubleRange(field_minY, precisionStep, bbox.GetMinY(), null, true, false);
            Query qMaxY       = NumericRangeQueryHelper.NewDoubleRange(field_maxY, precisionStep, null, bbox.GetMaxY(), false, true);
            Query yConditions = this.MakeQuery(new Query[] { qMinY, qMaxY }, BooleanClause.Occur.MUST);

            // X conditions
            Query xConditions = null;

            // X Conditions for documents that cross the date line,
            // the left portion of the document must be within the left portion of the query,
            // AND the right portion of the document must be within the right portion of the query
            // docMinXLeft >= queryExtent.GetMinX() AND docMaxXLeft <= 180.0
            // AND docMinXRight >= -180.0 AND docMaxXRight <= queryExtent.GetMaxX()
            Query qXDLLeft      = NumericRangeQueryHelper.NewDoubleRange(field_minX, precisionStep, bbox.GetMinX(), null, true, false);
            Query qXDLRight     = NumericRangeQueryHelper.NewDoubleRange(field_maxX, precisionStep, null, bbox.GetMaxX(), false, true);
            Query qXDLLeftRight = this.MakeQuery(new Query[] { qXDLLeft, qXDLRight }, BooleanClause.Occur.MUST);
            Query qXDL          = this.MakeXDL(true, qXDLLeftRight);

            // queries that do not cross the date line
            if (!bbox.GetCrossesDateLine())
            {
                // X Conditions for documents that do not cross the date line,
                // docMinX >= queryExtent.GetMinX() AND docMaxX <= queryExtent.GetMaxX()
                Query qMinX   = NumericRangeQueryHelper.NewDoubleRange(field_minX, precisionStep, bbox.GetMinX(), null, true, false);
                Query qMaxX   = NumericRangeQueryHelper.NewDoubleRange(field_maxX, precisionStep, null, bbox.GetMaxX(), false, true);
                Query qMinMax = this.MakeQuery(new Query[] { qMinX, qMaxX }, BooleanClause.Occur.MUST);
                Query qNonXDL = this.MakeXDL(false, qMinMax);

                // apply the non-XDL or XDL X conditions
                if ((bbox.GetMinX() <= -180.0) && bbox.GetMaxX() >= 180.0)
                {
                    xConditions = this.MakeQuery(new Query[] { qNonXDL, qXDL }, BooleanClause.Occur.SHOULD);
                }
                else
                {
                    xConditions = qNonXDL;
                }

                // queries that cross the date line
            }
            else
            {
                // X Conditions for documents that do not cross the date line

                // the document should be within the left portion of the query
                // docMinX >= queryExtent.GetMinX() AND docMaxX <= 180.0
                Query qMinXLeft = NumericRangeQueryHelper.NewDoubleRange(field_minX, precisionStep, bbox.GetMinX(), null, true, false);
                Query qMaxXLeft = NumericRangeQueryHelper.NewDoubleRange(field_maxX, precisionStep, null, 180.0, false, true);
                Query qLeft     = this.MakeQuery(new Query[] { qMinXLeft, qMaxXLeft }, BooleanClause.Occur.MUST);

                // the document should be within the right portion of the query
                // docMinX >= -180.0 AND docMaxX <= queryExtent.GetMaxX()
                Query qMinXRight = NumericRangeQueryHelper.NewDoubleRange(field_minX, precisionStep, -180.0, null, true, false);
                Query qMaxXRight = NumericRangeQueryHelper.NewDoubleRange(field_maxX, precisionStep, null, bbox.GetMaxX(), false, true);
                Query qRight     = this.MakeQuery(new Query[] { qMinXRight, qMaxXRight }, BooleanClause.Occur.MUST);

                // either left or right conditions should occur,
                // apply the left and right conditions to documents that do not cross the date line
                Query qLeftRight = this.MakeQuery(new Query[] { qLeft, qRight }, BooleanClause.Occur.SHOULD);
                Query qNonXDL    = this.MakeXDL(false, qLeftRight);

                // apply the non-XDL and XDL conditions
                xConditions = this.MakeQuery(new Query[] { qNonXDL, qXDL }, BooleanClause.Occur.SHOULD);
            }

            // both X and Y conditions must occur
            return(this.MakeQuery(new Query[] { xConditions, yConditions }, BooleanClause.Occur.MUST));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Constructs a query to retrieve documents that are disjoint to the input envelope.
        /// </summary>
        /// <param name="bbox"></param>
        /// <returns>the spatial query</returns>
        Query MakeDisjoint(Rectangle bbox)
        {
            // general case
            // docMinX > queryExtent.GetMaxX() OR docMaxX < queryExtent.GetMinX() OR docMinY > queryExtent.GetMaxY() OR docMaxY < queryExtent.GetMinY()

            // Y conditions
            // docMinY > queryExtent.GetMaxY() OR docMaxY < queryExtent.GetMinY()
            Query qMinY       = NumericRangeQueryHelper.NewDoubleRange(field_minY, precisionStep, bbox.GetMaxY(), null, false, false);
            Query qMaxY       = NumericRangeQueryHelper.NewDoubleRange(field_maxY, precisionStep, null, bbox.GetMinY(), false, false);
            Query yConditions = this.MakeQuery(new Query[] { qMinY, qMaxY }, BooleanClause.Occur.SHOULD);

            // X conditions
            Query xConditions = null;

            // queries that do not cross the date line
            if (!bbox.GetCrossesDateLine())
            {
                // X Conditions for documents that do not cross the date line,
                // docMinX > queryExtent.GetMaxX() OR docMaxX < queryExtent.GetMinX()
                Query qMinX   = NumericRangeQueryHelper.NewDoubleRange(field_minX, precisionStep, bbox.GetMaxX(), null, false, false);
                Query qMaxX   = NumericRangeQueryHelper.NewDoubleRange(field_maxX, precisionStep, null, bbox.GetMinX(), false, false);
                Query qMinMax = this.MakeQuery(new Query[] { qMinX, qMaxX }, BooleanClause.Occur.SHOULD);
                Query qNonXDL = this.MakeXDL(false, qMinMax);

                // X Conditions for documents that cross the date line,
                // both the left and right portions of the document must be disjoint to the query
                // (docMinXLeft > queryExtent.GetMaxX() OR docMaxXLeft < queryExtent.GetMinX()) AND
                // (docMinXRight > queryExtent.GetMaxX() OR docMaxXRight < queryExtent.GetMinX())
                // where: docMaxXLeft = 180.0, docMinXRight = -180.0
                // (docMaxXLeft  < queryExtent.GetMinX()) equates to (180.0  < queryExtent.GetMinX()) and is ignored
                // (docMinXRight > queryExtent.GetMaxX()) equates to (-180.0 > queryExtent.GetMaxX()) and is ignored
                Query qMinXLeft  = NumericRangeQueryHelper.NewDoubleRange(field_minX, precisionStep, bbox.GetMaxX(), null, false, false);
                Query qMaxXRight = NumericRangeQueryHelper.NewDoubleRange(field_maxX, precisionStep, null, bbox.GetMinX(), false, false);
                Query qLeftRight = this.MakeQuery(new Query[] { qMinXLeft, qMaxXRight }, BooleanClause.Occur.MUST);
                Query qXDL       = this.MakeXDL(true, qLeftRight);

                // apply the non-XDL and XDL conditions
                xConditions = this.MakeQuery(new Query[] { qNonXDL, qXDL }, BooleanClause.Occur.SHOULD);

                // queries that cross the date line
            }
            else
            {
                // X Conditions for documents that do not cross the date line,
                // the document must be disjoint to both the left and right query portions
                // (docMinX > queryExtent.GetMaxX()Left OR docMaxX < queryExtent.GetMinX()) AND (docMinX > queryExtent.GetMaxX() OR docMaxX < queryExtent.GetMinX()Left)
                // where: queryExtent.GetMaxX()Left = 180.0, queryExtent.GetMinX()Left = -180.0
                Query qMinXLeft  = NumericRangeQueryHelper.NewDoubleRange(field_minX, precisionStep, 180.0, null, false, false);
                Query qMaxXLeft  = NumericRangeQueryHelper.NewDoubleRange(field_maxX, precisionStep, null, bbox.GetMinX(), false, false);
                Query qMinXRight = NumericRangeQueryHelper.NewDoubleRange(field_minX, precisionStep, bbox.GetMaxX(), null, false, false);
                Query qMaxXRight = NumericRangeQueryHelper.NewDoubleRange(field_maxX, precisionStep, null, -180.0, false, false);
                Query qLeft      = this.MakeQuery(new Query[] { qMinXLeft, qMaxXLeft }, BooleanClause.Occur.SHOULD);
                Query qRight     = this.MakeQuery(new Query[] { qMinXRight, qMaxXRight }, BooleanClause.Occur.SHOULD);
                Query qLeftRight = this.MakeQuery(new Query[] { qLeft, qRight }, BooleanClause.Occur.MUST);

                // No need to search for documents that do not cross the date line

                xConditions = this.MakeXDL(false, qLeftRight);
            }

            // either X or Y conditions should occur
            return(this.MakeQuery(new Query[] { xConditions, yConditions }, BooleanClause.Occur.SHOULD));
        }