Uploaded image for project: 'Hibernate Search'
  1. HSEARCH-1918

Spatial Search with distance projection is not returning all results

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects versions: 5.3.0.Final
    • Fix versions: 5.4.0.CR2
    • Components: spatial
    • Labels:
      None

      Description

      I have created a class with fields annotated with @Latitude and @Longitude:

      https://github.com/infinispan/infinispan/blob/master/integrationtests/as-lucene-directory/src/test/java/org/infinispan/test/integration/as/wildfly/model/Member.java

      This method is used to perform a spatial search:

         public List<Member> spatialSearch(double latitude, double longitude, double distanceinKM) {
            Query spatialQuery = Search.getFullTextEntityManager(em).getSearchFactory()
                  .buildQueryBuilder().forEntity( Member.class ).get().spatial()
                  .within( distanceinKM, Unit.KM )
                  .ofLatitude( latitude )
                  .andLongitude( longitude )
                  .createQuery();
            return Search.getFullTextEntityManager(em).createFullTextQuery(spatialQuery, Member.class).getResultList();
         }
      

      This method is used to perform a spatial search and also uses a projection to return the distance each member is from the specified longitude and latitude:

         public List<Object[]> spatialSearchWithDistance(double latitude, double longitude, double distanceinKM) {
            Query spatialQuery = Search.getFullTextEntityManager(em).getSearchFactory()
                  .buildQueryBuilder().forEntity(Member.class).get().spatial()
                  .onField("location")
                  .within(distanceinKM, Unit.KM)
                  .ofLatitude(latitude)
                  .andLongitude(longitude)
                  .createQuery();
      
            FullTextQuery hibQuery = Search.getFullTextEntityManager(em).createFullTextQuery(spatialQuery, Member.class);
            hibQuery.setProjection(FullTextQuery.SPATIAL_DISTANCE, FullTextQuery.THIS);
            hibQuery.setSpatialParameters(latitude, longitude, "location");
            return hibQuery.getResultList();
         }
      

      Then created objects that have the latitude and longitude set. When I search using a search radius that should include multiple members, the first method returns both members. However when using the same parameters, the second method only returns one member.

        Attachments

          Activity

            People

            • Assignee:
              Nicolas Helleringer
              Reporter:
              Alan Field
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: