lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [39/58] [abbrv] lucenenet git commit: Ported Grouping.GroupingSearchTest and fixed several bugs.
Date Thu, 10 Nov 2016 11:47:53 GMT
Ported Grouping.GroupingSearchTest and fixed several bugs.


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

Branch: refs/heads/master
Commit: 28cd391216597828674b90ad477966326a5e34f9
Parents: 0a137be
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Wed Nov 2 23:08:22 2016 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Tue Nov 8 02:24:55 2016 +0700

----------------------------------------------------------------------
 .../AbstractFirstPassGroupingCollector.cs       |  13 +-
 .../AbstractSecondPassGroupingCollector.cs      |  16 ++-
 .../BlockGroupingCollector.cs                   |  19 +--
 .../FunctionSecondPassGroupingCollector.cs      |   2 +-
 src/Lucene.Net.Grouping/GroupingSearch.cs       |  74 ++++++++++--
 .../Term/TermSecondPassGroupingCollector.cs     |   7 +-
 .../AllGroupsCollectorTest.cs                   |  18 ++-
 .../GroupingSearchTest.cs                       | 120 +++++++++----------
 .../Lucene.Net.Tests.Grouping.csproj            |   1 +
 9 files changed, 157 insertions(+), 113 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/28cd3912/src/Lucene.Net.Grouping/AbstractFirstPassGroupingCollector.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Grouping/AbstractFirstPassGroupingCollector.cs b/src/Lucene.Net.Grouping/AbstractFirstPassGroupingCollector.cs
index 0fb682d..c7f6e52 100644
--- a/src/Lucene.Net.Grouping/AbstractFirstPassGroupingCollector.cs
+++ b/src/Lucene.Net.Grouping/AbstractFirstPassGroupingCollector.cs
@@ -1,11 +1,9 @@
-using Lucene.Net.Search;
+using Lucene.Net.Index;
+using Lucene.Net.Support;
 using System;
 using System.Collections.Generic;
 using System.Diagnostics;
 using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Lucene.Net.Index;
 
 namespace Lucene.Net.Search.Grouping
 {
@@ -77,7 +75,7 @@ namespace Lucene.Net.Search.Grouping
             }
 
             spareSlot = topNGroups;
-            groupMap = new Dictionary<TGroupValue, CollectedSearchGroup<TGroupValue>>(topNGroups);
+            groupMap = new HashMap<TGroupValue, CollectedSearchGroup<TGroupValue>>(topNGroups);
         }
 
         /// <summary>
@@ -188,9 +186,8 @@ namespace Lucene.Net.Search.Grouping
             // under null group)?
             TGroupValue groupValue = GetDocGroupValue(doc);
 
-            CollectedSearchGroup<TGroupValue> group = groupMap[groupValue];
-
-            if (group == null)
+            CollectedSearchGroup<TGroupValue> group;
+            if (!groupMap.TryGetValue(groupValue, out group))
             {
 
                 // First time we are seeing this group, or, we've seen

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/28cd3912/src/Lucene.Net.Grouping/AbstractSecondPassGroupingCollector.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Grouping/AbstractSecondPassGroupingCollector.cs b/src/Lucene.Net.Grouping/AbstractSecondPassGroupingCollector.cs
index 41b5837..6364d90 100644
--- a/src/Lucene.Net.Grouping/AbstractSecondPassGroupingCollector.cs
+++ b/src/Lucene.Net.Grouping/AbstractSecondPassGroupingCollector.cs
@@ -1,10 +1,8 @@
-using Lucene.Net.Search;
+using Lucene.Net.Index;
+using Lucene.Net.Support;
 using System;
 using System.Collections.Generic;
 using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Lucene.Net.Index;
 
 namespace Lucene.Net.Search.Grouping
 {
@@ -21,19 +19,19 @@ namespace Lucene.Net.Search.Grouping
     /// @lucene.experimental
     /// </summary>
     /// <typeparam name="TGroupValue"></typeparam>
-    public abstract class AbstractSecondPassGroupingCollector<TGroupValue> : Collector
+    public abstract class AbstractSecondPassGroupingCollector<TGroupValue> : Collector,
IAbstractSecondPassGroupingCollector<TGroupValue>
     {
         protected readonly IDictionary<TGroupValue, AbstractSecondPassGroupingCollector.SearchGroupDocs<TGroupValue>>
groupMap;
         private readonly int maxDocsPerGroup;
         protected AbstractSecondPassGroupingCollector.SearchGroupDocs<TGroupValue>[]
groupDocs;
-        private readonly IEnumerable<SearchGroup<TGroupValue>> groups;
+        private readonly IEnumerable<ISearchGroup<TGroupValue>> groups;
         private readonly Sort withinGroupSort;
         private readonly Sort groupSort;
 
         private int totalHitCount;
         private int totalGroupedHitCount;
 
-        public AbstractSecondPassGroupingCollector(IEnumerable<SearchGroup<TGroupValue>>
groups, Sort groupSort, Sort withinGroupSort,
+        public AbstractSecondPassGroupingCollector(IEnumerable<ISearchGroup<TGroupValue>>
groups, Sort groupSort, Sort withinGroupSort,
                                                    int maxDocsPerGroup, bool getScores, bool
getMaxScores, bool fillSortFields)
         {
 
@@ -47,7 +45,7 @@ namespace Lucene.Net.Search.Grouping
             this.withinGroupSort = withinGroupSort;
             this.groups = groups;
             this.maxDocsPerGroup = maxDocsPerGroup;
-            groupMap = new Dictionary<TGroupValue, AbstractSecondPassGroupingCollector.SearchGroupDocs<TGroupValue>>(groups.Count());
+            groupMap = new HashMap<TGroupValue, AbstractSecondPassGroupingCollector.SearchGroupDocs<TGroupValue>>(groups.Count());
 
             foreach (SearchGroup<TGroupValue> group in groups)
             {
@@ -116,7 +114,7 @@ namespace Lucene.Net.Search.Grouping
             return false;
         }
 
-        public TopGroups<TGroupValue> GetTopGroups(int withinGroupOffset)
+        public ITopGroups<TGroupValue> GetTopGroups(int withinGroupOffset)
         {
             GroupDocs<TGroupValue>[] groupDocsResult = new GroupDocs<TGroupValue>[groups.Count()];
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/28cd3912/src/Lucene.Net.Grouping/BlockGroupingCollector.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Grouping/BlockGroupingCollector.cs b/src/Lucene.Net.Grouping/BlockGroupingCollector.cs
index 2a82993..c7fd34c 100644
--- a/src/Lucene.Net.Grouping/BlockGroupingCollector.cs
+++ b/src/Lucene.Net.Grouping/BlockGroupingCollector.cs
@@ -1,12 +1,8 @@
 using Lucene.Net.Index;
-using Lucene.Net.Search;
 using Lucene.Net.Util;
 using System;
 using System.Collections.Generic;
 using System.Diagnostics;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace Lucene.Net.Search.Grouping
 {
@@ -330,7 +326,12 @@ namespace Lucene.Net.Search.Grouping
          *  @param fillSortFields If true then the Comparable
          *     values for the sort fields will be set
          */
-        public TopGroups<T> GetTopGroups<T>(Sort withinGroupSort, int groupOffset,
int withinGroupOffset, int maxDocsPerGroup, bool fillSortFields)
+        public ITopGroups<object> GetTopGroups(Sort withinGroupSort, int groupOffset,
int withinGroupOffset, int maxDocsPerGroup, bool fillSortFields)
+        {
+            return GetTopGroups<object>(withinGroupSort, groupOffset, withinGroupOffset,
maxDocsPerGroup, fillSortFields);
+        }
+
+        public ITopGroups<TGroupValue> GetTopGroups<TGroupValue>(Sort withinGroupSort,
int groupOffset, int withinGroupOffset, int maxDocsPerGroup, bool fillSortFields)
         {
 
             //if (queueFull) {
@@ -350,7 +351,7 @@ namespace Lucene.Net.Search.Grouping
 
             float maxScore = float.MinValue;
 
-            GroupDocs<T>[] groups = new GroupDocs<T>[groupQueue.Size() - groupOffset];
+            GroupDocs<TGroupValue>[] groups = new GroupDocs<TGroupValue>[groupQueue.Size()
- groupOffset];
             for (int downTo = groupQueue.Size() - groupOffset - 1; downTo >= 0; downTo--)
             {
                 OneGroup og = groupQueue.Pop();
@@ -406,11 +407,11 @@ namespace Lucene.Net.Search.Grouping
 
                 // TODO: we could aggregate scores across children
                 // by Sum/Avg instead of passing NaN:
-                groups[downTo] = new GroupDocs<T>(float.NaN,
+                groups[downTo] = new GroupDocs<TGroupValue>(float.NaN,
                                                        topDocs.MaxScore,
                                                        og.count,
                                                        topDocs.ScoreDocs,
-                                                       default(T),
+                                                       default(TGroupValue),
                                                        groupSortValues);
                 maxScore = Math.Max(maxScore, topDocs.MaxScore);
             }
@@ -423,7 +424,7 @@ namespace Lucene.Net.Search.Grouping
             }
             */
 
-            return new TopGroups<T>(new TopGroups<T>(groupSort.GetSort(),
+            return new TopGroups<TGroupValue>(new TopGroups<TGroupValue>(groupSort.GetSort(),
                                                withinGroupSort == null ? null : withinGroupSort.GetSort(),
                                                totalHitCount, totalGroupedHitCount, groups,
maxScore),
                                  totalGroupCount);

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/28cd3912/src/Lucene.Net.Grouping/Function/FunctionSecondPassGroupingCollector.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Grouping/Function/FunctionSecondPassGroupingCollector.cs b/src/Lucene.Net.Grouping/Function/FunctionSecondPassGroupingCollector.cs
index 23f04b0..ec1fccb 100644
--- a/src/Lucene.Net.Grouping/Function/FunctionSecondPassGroupingCollector.cs
+++ b/src/Lucene.Net.Grouping/Function/FunctionSecondPassGroupingCollector.cs
@@ -33,7 +33,7 @@ namespace Lucene.Net.Search.Grouping.Function
         /// <param name="groupByVS">The <see cref="ValueSource"/> to group by</param>
         /// <param name="vsContext">The value source context</param>
         /// <exception cref="IOException">When I/O related errors occur</exception>
-        public FunctionSecondPassGroupingCollector(ICollection<SearchGroup<MutableValue>>
searchGroups, 
+        public FunctionSecondPassGroupingCollector(IEnumerable<ISearchGroup<MutableValue>>
searchGroups, 
             Sort groupSort, Sort withinGroupSort, int maxDocsPerGroup, bool getScores, bool
getMaxScores, 
             bool fillSortFields, ValueSource groupByVS, IDictionary /* Map<?, ?> */
vsContext)
             : base(searchGroups, groupSort, withinGroupSort, maxDocsPerGroup, getScores,
getMaxScores, fillSortFields)

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/28cd3912/src/Lucene.Net.Grouping/GroupingSearch.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Grouping/GroupingSearch.cs b/src/Lucene.Net.Grouping/GroupingSearch.cs
index 56554f6..c9353d8 100644
--- a/src/Lucene.Net.Grouping/GroupingSearch.cs
+++ b/src/Lucene.Net.Grouping/GroupingSearch.cs
@@ -1,6 +1,4 @@
 using Lucene.Net.Queries.Function;
-using Lucene.Net.Search;
-using Lucene.Net.Search.Grouping;
 using Lucene.Net.Search.Grouping.Function;
 using Lucene.Net.Search.Grouping.Terms;
 using Lucene.Net.Util;
@@ -8,9 +6,6 @@ using Lucene.Net.Util.Mutable;
 using System;
 using System.Collections;
 using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace Lucene.Net.Search.Grouping
 {
@@ -41,7 +36,7 @@ namespace Lucene.Net.Search.Grouping
         private bool allGroupHeads;
         private int initialSize = 128;
 
-        private IList /* Collection<?> */ matchingGroups;
+        private ICollection /* Collection<?> */ matchingGroups;
         private Bits matchingGroupHeads;
 
         /**
@@ -97,6 +92,11 @@ namespace Lucene.Net.Search.Grouping
          * @return the grouped result as a {@link TopGroups} instance
          * @throws IOException If any I/O related errors occur
          */
+        public ITopGroups<object> Search(IndexSearcher searcher, Query query, int groupOffset,
int groupLimit)
+        {
+            return Search<object>(searcher, null, query, groupOffset, groupLimit);
+        }
+
         public ITopGroups<TGroupValue> Search<TGroupValue>(IndexSearcher searcher,
Query query, int groupOffset, int groupLimit)
         {
             return Search<TGroupValue>(searcher, null, query, groupOffset, groupLimit);
@@ -113,6 +113,26 @@ namespace Lucene.Net.Search.Grouping
          * @return the grouped result as a {@link TopGroups} instance
          * @throws IOException If any I/O related errors occur
          */
+        public ITopGroups<object> Search(IndexSearcher searcher, Filter filter, Query
query, int groupOffset, int groupLimit)
+        {
+            if (groupFunction != null)
+            {
+                return GroupByFieldOrFunction<MutableValue>(searcher, filter, query,
groupOffset, groupLimit);
+            }
+            else if (groupField != null)
+            {
+                return GroupByFieldOrFunction<BytesRef>(searcher, filter, query, groupOffset,
groupLimit);
+            }
+            else if (groupEndDocs != null)
+            {
+                return GroupByDocBlock<object>(searcher, filter, query, groupOffset,
groupLimit);
+            }
+            else
+            {
+                throw new InvalidOperationException("Either groupField, groupFunction or
groupEndDocs must be set."); // This can't happen...
+            }
+        }
+
         public ITopGroups<TGroupValue> Search<TGroupValue>(IndexSearcher searcher,
Filter filter, Query query, int groupOffset, int groupLimit)
         {
             if (groupField != null || groupFunction != null)
@@ -121,7 +141,7 @@ namespace Lucene.Net.Search.Grouping
             }
             else if (groupEndDocs != null)
             {
-                return (TopGroups<TGroupValue>)GroupByDocBlock<TGroupValue>(searcher,
filter, query, groupOffset, groupLimit);
+                return GroupByDocBlock<TGroupValue>(searcher, filter, query, groupOffset,
groupLimit);
             }
             else
             {
@@ -129,6 +149,19 @@ namespace Lucene.Net.Search.Grouping
             }
         }
 
+        //protected ITopGroups<object> GroupByFieldOrFunction(IndexSearcher searcher,
Filter filter, Query query, int groupOffset, int groupLimit)
+        //{
+        //    // LUCENENET TODO: Perhaps there is a better way to infer type without resorting
to hard-coding them here, but
+        //    // the original GroupByFieldOrFunction is already aware of the underlying type
based on the FirstPassGroupingCollector
+        //    // and SecondPassGroupingCollector.
+        //    if (groupFunction != null)
+        //    {
+        //        return GroupByFieldOrFunction<MutableValue>(searcher, filter, query,
groupOffset, groupLimit);
+        //    }
+
+        //    return GroupByFieldOrFunction<BytesRef>(searcher, filter, query, groupOffset,
groupLimit);
+        //}
+
         protected ITopGroups<TGroupValue> GroupByFieldOrFunction<TGroupValue>(IndexSearcher
searcher, Filter filter, Query query, int groupOffset, int groupLimit)
         {
             int topN = groupOffset + groupLimit;
@@ -247,20 +280,28 @@ namespace Lucene.Net.Search.Grouping
             IAbstractSecondPassGroupingCollector<TGroupValue> secondPassCollector;
             if (groupFunction != null)
             {
-                secondPassCollector = (IAbstractSecondPassGroupingCollector<TGroupValue>)new
FunctionSecondPassGroupingCollector(topSearchGroups as ICollection<SearchGroup<MutableValue>>,
groupSort, sortWithinGroup, topNInsideGroup, includeScores, includeMaxScore, fillSortFields,
groupFunction, valueSourceContext);
+                secondPassCollector = new FunctionSecondPassGroupingCollector(topSearchGroups
as IEnumerable<ISearchGroup<MutableValue>>, 
+                    groupSort, sortWithinGroup, topNInsideGroup, includeScores, includeMaxScore,
fillSortFields, groupFunction, valueSourceContext)
+                    as IAbstractSecondPassGroupingCollector<TGroupValue>;
             }
             else
             {
-                secondPassCollector = (IAbstractSecondPassGroupingCollector<TGroupValue>)new
TermSecondPassGroupingCollector(groupField, topSearchGroups as ICollection<SearchGroup<BytesRef>>,
groupSort, sortWithinGroup, topNInsideGroup, includeScores, includeMaxScore, fillSortFields);
+                secondPassCollector = new TermSecondPassGroupingCollector(groupField, topSearchGroups
as IEnumerable<ISearchGroup<BytesRef>>, 
+                    groupSort, sortWithinGroup, topNInsideGroup, includeScores, includeMaxScore,
fillSortFields)
+                    as IAbstractSecondPassGroupingCollector<TGroupValue>;
             }
 
             if (cachedCollector != null && cachedCollector.Cached)
             {
-                cachedCollector.Replay((Collector)secondPassCollector);
+                // 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.
+                cachedCollector.Replay(secondPassCollector as Collector);
             }
             else
             {
-                searcher.Search(query, filter, (Collector)secondPassCollector);
+                // 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.
+                searcher.Search(query, filter, secondPassCollector as Collector);
             }
 
             if (allGroups)
@@ -273,13 +314,13 @@ namespace Lucene.Net.Search.Grouping
             }
         }
 
-        protected ITopGroups<T> GroupByDocBlock<T>(IndexSearcher searcher, Filter
filter, Query query, int groupOffset, int groupLimit)
+        protected ITopGroups<TGroupValue> GroupByDocBlock<TGroupValue>(IndexSearcher
searcher, Filter filter, Query query, int groupOffset, int groupLimit)
         {
             int topN = groupOffset + groupLimit;
             BlockGroupingCollector c = new BlockGroupingCollector(groupSort, topN, includeScores,
groupEndDocs);
             searcher.Search(query, filter, c);
             int topNInsideGroup = groupDocsOffset + groupDocsLimit;
-            return c.GetTopGroups<T>(sortWithinGroup, groupOffset, groupDocsOffset,
topNInsideGroup, fillSortFields);
+            return c.GetTopGroups<TGroupValue>(sortWithinGroup, groupOffset, groupDocsOffset,
topNInsideGroup, fillSortFields);
         }
 
         /**
@@ -443,6 +484,13 @@ namespace Lucene.Net.Search.Grouping
             return (ICollection<T>)matchingGroups;
         }
 
+        // LUCENENET specific used to get the groups if the type is unknown (since the above
+        // method will crash if the wrong type is used)
+        public ICollection GetAllMatchingGroups()
+        {
+            return matchingGroups;
+        }
+
         /**
          * Whether to compute all group heads (most relevant document per group) matching
the query.
          * <p/>

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/28cd3912/src/Lucene.Net.Grouping/Term/TermSecondPassGroupingCollector.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Grouping/Term/TermSecondPassGroupingCollector.cs b/src/Lucene.Net.Grouping/Term/TermSecondPassGroupingCollector.cs
index da70372..c9de6c1 100644
--- a/src/Lucene.Net.Grouping/Term/TermSecondPassGroupingCollector.cs
+++ b/src/Lucene.Net.Grouping/Term/TermSecondPassGroupingCollector.cs
@@ -1,11 +1,6 @@
 using Lucene.Net.Index;
-using Lucene.Net.Search;
 using Lucene.Net.Util;
-using System;
 using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace Lucene.Net.Search.Grouping.Terms
 {
@@ -22,7 +17,7 @@ namespace Lucene.Net.Search.Grouping.Terms
         private SortedDocValues index;
         private readonly string groupField;
 
-        public TermSecondPassGroupingCollector(string groupField, ICollection<SearchGroup<BytesRef>>
groups, Sort groupSort, Sort withinGroupSort,
+        public TermSecondPassGroupingCollector(string groupField, IEnumerable<ISearchGroup<BytesRef>>
groups, Sort groupSort, Sort withinGroupSort,
                                                int maxDocsPerGroup, bool getScores, bool
getMaxScores, bool fillSortFields)
                   : base(groups, groupSort, withinGroupSort, maxDocsPerGroup, getScores,
getMaxScores, fillSortFields)
         {

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/28cd3912/src/Lucene.Net.Tests.Grouping/AllGroupsCollectorTest.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Grouping/AllGroupsCollectorTest.cs b/src/Lucene.Net.Tests.Grouping/AllGroupsCollectorTest.cs
index c76a4da..32bdbc1 100644
--- a/src/Lucene.Net.Tests.Grouping/AllGroupsCollectorTest.cs
+++ b/src/Lucene.Net.Tests.Grouping/AllGroupsCollectorTest.cs
@@ -88,16 +88,22 @@ namespace Lucene.Net.Search.Grouping
             IndexSearcher indexSearcher = NewSearcher(w.Reader);
             w.Dispose();
 
-            AbstractAllGroupsCollector allGroupsCollector = CreateRandomCollector(groupField,
canUseIDV);
-            indexSearcher.Search(new TermQuery(new Term("content", "random")), allGroupsCollector);
+            IAbstractAllGroupsCollector<object> allGroupsCollector = CreateRandomCollector(groupField,
canUseIDV);
+            // 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 Term("content", "random")), allGroupsCollector
as Collector);
             assertEquals(4, allGroupsCollector.GroupCount);
 
             allGroupsCollector = CreateRandomCollector(groupField, canUseIDV);
-            indexSearcher.Search(new TermQuery(new Term("content", "some")), allGroupsCollector);
+            // 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 Term("content", "some")), allGroupsCollector
as Collector);
             assertEquals(3, allGroupsCollector.GroupCount);
 
             allGroupsCollector = CreateRandomCollector(groupField, canUseIDV);
-            indexSearcher.Search(new TermQuery(new Term("content", "blob")), allGroupsCollector);
+            // 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 Term("content", "blob")), allGroupsCollector
as Collector);
             assertEquals(2, allGroupsCollector.GroupCount);
 
             indexSearcher.IndexReader.Dispose();
@@ -113,9 +119,9 @@ namespace Lucene.Net.Search.Grouping
             }
         }
 
-        private AbstractAllGroupsCollector CreateRandomCollector(string groupField, bool
canUseIDV)
+        private IAbstractAllGroupsCollector<object> CreateRandomCollector(string groupField,
bool canUseIDV)
         {
-            AbstractAllGroupsCollector selected;
+            IAbstractAllGroupsCollector<object> selected;
             if (Random().nextBoolean())
             {
                 selected = new TermAllGroupsCollector(groupField);

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/28cd3912/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 8f49614..0b80e2e 100644
--- a/src/Lucene.Net.Tests.Grouping/GroupingSearchTest.cs
+++ b/src/Lucene.Net.Tests.Grouping/GroupingSearchTest.cs
@@ -8,10 +8,8 @@ using Lucene.Net.Util;
 using Lucene.Net.Util.Mutable;
 using NUnit.Framework;
 using System;
+using System.Collections;
 using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace Lucene.Net.Search.Grouping
 {
@@ -19,7 +17,7 @@ namespace Lucene.Net.Search.Grouping
     {
         // Tests some very basic usages...
         [Test]
-        public void testBasic()
+        public virtual void TestBasic()
         {
 
             string groupField = "author";
@@ -37,21 +35,21 @@ namespace Lucene.Net.Search.Grouping
             List<Document> documents = new List<Document>();
             // 0
             Document doc = new Document();
-            addGroupField(doc, groupField, "author1", canUseIDV);
+            AddGroupField(doc, groupField, "author1", canUseIDV);
             doc.Add(new TextField("content", "random text", Field.Store.YES));
             doc.Add(new Field("id", "1", customType));
             documents.Add(doc);
 
             // 1
             doc = new Document();
-            addGroupField(doc, groupField, "author1", canUseIDV);
+            AddGroupField(doc, groupField, "author1", canUseIDV);
             doc.Add(new TextField("content", "some more random text", Field.Store.YES));
             doc.Add(new Field("id", "2", customType));
             documents.Add(doc);
 
             // 2
             doc = new Document();
-            addGroupField(doc, groupField, "author1", canUseIDV);
+            AddGroupField(doc, groupField, "author1", canUseIDV);
             doc.Add(new TextField("content", "some more random textual data", Field.Store.YES));
             doc.Add(new Field("id", "3", customType));
             doc.Add(new StringField("groupend", "x", Field.Store.NO));
@@ -61,7 +59,7 @@ namespace Lucene.Net.Search.Grouping
 
             // 3
             doc = new Document();
-            addGroupField(doc, groupField, "author2", canUseIDV);
+            AddGroupField(doc, groupField, "author2", canUseIDV);
             doc.Add(new TextField("content", "some random text", Field.Store.YES));
             doc.Add(new Field("id", "4", customType));
             doc.Add(new StringField("groupend", "x", Field.Store.NO));
@@ -69,14 +67,14 @@ namespace Lucene.Net.Search.Grouping
 
             // 4
             doc = new Document();
-            addGroupField(doc, groupField, "author3", canUseIDV);
+            AddGroupField(doc, groupField, "author3", canUseIDV);
             doc.Add(new TextField("content", "some more random text", Field.Store.YES));
             doc.Add(new Field("id", "5", customType));
             documents.Add(doc);
 
             // 5
             doc = new Document();
-            addGroupField(doc, groupField, "author3", canUseIDV);
+            AddGroupField(doc, groupField, "author3", canUseIDV);
             doc.Add(new TextField("content", "random", Field.Store.YES));
             doc.Add(new Field("id", "6", customType));
             doc.Add(new StringField("groupend", "x", Field.Store.NO));
@@ -96,58 +94,58 @@ namespace Lucene.Net.Search.Grouping
             w.Dispose();
 
             Sort groupSort = Sort.RELEVANCE;
-            GroupingSearch groupingSearch = createRandomGroupingSearch(groupField, groupSort,
5, canUseIDV);
+            GroupingSearch groupingSearch = CreateRandomGroupingSearch(groupField, groupSort,
5, canUseIDV);
 
-            var groups = groupingSearch.Search(indexSearcher, (Filter)null, new TermQuery(new
Index.Term("content", "random")), 0, 10);
+            ITopGroups<object> groups = groupingSearch.Search(indexSearcher, (Filter)null,
new TermQuery(new Index.Term("content", "random")), 0, 10);
 
-            assertEquals(7, groups.totalHitCount);
-            assertEquals(7, groups.totalGroupedHitCount);
-            assertEquals(4, groups.groups.length);
+            assertEquals(7, groups.TotalHitCount);
+            assertEquals(7, groups.TotalGroupedHitCount);
+            assertEquals(4, groups.Groups.Length);
 
             // relevance order: 5, 0, 3, 4, 1, 2, 6
 
             // the later a document is added the higher this docId
             // value
-            GroupDocs <?> group = groups.groups[0];
-            compareGroupValue("author3", group);
-            assertEquals(2, group.scoreDocs.length);
-            assertEquals(5, group.scoreDocs[0].doc);
-            assertEquals(4, group.scoreDocs[1].doc);
-            assertTrue(group.scoreDocs[0].score > group.scoreDocs[1].score);
-
-            group = groups.groups[1];
-            compareGroupValue("author1", group);
-            assertEquals(3, group.scoreDocs.length);
-            assertEquals(0, group.scoreDocs[0].doc);
-            assertEquals(1, group.scoreDocs[1].doc);
-            assertEquals(2, group.scoreDocs[2].doc);
-            assertTrue(group.scoreDocs[0].score > group.scoreDocs[1].score);
-            assertTrue(group.scoreDocs[1].score > group.scoreDocs[2].score);
-
-            group = groups.groups[2];
-            compareGroupValue("author2", group);
-            assertEquals(1, group.scoreDocs.length);
-            assertEquals(3, group.scoreDocs[0].doc);
-
-            group = groups.groups[3];
-            compareGroupValue(null, group);
-            assertEquals(1, group.scoreDocs.length);
-            assertEquals(6, group.scoreDocs[0].doc);
+            var group = groups.Groups[0];
+            CompareGroupValue("author3", group);
+            assertEquals(2, group.ScoreDocs.Length);
+            assertEquals(5, group.ScoreDocs[0].Doc);
+            assertEquals(4, group.ScoreDocs[1].Doc);
+            assertTrue(group.ScoreDocs[0].Score > group.ScoreDocs[1].Score);
+
+            group = groups.Groups[1];
+            CompareGroupValue("author1", group);
+            assertEquals(3, group.ScoreDocs.Length);
+            assertEquals(0, group.ScoreDocs[0].Doc);
+            assertEquals(1, group.ScoreDocs[1].Doc);
+            assertEquals(2, group.ScoreDocs[2].Doc);
+            assertTrue(group.ScoreDocs[0].Score > group.ScoreDocs[1].Score);
+            assertTrue(group.ScoreDocs[1].Score > group.ScoreDocs[2].Score);
+
+            group = groups.Groups[2];
+            CompareGroupValue("author2", group);
+            assertEquals(1, group.ScoreDocs.Length);
+            assertEquals(3, group.ScoreDocs[0].Doc);
+
+            group = groups.Groups[3];
+            CompareGroupValue(null, group);
+            assertEquals(1, group.ScoreDocs.Length);
+            assertEquals(6, group.ScoreDocs[0].Doc);
 
             Filter lastDocInBlock = new CachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new
Index.Term("groupend", "x"))));
             groupingSearch = new GroupingSearch(lastDocInBlock);
             groups = groupingSearch.Search(indexSearcher, null, new TermQuery(new Index.Term("content",
"random")), 0, 10);
 
-            assertEquals(7, groups.totalHitCount);
-            assertEquals(7, groups.totalGroupedHitCount);
-            assertEquals(4, groups.totalGroupCount.longValue());
-            assertEquals(4, groups.groups.length);
+            assertEquals(7, groups.TotalHitCount);
+            assertEquals(7, groups.TotalGroupedHitCount);
+            assertEquals(4, groups.TotalGroupCount.GetValueOrDefault());
+            assertEquals(4, groups.Groups.Length);
 
             indexSearcher.IndexReader.Dispose();
             dir.Dispose();
         }
 
-        private void addGroupField(Document doc, string groupField, string value, bool canUseIDV)
+        private void AddGroupField(Document doc, string groupField, string value, bool canUseIDV)
         {
             doc.Add(new TextField(groupField, value, Field.Store.YES));
             if (canUseIDV)
@@ -156,34 +154,34 @@ namespace Lucene.Net.Search.Grouping
             }
         }
 
-        private void compareGroupValue(string expected, GroupDocs<?> group)
+        private void CompareGroupValue(string expected, IGroupDocs<object> group)
         {
             if (expected == null)
             {
-                if (group.groupValue == null)
+                if (group.GroupValue == null)
                 {
                     return;
                 }
-                else if (group.groupValue.GetType().IsAssignableFrom(typeof(MutableValueStr)))
+                else if (group.GroupValue.GetType().IsAssignableFrom(typeof(MutableValueStr)))
                 {
                     return;
                 }
-                else if (((BytesRef)group.groupValue).length == 0)
+                else if (((BytesRef)group.GroupValue).Length == 0)
                 {
                     return;
                 }
                 fail();
             }
 
-            if (group.groupValue.GetType().IsAssignableFrom(typeof(BytesRef)))
+            if (group.GroupValue.GetType().IsAssignableFrom(typeof(BytesRef)))
             {
-                assertEquals(new BytesRef(expected), group.groupValue);
+                assertEquals(new BytesRef(expected), group.GroupValue);
             }
-            else if (group.groupValue.GetType().IsAssignableFrom(typeof(MutableValueStr)))
+            else if (group.GroupValue.GetType().IsAssignableFrom(typeof(MutableValueStr)))
             {
                 MutableValueStr v = new MutableValueStr();
-                v.value = new BytesRef(expected);
-                assertEquals(v, group.groupValue);
+                v.Value = new BytesRef(expected);
+                assertEquals(v, group.GroupValue);
             }
             else
             {
@@ -191,13 +189,13 @@ 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())
             {
                 ValueSource vs = new BytesRefFieldSource(groupField);
-                groupingSearch = new GroupingSearch(vs, new Dictionary());
+                groupingSearch = new GroupingSearch(vs, new Hashtable());
             }
             else
             {
@@ -216,7 +214,7 @@ namespace Lucene.Net.Search.Grouping
         }
 
         [Test]
-        public void testSetAllGroups()
+        public virtual void TestSetAllGroups()
         {
             Directory dir = NewDirectory();
             RandomIndexWriter w = new RandomIndexWriter(
@@ -233,11 +231,11 @@ namespace Lucene.Net.Search.Grouping
 
             GroupingSearch gs = new GroupingSearch("group");
             gs.SetAllGroups(true);
-            TopGroups <?> groups = gs.Search(indexSearcher, null, new TermQuery(new
Index.Term("group", "foo")), 0, 10);
-            assertEquals(1, groups.totalHitCount);
+            ITopGroups<object> groups = gs.Search(indexSearcher, null, new TermQuery(new
Index.Term("group", "foo")), 0, 10);
+            assertEquals(1, groups.TotalHitCount);
             //assertEquals(1, groups.totalGroupCount.intValue());
-            assertEquals(1, groups.totalGroupedHitCount);
-            assertEquals(1, gs.GetAllMatchingGroups().size());
+            assertEquals(1, groups.TotalGroupedHitCount);
+            assertEquals(1, gs.GetAllMatchingGroups().Count);
             indexSearcher.IndexReader.Dispose();
             dir.Dispose();
         }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/28cd3912/src/Lucene.Net.Tests.Grouping/Lucene.Net.Tests.Grouping.csproj
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Grouping/Lucene.Net.Tests.Grouping.csproj b/src/Lucene.Net.Tests.Grouping/Lucene.Net.Tests.Grouping.csproj
index 806839d..cc96210 100644
--- a/src/Lucene.Net.Tests.Grouping/Lucene.Net.Tests.Grouping.csproj
+++ b/src/Lucene.Net.Tests.Grouping/Lucene.Net.Tests.Grouping.csproj
@@ -48,6 +48,7 @@
     <Compile Include="AllGroupHeadsCollectorTest.cs" />
     <Compile Include="AllGroupsCollectorTest.cs" />
     <Compile Include="GroupFacetCollectorTest.cs" />
+    <Compile Include="GroupingSearchTest.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>
   <ItemGroup>


Mime
View raw message