You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2019/08/07 22:26:25 UTC
[lucenenet] 28/42: BUG: Lucene.Net.Grouping.TopGroups - check
collection equality if the generic type is a reference type (as is the
default behavior in Java)
This is an automated email from the ASF dual-hosted git repository.
nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git
commit 5d3f29371c5a96620a364396664bc7424a4c6a39
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Mon Aug 5 08:00:45 2019 +0700
BUG: Lucene.Net.Grouping.TopGroups - check collection equality if the generic type is a reference type (as is the default behavior in Java)
---
src/Lucene.Net.Grouping/TopGroups.cs | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/src/Lucene.Net.Grouping/TopGroups.cs b/src/Lucene.Net.Grouping/TopGroups.cs
index 132957c..7a7e522 100644
--- a/src/Lucene.Net.Grouping/TopGroups.cs
+++ b/src/Lucene.Net.Grouping/TopGroups.cs
@@ -1,6 +1,7 @@
using Lucene.Net.Support;
using System;
using System.Diagnostics.CodeAnalysis;
+using System.Reflection;
namespace Lucene.Net.Search.Grouping
{
@@ -144,6 +145,10 @@ namespace Lucene.Net.Search.Grouping
return null;
}
+ // LUCENENET specific - store whether T is value type
+ // for optimization of GetHashCode() and Equals()
+ bool shardGroupsIsValueType = typeof(T).GetTypeInfo().IsValueType;
+
int totalHitCount = 0;
int totalGroupedHitCount = 0;
// Optionally merge the totalGroupCount.
@@ -193,7 +198,9 @@ namespace Lucene.Net.Search.Grouping
throw new ArgumentException("group values differ across shards; you must pass same top groups to all shards' second-pass collector");
}
}
- else if (!groupValue.Equals(shardGroupDocs.GroupValue))
+ // LUCENENET specific - use Collections.Equals() if we have a reference type
+ // to ensure if it is a collection its contents are compared
+ else if (!(shardGroupsIsValueType ? groupValue.Equals(shardGroupDocs.GroupValue) : Collections.Equals(groupValue, shardGroupDocs.GroupValue)))
{
throw new ArgumentException("group values differ across shards; you must pass same top groups to all shards' second-pass collector");
}