Uploaded image for project: 'Lucene - Core'
  1. Lucene - Core
  2. LUCENE-8669

LatLonShape WITHIN queries fail with Multiple search Polygons that share the dateline

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Blocker
    • Resolution: Fixed
    • 7.7, 8.0
    • None
    • None
    • None
    • New, Patch Available

    Description

      LatLonShape.newPolygonQuery does not support dateline crossing polygons. It is therefore up to the calling application / user to split dateline crossing polygons into a MultiPolygon query with two search polygons that share the dateline. This, however, does not produce expected results because EdgeTree.internalComponentRelateTriangle does not differentiate between a triangle that CROSSES or is WITHIN the target polygon. Therefore MultiPolygon WITHIN queries that share the dateline behave as an INTERSECT and will therefore produce incorrect results.

      Consider the following test, for example:

          // index
          // western poly
          Polygon indexPoly1 = new Polygon(
              new double[] {-7.5d, 15d, 15d, 0d, -7.5d},
              new double[] {-180d, -180d, -176d, -176d, -180d}
          );
      
          // eastern poly
          Polygon indexPoly2 = new Polygon(
              new double[] {15d, -7.5d, -15d, -10d, 15d, 15d},
              new double[] {180d, 180d, 176d, 174d, 176d, 180d}
          );
      
          //// index ////
          Field[] fields = LatLonShape.createIndexableFields("test", indexPoly1);
          for (Field f : fields) {
            doc.add(f);
          }
          fields = LatLonShape.createIndexableFields("test", indexPoly2);
          for (Field f : fields) {
            doc.add(f);
          }
          writer.addDocument(doc);
      
          ///// search //////
          Polygon[] searchPoly = new Polygon[] {
              new Polygon(new double[] {-20d, 20d, 20d, -20d, -20d},
                  new double[] {-180d, -180d, -170d, -170d, -180d}),
              new Polygon(new double[] {20d, -20d, -20d, 20d, 20d},
                  new double[] {180d, 180d, 170d, 170d, 180d})
          };
      
          Query q = LatLonShape.newPolygonQuery("test", QueryRelation.WITHIN, searchPoly);
          assertEquals(1, searcher.count(q));
      

       

      In the example above, a dateline spanning polygon is indexed as a MultiPolygon with two polygons that share the dateline. Similarly, a polygon that spans the dateline is provided as two polygons that share the dateline in a WITHIN query. The indexed polygon should be returned as a match; but it does not.

      Attachments

        1. LUCENE-8669.patch
          9 kB
          Nick Knize

        Activity

          People

            nknize Nick Knize
            nknize Nick Knize
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: