Lucene - Core
  1. Lucene - Core
  2. LUCENE-5062

Spatial CONTAINS is sometimes incorrect for overlapped indexed shapes

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 4.3
    • Fix Version/s: 4.4
    • Component/s: modules/spatial
    • Labels:
      None
    • Lucene Fields:
      New

      Description

      If the spatial data for a document is comprised of multiple overlapping or adjacent parts, it might fail to match a query shape when doing the CONTAINS predicate when the sum of those shapes contain the query shape but none do individually.

        Activity

        Hide
        David Smiley added a comment -

        This test demonstrates the problem (place in SpatialOpRecursivePrefixTreeTest):

          public void testContainsPairOverlap() throws IOException {
            mySetup(7);
            adoc("0", new ShapePair(ctx.makeRectangle(60, 70, 35, 63), ctx.makeRectangle(10, 60, 35, 63), true));
            commit();
            Query query = strategy.makeQuery(new SpatialArgs(SpatialOperation.Contains,
                ctx.makeRectangle(50, 65, 40, 60)));
            SearchResults searchResults = executeQuery(query, 1);
            assertEquals(1, searchResults.numFound);
          }
        
        Show
        David Smiley added a comment - This test demonstrates the problem (place in SpatialOpRecursivePrefixTreeTest): public void testContainsPairOverlap() throws IOException { mySetup(7); adoc( "0" , new ShapePair(ctx.makeRectangle(60, 70, 35, 63), ctx.makeRectangle(10, 60, 35, 63), true )); commit(); Query query = strategy.makeQuery( new SpatialArgs(SpatialOperation.Contains, ctx.makeRectangle(50, 65, 40, 60))); SearchResults searchResults = executeQuery(query, 1); assertEquals(1, searchResults.numFound); }
        Hide
        David Smiley added a comment -

        The attached patch corrects this problem. I left the former behavior as a boolean flag performance optimization, since if you don't have indexed data triggering this problem then there's no point in the extra overhead of checking for it at runtime. I doubt it's much but nonetheless it was easy to add.

        Show
        David Smiley added a comment - The attached patch corrects this problem. I left the former behavior as a boolean flag performance optimization, since if you don't have indexed data triggering this problem then there's no point in the extra overhead of checking for it at runtime. I doubt it's much but nonetheless it was easy to add.
        Hide
        David Smiley added a comment -

        This patch adds the flag as a boolean constructor parameter. And adds equals & hashCode based on it.

        I also made this setting and "hasPoints" (inverse of hasIndexedLeaves) protected field members of RecursivePrefixTreeStrategy so that subclassers can tune them.

        I'll commit this in a day or two.

        Show
        David Smiley added a comment - This patch adds the flag as a boolean constructor parameter. And adds equals & hashCode based on it. I also made this setting and "hasPoints" (inverse of hasIndexedLeaves) protected field members of RecursivePrefixTreeStrategy so that subclassers can tune them. I'll commit this in a day or two.
        Hide
        Commit Tag Bot added a comment -

        [trunk commit] dsmiley
        http://svn.apache.org/viewvc?view=revision&revision=1495059

        LUCENE-5062: Spatial CONTAINS bug fix for indexed MultiPolygons with overlaps

        Show
        Commit Tag Bot added a comment - [trunk commit] dsmiley http://svn.apache.org/viewvc?view=revision&revision=1495059 LUCENE-5062 : Spatial CONTAINS bug fix for indexed MultiPolygons with overlaps
        Hide
        Commit Tag Bot added a comment -

        [branch_4x commit] dsmiley
        http://svn.apache.org/viewvc?view=revision&revision=1495061

        LUCENE-5062: Spatial CONTAINS bug fix for indexed MultiPolygons with overlaps

        Show
        Commit Tag Bot added a comment - [branch_4x commit] dsmiley http://svn.apache.org/viewvc?view=revision&revision=1495061 LUCENE-5062 : Spatial CONTAINS bug fix for indexed MultiPolygons with overlaps
        Hide
        David Smiley added a comment -

        Committed to both branches.

        * LUCENE-5062: If the spatial data for a document was comprised of multiple
          overlapping or adjacent parts then a CONTAINS predicate query might not match
          when the sum of those shapes contain the query shape but none do individually.
          A flag was added to use the original faster algorithm. (David Smiley)
        
        Show
        David Smiley added a comment - Committed to both branches. * LUCENE-5062: If the spatial data for a document was comprised of multiple overlapping or adjacent parts then a CONTAINS predicate query might not match when the sum of those shapes contain the query shape but none do individually. A flag was added to use the original faster algorithm. (David Smiley)

          People

          • Assignee:
            David Smiley
            Reporter:
            David Smiley
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development