lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [57/58] [abbrv] lucenenet git commit: Lucene.Net.Grouping: Fixed test failures due to sorting using the wrong algorithm. TimSort doesn't call the IComparer<T>.Compare() method unless the values differ. If it is called when they are the same, the TestGrou
Date Thu, 10 Nov 2016 11:34:08 GMT
Lucene.Net.Grouping: Fixed test failures due to sorting using the wrong algorithm. TimSort
doesn't call the IComparer<T>.Compare() method unless the values differ. If it is called
when they are the same, the TestGrouping.TestRandom() and AllGroupHeadsCollectorTest.TestRandom()
tests fail. Added TODO about differences in sorting APIs.


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/049718c6
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/049718c6
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/049718c6

Branch: refs/heads/grouping
Commit: 049718c6cdd9f2170ba4c3227882bf88c03980e1
Parents: a0a61e2
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Mon Nov 7 18:18:05 2016 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Tue Nov 8 02:48:34 2016 +0700

----------------------------------------------------------------------
 .../AllGroupHeadsCollectorTest.cs               | 10 ++++++++-
 src/Lucene.Net.Tests.Grouping/TestGrouping.cs   | 22 ++++++++++++++++++--
 2 files changed, 29 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/049718c6/src/Lucene.Net.Tests.Grouping/AllGroupHeadsCollectorTest.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Grouping/AllGroupHeadsCollectorTest.cs b/src/Lucene.Net.Tests.Grouping/AllGroupHeadsCollectorTest.cs
index 8d6ca76..38c1721 100644
--- a/src/Lucene.Net.Tests.Grouping/AllGroupHeadsCollectorTest.cs
+++ b/src/Lucene.Net.Tests.Grouping/AllGroupHeadsCollectorTest.cs
@@ -500,7 +500,15 @@ namespace Lucene.Net.Search.Grouping
             foreach (BytesRef groupValue in groupHeads.Keys)
             {
                 List<GroupDoc> docs = groupHeads[groupValue];
-                docs.Sort(GetComparator(docSort, sortByScoreOnly, fieldIdToDocID));
+                // LUCENENET TODO: The original API Collections.Sort does not currently exist.
+                // This call ultimately results in calling TimSort, which is why this line
was replaced
+                // with CollectionUtil.TimSort(IList<T>, IComparer<T>).
+                //
+                // NOTE: List.Sort(comparer) won't work in this case because it calls the
comparer when the
+                // values are the same, which results in this test failing. TimSort only
calls the comparer
+                // when the values differ.
+                //Collections.Sort(docs, GetComparator(docSort, sortByScoreOnly, fieldIdToDocID));
+                CollectionUtil.TimSort(docs, GetComparator(docSort, sortByScoreOnly, fieldIdToDocID));
                 allGroupHeads[i++] = docs[0].id;
             }
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/049718c6/src/Lucene.Net.Tests.Grouping/TestGrouping.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Grouping/TestGrouping.cs b/src/Lucene.Net.Tests.Grouping/TestGrouping.cs
index 1ce5f0e..9d81af9 100644
--- a/src/Lucene.Net.Tests.Grouping/TestGrouping.cs
+++ b/src/Lucene.Net.Tests.Grouping/TestGrouping.cs
@@ -531,7 +531,16 @@ namespace Lucene.Net.Search.Grouping
 
             IComparer<GroupDoc> groupSortComp = GetComparator(groupSort);
 
-            Array.Sort(groupDocs, groupSortComp);
+            // LUCENENET TODO: The original Java API Arrays.Sort does not currently exist.
+            // This call ultimately results in calling TimSort, which is why this line was
replaced
+            // with ArrayUtil.TimSort(T[], IComparer<T>).
+            //
+            // NOTE: Array.Sort(comparer) won't work in this case because it calls the comparer
when the
+            // values are the same, which results in this test failing. TimSort only calls
the comparer
+            // when the values differ.
+            //Arrays.Sort(groupDocs, groupSortComp);
+            ArrayUtil.TimSort(groupDocs, groupSortComp);
+            
             HashMap<BytesRef, List<GroupDoc>> groups = new HashMap<BytesRef,
List<GroupDoc>>();
             List<BytesRef> sortedGroups = new List<BytesRef>();
             List<IComparable[]> sortedGroupFields = new List<IComparable[]>();
@@ -591,7 +600,16 @@ namespace Lucene.Net.Search.Grouping
                 BytesRef group = sortedGroups[idx];
                 List<GroupDoc> docs = groups[group];
                 totalGroupedHitCount += docs.size();
-                docs.Sort(docSortComp);
+
+                // LUCENENET TODO: The original API Collections.Sort does not currently exist.
+                // This call ultimately results in calling TimSort, which is why this line
was replaced
+                // with CollectionUtil.TimSort(IList<T>, IComparer<T>).
+                //
+                // NOTE: List.Sort(comparer) won't work in this case because it calls the
comparer when the
+                // values are the same, which results in this test failing. TimSort only
calls the comparer
+                // when the values differ.
+                //Collections.Sort(docs, docSortComp);
+                CollectionUtil.TimSort(docs, docSortComp);
                 ScoreDoc[] hits;
                 if (docs.size() > docOffset)
                 {


Mime
View raw message