Lucene.Net.Search.TestCustomSearcherSort.MatchHits C# (CSharp) Method

MatchHits() private method

private MatchHits ( Searcher searcher, Lucene.Net.Search.Sort sort ) : void
searcher Searcher
sort Lucene.Net.Search.Sort
return void
		private void  MatchHits(Searcher searcher, Sort sort)
		{
			// make a query without sorting first
			ScoreDoc[] hitsByRank = searcher.Search(query, null, 1000).ScoreDocs;
			CheckHits(hitsByRank, "Sort by rank: "); // check for duplicates
			System.Collections.IDictionary resultMap = new System.Collections.SortedList();
			// store hits in TreeMap - TreeMap does not allow duplicates; existing entries are silently overwritten
			for (int hitid = 0; hitid < hitsByRank.Length; ++hitid)
			{
				resultMap[hitsByRank[hitid].Doc] = hitid; // Value: Hits-Objekt Index
			}
			
			// now make a query using the sort criteria
			ScoreDoc[] resultSort = searcher.Search(query, null, 1000, sort).ScoreDocs;
			CheckHits(resultSort, "Sort by custom criteria: "); // check for duplicates
			
			// besides the sorting both sets of hits must be identical
			for (int hitid = 0; hitid < resultSort.Length; ++hitid)
			{
				System.Int32 idHitDate = (System.Int32) resultSort[hitid].Doc; // document ID from sorted search
				if (!resultMap.Contains(idHitDate))
				{
					Log("ID " + idHitDate + " not found. Possibliy a duplicate.");
				}
				Assert.IsTrue(resultMap.Contains(idHitDate)); // same ID must be in the Map from the rank-sorted search
				// every hit must appear once in both result sets --> remove it from the Map.
				// At the end the Map must be empty!
				resultMap.Remove(idHitDate);
			}
			if (resultMap.Count == 0)
			{
				// log("All hits matched");
			}
			else
			{
				Log("Couldn't match " + resultMap.Count + " hits.");
			}
			Assert.AreEqual(resultMap.Count, 0);
		}