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

Spatial Search skipping records with small radius e.g. 1 mile

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: Lucene.Net 2.9.4
    • Fix Version/s: None
    • Component/s: Lucene.Net Contrib
    • Environment:

      .Net framework 4.0

      Description

      Running a spatial query against a list of locations all within 1 mile of a location returns correct results for 2 miles, but incorrect results for 1 mile. For the one mile query, only 2 of the 8 rows are returned.

      Locations & Test below:

      // Origin
      private double _lat = 51.508129;
      private double _lng = -0.128005;
      private const string LatField = "lat";
      private const string LngField = "lng";
      
      // Locations
      AddPoint(writer, "Location 1", 51.5073802128877, -0.124669075012207);
      AddPoint(writer, "Location 2", 51.5091, -0.1235);
      AddPoint(writer, "Location 3", 51.5093, -0.1232);
      AddPoint(writer, "Location 4", 51.5112531582845, -0.12509822845459);
      AddPoint(writer, "Location 5", 51.5107, -0.123);
      AddPoint(writer, "Location 6", 51.512, -0.1246);
      AddPoint(writer, "Location 8", 51.5088760101322, -0.143165588378906);
      AddPoint(writer, "Location 9", 51.5087958793819, -0.143508911132813);
      
      [Test]
      public void TestAntiM()
      {
      	_searcher = new IndexSearcher(_directory, true);
      
      	const double miles = 1.0; // Bug? Only returns 2 locations. Should return 8. 
      	// const double miles = 2.0; // Correct. Returns 8 Locations.
      
      	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 8 " + distances.Count);
      	Console.WriteLine("Results should be 8 " + results);
      
      	Assert.AreEqual(8, distances.Count); // fixed a store of only needed distances
      	Assert.AreEqual(8, results);
      }
      

        Attachments

          Activity

            People

            • Assignee:
              itamar Itamar Syn-Hershko
              Reporter:
              markrodseth Mark Rodseth
            • Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: