lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [51/58] [abbrv] lucenenet git commit: Grouping: Test code cleanup to verify API
Date Thu, 10 Nov 2016 11:48:05 GMT
Grouping: Test code cleanup to verify API


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

Branch: refs/heads/master
Commit: d0838cc3706f93a36557e1aa783f0af523aeace2
Parents: 3881180
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Sun Nov 6 23:51:21 2016 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Tue Nov 8 02:48:20 2016 +0700

----------------------------------------------------------------------
 src/Lucene.Net.Grouping/SearchGroup.cs          | 14 +++++++
 src/Lucene.Net.Grouping/TopGroups.cs            | 14 ++++++-
 .../AllGroupHeadsCollectorTest.cs               |  9 ++---
 .../GroupFacetCollectorTest.cs                  | 25 ++++++------
 .../GroupingSearchTest.cs                       |  4 +-
 src/Lucene.Net.Tests.Grouping/TestGrouping.cs   | 41 +++++++++-----------
 6 files changed, 64 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/d0838cc3/src/Lucene.Net.Grouping/SearchGroup.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Grouping/SearchGroup.cs b/src/Lucene.Net.Grouping/SearchGroup.cs
index a225f3c..23140bc 100644
--- a/src/Lucene.Net.Grouping/SearchGroup.cs
+++ b/src/Lucene.Net.Grouping/SearchGroup.cs
@@ -54,6 +54,18 @@ namespace Lucene.Net.Search.Grouping
         {
             return GroupValue != null ? GroupValue.GetHashCode() : 0;
         }
+    }
+
+    /// <summary>
+    /// LUCENENET specific class used to nest types to mimic the syntax used 
+    /// by Lucene (that is, without specifying the generic closing type of <see cref="SearchGroup{TGroupValue}"/>)
+    /// </summary>
+    public class SearchGroup
+    {
+        /// <summary>
+        /// Prevent direct creation
+        /// </summary>
+        private SearchGroup() { }
 
         private class ShardIter<T>
         {
@@ -361,6 +373,7 @@ namespace Lucene.Net.Search.Grouping
             }
         }
 
+
         /** Merges multiple collections of top groups, for example
          *  obtained from separate index shards.  The provided
          *  groupSort must match how the groups were sorted, and
@@ -383,6 +396,7 @@ namespace Lucene.Net.Search.Grouping
         }
     }
 
+
     /// <summary>
     /// LUCENENET specific interface used to provide covariance
     /// with the TGroupValue type

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/d0838cc3/src/Lucene.Net.Grouping/TopGroups.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Grouping/TopGroups.cs b/src/Lucene.Net.Grouping/TopGroups.cs
index 54a9547..d66439d 100644
--- a/src/Lucene.Net.Grouping/TopGroups.cs
+++ b/src/Lucene.Net.Grouping/TopGroups.cs
@@ -77,6 +77,18 @@ namespace Lucene.Net.Search.Grouping
             MaxScore = oldTopGroups.MaxScore;
             TotalGroupCount = totalGroupCount;
         }
+    }
+
+    /// <summary>
+    /// LUCENENET specific class used to nest types to mimic the syntax used 
+    /// by Lucene (that is, without specifying the generic closing type of <see cref="TopGroups{TGroupValue}"/>)
+    /// </summary>
+    public class TopGroups
+    {
+        /// <summary>
+        /// Prevent direct creation
+        /// </summary>
+        private TopGroups() { }
 
         /// <summary>
         /// How the GroupDocs score (if any) should be merged. </summary>
@@ -148,7 +160,7 @@ namespace Lucene.Net.Search.Grouping
                     totalGroupCount += shard.TotalGroupCount;
                 }
             }
-            
+
             var mergedGroupDocs = new GroupDocs<T>[numGroups];
 
             TopDocs[] shardTopDocs = new TopDocs[shardGroups.Length];

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/d0838cc3/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 0f1ddb2..c7cac67 100644
--- a/src/Lucene.Net.Tests.Grouping/AllGroupHeadsCollectorTest.cs
+++ b/src/Lucene.Net.Tests.Grouping/AllGroupHeadsCollectorTest.cs
@@ -30,9 +30,9 @@ namespace Lucene.Net.Search.Grouping
             Directory dir = NewDirectory();
             RandomIndexWriter w = new RandomIndexWriter(
                 Random(),
-            dir,
-            NewIndexWriterConfig(TEST_VERSION_CURRENT,
-                new MockAnalyzer(Random())).SetMergePolicy(NewLogMergePolicy()));
+                dir,
+                NewIndexWriterConfig(TEST_VERSION_CURRENT,
+                    new MockAnalyzer(Random())).SetMergePolicy(NewLogMergePolicy()));
             bool canUseIDV = !"Lucene3x".Equals(w.w.Config.Codec.Name, StringComparison.Ordinal);
             FieldInfo.DocValuesType_e valueType = vts[Random().nextInt(vts.Length)];
 
@@ -343,7 +343,7 @@ namespace Lucene.Net.Search.Grouping
                         string searchTerm = "real" + Random().nextInt(3);
                         bool sortByScoreOnly = Random().nextBoolean();
                         Sort sortWithinGroup = GetRandomSort(sortByScoreOnly);
-                        var allGroupHeadsCollector = CreateRandomCollector("group", sortWithinGroup,
canUseIDV, valueType);
+                        AbstractAllGroupHeadsCollector allGroupHeadsCollector = CreateRandomCollector("group",
sortWithinGroup, canUseIDV, valueType);
                         s.Search(new TermQuery(new Term("content", searchTerm)), allGroupHeadsCollector);
                         int[] expectedGroupHeads = CreateExpectedGroupHeads(searchTerm, groupDocs,
sortWithinGroup, sortByScoreOnly, fieldIdToDocID);
                         int[] actualGroupHeads = allGroupHeadsCollector.RetrieveGroupHeads();
@@ -660,7 +660,6 @@ namespace Lucene.Net.Search.Grouping
                 this.sort3 = sort3;
                 this.content = content;
             }
-
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/d0838cc3/src/Lucene.Net.Tests.Grouping/GroupFacetCollectorTest.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Grouping/GroupFacetCollectorTest.cs b/src/Lucene.Net.Tests.Grouping/GroupFacetCollectorTest.cs
index dda2cdb..e50c91b 100644
--- a/src/Lucene.Net.Tests.Grouping/GroupFacetCollectorTest.cs
+++ b/src/Lucene.Net.Tests.Grouping/GroupFacetCollectorTest.cs
@@ -74,8 +74,7 @@ namespace Lucene.Net.Search.Grouping
             AbstractGroupFacetCollector groupedAirportFacetCollector = null;
             TermGroupFacetCollector.GroupedFacetResult airportResult = null;
 
-            foreach (int limit in new int[] { 2, 10, 100, int.MaxValue
-    })
+            foreach (int limit in new int[] { 2, 10, 100, int.MaxValue })
             {
                 // any of these limits is plenty for the data we have
 
@@ -407,7 +406,7 @@ namespace Lucene.Net.Search.Grouping
                     searcher.Search(new TermQuery(new Term("content", searchTerm)), groupFacetCollector);
                     TermGroupFacetCollector.GroupedFacetResult actualFacetResult = groupFacetCollector.MergeSegmentResults(size,
minCount, orderByCount);
 
-                    List<TermGroupFacetCollector.FacetEntry> expectedFacetEntries =
expectedFacetResult.getFacetEntries();
+                    List<TermGroupFacetCollector.FacetEntry> expectedFacetEntries =
expectedFacetResult.GetFacetEntries();
                     List<TermGroupFacetCollector.FacetEntry> actualFacetEntries = actualFacetResult.GetFacetEntries(offset,
limit);
 
                     if (VERBOSE)
@@ -428,8 +427,8 @@ namespace Lucene.Net.Search.Grouping
                         Console.WriteLine("Order by count: " + orderByCount);
 
                         Console.WriteLine("\n=== Expected: \n");
-                        Console.WriteLine("Total count " + expectedFacetResult.getTotalCount());
-                        Console.WriteLine("Total missing count " + expectedFacetResult.getTotalMissingCount());
+                        Console.WriteLine("Total count " + expectedFacetResult.TotalCount);
+                        Console.WriteLine("Total missing count " + expectedFacetResult.TotalMissingCount);
                         int counter = 0;
                         foreach (TermGroupFacetCollector.FacetEntry expectedFacetEntry in
expectedFacetEntries)
                         {
@@ -457,8 +456,8 @@ namespace Lucene.Net.Search.Grouping
                         Console.WriteLine("\n===================================================================================");
                     }
 
-                    assertEquals(expectedFacetResult.getTotalCount(), actualFacetResult.TotalCount);
-                    assertEquals(expectedFacetResult.getTotalMissingCount(), actualFacetResult.TotalMissingCount);
+                    assertEquals(expectedFacetResult.TotalCount, actualFacetResult.TotalCount);
+                    assertEquals(expectedFacetResult.TotalMissingCount, actualFacetResult.TotalMissingCount);
                     assertEquals(expectedFacetEntries.size(), actualFacetEntries.size());
                     for (int i = 0; i < expectedFacetEntries.size(); i++)
                     {
@@ -587,7 +586,7 @@ namespace Lucene.Net.Search.Grouping
             docNoGroupNoFacet.Add(content);
 
             // LUCENENET NOTE: TreeSet (the class used in Java) allows duplicate keys. However,
SortedSet seems to work,
-            // and based on the name of the variable, presuming the keys are meant to be
unique.
+            // and based on the name of the variable, presuming the entries are meant to
be unique.
             ISet<string> uniqueFacetValues = new SortedSet<string>(new ComparerAnonymousHelper1());
 
             // LUCENENET NOTE: Need HashMap here because of null keys
@@ -881,17 +880,17 @@ namespace Lucene.Net.Search.Grouping
                 this.facetEntries = facetEntries;
             }
 
-            public int getTotalCount()
+            public int TotalCount
             {
-                return totalCount;
+                get { return totalCount; }
             }
 
-            public int getTotalMissingCount()
+            public int TotalMissingCount
             {
-                return totalMissingCount;
+                get { return totalMissingCount; }
             }
 
-            public List<TermGroupFacetCollector.FacetEntry> getFacetEntries()
+            public List<TermGroupFacetCollector.FacetEntry> GetFacetEntries()
             {
                 return facetEntries;
             }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/d0838cc3/src/Lucene.Net.Tests.Grouping/GroupingSearchTest.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Grouping/GroupingSearchTest.cs b/src/Lucene.Net.Tests.Grouping/GroupingSearchTest.cs
index 2971a52..49b56e6 100644
--- a/src/Lucene.Net.Tests.Grouping/GroupingSearchTest.cs
+++ b/src/Lucene.Net.Tests.Grouping/GroupingSearchTest.cs
@@ -106,7 +106,7 @@ namespace Lucene.Net.Search.Grouping
 
             // the later a document is added the higher this docId
             // value
-            var group = groups.Groups[0];
+            IGroupDocs<object> group = groups.Groups[0];
             CompareGroupValue("author3", group);
             assertEquals(2, group.ScoreDocs.Length);
             assertEquals(5, group.ScoreDocs[0].Doc);
@@ -189,7 +189,7 @@ namespace Lucene.Net.Search.Grouping
             }
         }
 
-        private GroupingSearch CreateRandomGroupingSearch(String groupField, Sort groupSort,
int docsInGroup, bool canUseIDV)
+        private GroupingSearch CreateRandomGroupingSearch(string groupField, Sort groupSort,
int docsInGroup, bool canUseIDV)
         {
             GroupingSearch groupingSearch;
             if (Random().nextBoolean())

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/d0838cc3/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 6098887..1ce5f0e 100644
--- a/src/Lucene.Net.Tests.Grouping/TestGrouping.cs
+++ b/src/Lucene.Net.Tests.Grouping/TestGrouping.cs
@@ -99,17 +99,17 @@ namespace Lucene.Net.Search.Grouping
                 groupField += "_dv";
             }
 
-            IAbstractFirstPassGroupingCollector<IComparable> c1 = CreateRandomFirstPassCollector(groupField,
groupSort, 10);
+            IAbstractFirstPassGroupingCollector<object> c1 = CreateRandomFirstPassCollector(groupField,
groupSort, 10);
             // LUCENENET TODO: Create an ICollector interface that we can inherit our Collector
interfaces from
             // so this cast is not necessary. Consider eliminating the Collector abstract
class.
             indexSearcher.Search(new TermQuery(new Index.Term("content", "random")), c1 as
Collector);
 
-            IAbstractSecondPassGroupingCollector<IComparable> c2 = CreateSecondPassCollector(c1,
groupField, groupSort, null, 0, 5, true, true, true);
+            IAbstractSecondPassGroupingCollector<object> c2 = CreateSecondPassCollector(c1,
groupField, groupSort, null, 0, 5, true, true, true);
             // LUCENENET TODO: Create an ICollector interface that we can inherit our Collector
interfaces from
             // so this cast is not necessary. Consider eliminating the Collector abstract
class.
             indexSearcher.Search(new TermQuery(new Index.Term("content", "random")), c2 as
Collector);
 
-            ITopGroups<IComparable> groups = c2.GetTopGroups(0);
+            ITopGroups<object> groups = c2.GetTopGroups(0);
             assertFalse(float.IsNaN(groups.MaxScore));
 
             assertEquals(7, groups.TotalHitCount);
@@ -120,7 +120,7 @@ namespace Lucene.Net.Search.Grouping
 
             // the later a document is added the higher this docId
             // value
-            IGroupDocs<IComparable> group = groups.Groups[0];
+            IGroupDocs<object> group = groups.Groups[0];
             CompareGroupValue("author3", group);
             assertEquals(2, group.ScoreDocs.Length);
             assertEquals(5, group.ScoreDocs[0].Doc);
@@ -159,9 +159,9 @@ namespace Lucene.Net.Search.Grouping
             }
         }
 
-        private IAbstractFirstPassGroupingCollector<IComparable> CreateRandomFirstPassCollector(string
groupField, Sort groupSort, int topDocs)
+        private IAbstractFirstPassGroupingCollector<object> CreateRandomFirstPassCollector(string
groupField, Sort groupSort, int topDocs)
         {
-            IAbstractFirstPassGroupingCollector<IComparable> selected;
+            IAbstractFirstPassGroupingCollector<object> selected;
             if (Random().nextBoolean())
             {
                 ValueSource vs = new BytesRefFieldSource(groupField);
@@ -318,8 +318,9 @@ namespace Lucene.Net.Search.Grouping
             }
             else if (typeof(FunctionFirstPassGroupingCollector).IsAssignableFrom(c.GetType()))
             {
-                // LUCENENET TODO: Can we remove this cast?
-                var mutableValueGroups = c.GetTopGroups(groupOffset, fillFields) as IEnumerable<ISearchGroup<MutableValue>>;
+                // LUCENENET NOTE: This is IEnumerable instead of ICollection because it

+                // needs to be covariant to mimic the wildcard generics in Java
+                IEnumerable<ISearchGroup<MutableValue>> mutableValueGroups =
((FunctionFirstPassGroupingCollector)c).GetTopGroups(groupOffset, fillFields);
                 if (mutableValueGroups == null)
                 {
                     return null;
@@ -362,9 +363,6 @@ namespace Lucene.Net.Search.Grouping
 
         internal class GroupDoc
         {
-            private static int instanceIndex;
-            internal readonly int instanceId;
-
             internal readonly int id;
             internal readonly BytesRef group;
             internal readonly BytesRef sort1;
@@ -376,8 +374,6 @@ namespace Lucene.Net.Search.Grouping
 
             public GroupDoc(int id, BytesRef group, BytesRef sort1, BytesRef sort2, string
content)
             {
-                this.instanceId = instanceIndex++;
-
                 this.id = id;
                 this.group = group;
                 this.sort1 = sort1;
@@ -1026,11 +1022,11 @@ namespace Lucene.Net.Search.Grouping
                         {
                             Console.WriteLine("  groupField=" + groupField);
                         }
-                        IAbstractFirstPassGroupingCollector<IComparable> c1 = CreateRandomFirstPassCollector(groupField,
groupSort, groupOffset + topNGroups);
+                        IAbstractFirstPassGroupingCollector<object> c1 = CreateRandomFirstPassCollector(groupField,
groupSort, groupOffset + topNGroups);
                         CachingCollector cCache;
                         Collector c;
 
-                        IAbstractAllGroupsCollector<IComparable> allGroupsCollector;
+                        IAbstractAllGroupsCollector<object> allGroupsCollector;
                         if (doAllGroups)
                         {
                             allGroupsCollector = CreateAllGroupsCollector(c1, groupField);
@@ -1126,6 +1122,8 @@ namespace Lucene.Net.Search.Grouping
                         }
 
                         // Get 1st pass top groups
+                        // LUCENENET NOTE: This is IEnumerable rather than ICollection because
we need it to be
+                        // covariant in order to mimic Java's wildcard generics
                         IEnumerable<ISearchGroup<BytesRef>> topGroups = GetSearchGroups(c1,
groupOffset, fillFields);
                         ITopGroups<BytesRef> groupsResult;
                         if (VERBOSE)
@@ -1149,7 +1147,7 @@ namespace Lucene.Net.Search.Grouping
                         ValueHolder<bool> idvBasedImplsUsedSharded = new ValueHolder<bool>(false);
                         TopGroups<BytesRef> topGroupsShards = SearchShards(s, shards.subSearchers,
query, groupSort, docSort,
                            groupOffset, topNGroups, docOffset, docsPerGroup, getScores, getMaxScores,
canUseIDV, preFlex, idvBasedImplsUsedSharded);
-                        IAbstractSecondPassGroupingCollector<IComparable> c2;
+                        IAbstractSecondPassGroupingCollector<object> c2;
                         if (topGroups != null)
                         {
 
@@ -1450,8 +1448,8 @@ namespace Lucene.Net.Search.Grouping
             // Run 1st pass collector to get top groups per shard
             Weight w = topSearcher.CreateNormalizedWeight(query);
             List<IEnumerable<ISearchGroup<BytesRef>>> shardGroups = new
List<IEnumerable<ISearchGroup<BytesRef>>>();
-            List<IAbstractFirstPassGroupingCollector<IComparable>> firstPassGroupingCollectors
= new List<IAbstractFirstPassGroupingCollector<IComparable>>();
-            IAbstractFirstPassGroupingCollector<IComparable> firstPassCollector = null;
+            List<IAbstractFirstPassGroupingCollector<object>> firstPassGroupingCollectors
= new List<IAbstractFirstPassGroupingCollector<object>>();
+            IAbstractFirstPassGroupingCollector<object> firstPassCollector = null;
             bool shardsCanUseIDV;
             if (canUseIDV)
             {
@@ -1513,7 +1511,7 @@ namespace Lucene.Net.Search.Grouping
                 }
             }
 
-            ICollection<SearchGroup<BytesRef>> mergedTopGroups = SearchGroup<BytesRef>.Merge(shardGroups,
groupOffset, topNGroups, groupSort);
+            ICollection<SearchGroup<BytesRef>> mergedTopGroups = SearchGroup.Merge(shardGroups,
groupOffset, topNGroups, groupSort);
             if (VERBOSE)
             {
                 Console.WriteLine(" top groups merged:");
@@ -1537,7 +1535,7 @@ namespace Lucene.Net.Search.Grouping
                 ITopGroups<BytesRef>[] shardTopGroups = new ITopGroups<BytesRef>[subSearchers.Length];
                 for (int shardIDX = 0; shardIDX < subSearchers.Length; shardIDX++)
                 {
-                    IAbstractSecondPassGroupingCollector<IComparable> secondPassCollector
= CreateSecondPassCollector(firstPassGroupingCollectors[shardIDX],
+                    IAbstractSecondPassGroupingCollector<object> secondPassCollector
= CreateSecondPassCollector(firstPassGroupingCollectors[shardIDX],
                         groupField, mergedTopGroups, groupSort, docSort, docOffset + topNDocs,
getScores, getMaxScores, true);
                     // LUCENENET TODO: Create an ICollector interface that we can inherit
our Collector interfaces from
                     // so this cast is not necessary. Consider eliminating the Collector
abstract class.
@@ -1553,8 +1551,7 @@ namespace Lucene.Net.Search.Grouping
                     }
                 }
 
-                // LUCENENET TODO: Put Merge() in a TopGroups class
-                TopGroups<BytesRef> mergedGroups = TopGroups<BytesRef>.Merge(shardTopGroups,
groupSort, docSort, docOffset, topNDocs, TopGroups<BytesRef>.ScoreMergeMode.None);
+                TopGroups<BytesRef> mergedGroups = TopGroups.Merge(shardTopGroups,
groupSort, docSort, docOffset, topNDocs, TopGroups.ScoreMergeMode.None);
                 if (VERBOSE)
                 {
                     Console.WriteLine(" " + mergedGroups.Groups.Length + " merged groups:");


Mime
View raw message