Uploaded image for project: 'Lucene.Net'
  1. Lucene.Net
  2. LUCENENET-483

Spatial Search skipping records when one location is close to origin, another one is away and radius is wider

    XMLWordPrintableJSON

    Details

      Description

      Running a spatial query against two locations where one location is close to origin (less than a mile), another one is away (24 miles) and radius is wider (52 miles) returns only one result. Running query with a bit wider radius (53.8) returns 2 results.

      IMPORTANT UPDATE: Problem can't be reproduced in Java, with using original Lucene.Spatial (2.9.4 version) library.

              // Origin
              private double _lat = 42.350153;
              private double _lng = -71.061667;
              private const string LatField = "lat";
              private const string LngField = "lng";
      
              //Locations            
              AddPoint(writer, "Location 1", 42.0, -71.0); //24 miles away from origin
              AddPoint(writer, "Location 2", 42.35, -71.06); //less than a mile
      
              [TestMethod]
              public void TestAntiM()
              {
                  _directory = new RAMDirectory();
      
                  var writer = new IndexWriter(_directory, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED);
      
                  SetUpPlotter(2, 15);
      
                  AddData(writer);
      
      
                  _searcher = new IndexSearcher(_directory, true);
      
                  //const double miles = 53.8; // Correct. Returns 2 Locations.
                  const double miles = 52; // Incorrect. Returns 1 Location.
      
                  Console.WriteLine("testAntiM");
                  // create a distance query
                  var dq = new DistanceQueryBuilder(_lat, _lng, miles, LatField, LngField, CartesianTierPlotter.DefaltFieldPrefix, true);
      
                  Console.WriteLine(dq);
                  //create a term query to search against all documents
                  Query tq = new TermQuery(new Term("metafile", "doc"));
      
                  var dsort = new DistanceFieldComparatorSource(dq.DistanceFilter);
                  Sort sort = new Sort(new SortField("foo", dsort, false));
      
                  // Perform the search, using the term query, the distance filter, and the
                  // distance sort
                  TopDocs hits = _searcher.Search(tq, dq.Filter, 1000, sort);
                  int results = hits.TotalHits;
                  ScoreDoc[] scoreDocs = hits.ScoreDocs;
      
                  // Get a list of distances
                  Dictionary<int, Double> distances = dq.DistanceFilter.Distances;
      
                  Console.WriteLine("Distance Filter filtered: " + distances.Count);
                  Console.WriteLine("Results: " + results);
                  Console.WriteLine("=============================");
                  Console.WriteLine("Distances should be 2 " + distances.Count);
                  Console.WriteLine("Results should be 2 " + results);
      
                  Assert.AreEqual(2, distances.Count); // fixed a store of only needed distances
                  Assert.AreEqual(2, results);
              }
      
      

        Attachments

          Activity

            People

            • Assignee:
              itamar Itamar Syn-Hershko
              Reporter:
              aleksandar.panov Aleksandar Panov
            • Votes:
              3 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: