lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [47/58] [abbrv] lucenenet git commit: Removed superfluous IGroupCount interface. Created non-generic AbstractDistinctValuesCollector class to nest IGroupCount and GroupCount so the syntax is similar to Lucene.
Date Thu, 10 Nov 2016 11:33:58 GMT
Removed superfluous IGroupCount interface. Created non-generic AbstractDistinctValuesCollector
class to nest IGroupCount and GroupCount so the syntax is similar to Lucene.


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

Branch: refs/heads/grouping
Commit: 41b9732e9a11f3ad04f8633ce47857c7c98e18e0
Parents: 95bb669
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Sun Nov 6 22:19:37 2016 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Tue Nov 8 02:24:58 2016 +0700

----------------------------------------------------------------------
 .../AbstractDistinctValuesCollector.cs          | 93 ++++++++------------
 .../Function/FunctionDistinctValuesCollector.cs |  2 +-
 .../Term/TermDistinctValuesCollector.cs         |  2 +-
 .../DistinctValuesCollectorTest.cs              | 36 ++++----
 4 files changed, 56 insertions(+), 77 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/41b9732e/src/Lucene.Net.Grouping/AbstractDistinctValuesCollector.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Grouping/AbstractDistinctValuesCollector.cs b/src/Lucene.Net.Grouping/AbstractDistinctValuesCollector.cs
index 0f51a24..5c3e624 100644
--- a/src/Lucene.Net.Grouping/AbstractDistinctValuesCollector.cs
+++ b/src/Lucene.Net.Grouping/AbstractDistinctValuesCollector.cs
@@ -14,7 +14,7 @@ namespace Lucene.Net.Search.Grouping
     /// </summary>
     /// <typeparam name="GC"></typeparam>
     public abstract class AbstractDistinctValuesCollector<GC> : Collector, IAbstractDistinctValuesCollector<GC>
-        where GC : IGroupCount /* AbstractDistinctValuesCollector<GC>.GroupCount */
+        where GC : AbstractDistinctValuesCollector.IGroupCount<object>
     {
         /// <summary>
         /// Returns all unique values for each top N group.
@@ -35,71 +35,50 @@ namespace Lucene.Net.Search.Grouping
         } 
     }
 
-    //public abstract class AbstractDistinctValuesCollector : Collector
-    //{
-    //    /// <summary>
-    //    /// Returns all unique values for each top N group.
-    //    /// </summary>
-    //    /// <returns>all unique values for each top N group</returns>
-    //    public abstract List<GC> GetGroups();
-
-    //    public override bool AcceptsDocsOutOfOrder()
-    //    {
-    //        return true;
-    //    }
-
-    //    public override Scorer Scorer
-    //    {
-    //        set
-    //        {
-    //        }
-    //    }
-    //}
-
-
     /// <summary>
-    /// Returned by <see cref="AbstractDistinctValuesCollector.GetGroups()"/>,
-    /// representing the value and set of distinct values for the group.
+    /// LUCENENET specific class used to nest the <see cref="GroupCount{TGroupValue}"/>
+    /// class so it has similar syntax to that in Java Lucene
+    /// (AbstractDistinctValuesCollector.GroupCount{TGroupValue} rather than 
+    /// AbstractDistinctValuesCollector{GC}.GroupCount{TGroupValue}).
     /// </summary>
-    /// <typeparam name="TGroupValue"></typeparam>
-    /// <remarks>
-    /// LUCENENET - removed this class from being a nested class of 
-    /// <see cref="AbstractDistinctValuesCollector{GC}"/> and renamed
-    /// from GroupCount to AbstractGroupCount
-    /// </remarks>
-    public abstract class AbstractGroupCount<TGroupValue> : IGroupCount<TGroupValue>
-        //where TGroupValue : IComparable
+    public class AbstractDistinctValuesCollector
     {
-        public TGroupValue GroupValue { get; protected set; }
-        public IEnumerable<TGroupValue> UniqueValues { get; protected set; }
+        // Disallow direct creation
+        private AbstractDistinctValuesCollector() { }
 
-        public AbstractGroupCount(TGroupValue groupValue)
+        /// <summary>
+        /// Returned by <see cref="AbstractDistinctValuesCollector.GetGroups()"/>,
+        /// representing the value and set of distinct values for the group.
+        /// </summary>
+        /// <typeparam name="TGroupValue"></typeparam>
+        /// <remarks>
+        /// LUCENENET - removed this class from being a nested class of 
+        /// <see cref="AbstractDistinctValuesCollector{GC}"/> and renamed
+        /// from GroupCount to AbstractGroupCount
+        /// </remarks>
+        public abstract class GroupCount<TGroupValue> : IGroupCount<TGroupValue>
         {
-            this.GroupValue = groupValue;
-            this.UniqueValues = new HashSet<TGroupValue>();
-        }
-    }
-
-    /// <summary>
-    /// LUCENENET specific interface to allow usage of <see cref="AbstractGroupCount{TGroupValue}"/>
-    /// as a generic closing type without having to specify TGroupValue.
-    /// </summary>
-    public interface IGroupCount
-    {
-    }
+            public TGroupValue GroupValue { get; protected set; }
+            public IEnumerable<TGroupValue> UniqueValues { get; protected set; }
 
+            public GroupCount(TGroupValue groupValue)
+            {
+                this.GroupValue = groupValue;
+                this.UniqueValues = new HashSet<TGroupValue>();
+            }
+        }
 
-    /// <summary>
-    /// LUCENENET specific interface used to apply covariance to TGroupValue
-    /// </summary>
-    /// <typeparam name="TGroupValue"></typeparam>
-    public interface IGroupCount<out TGroupValue> : IGroupCount
-    {
-        TGroupValue GroupValue { get; }
-        IEnumerable<TGroupValue> UniqueValues { get; }
+        /// <summary>
+        /// LUCENENET specific interface used to apply covariance to TGroupValue
+        /// </summary>
+        /// <typeparam name="TGroupValue"></typeparam>
+        public interface IGroupCount<out TGroupValue>
+        {
+            TGroupValue GroupValue { get; }
+            IEnumerable<TGroupValue> UniqueValues { get; }
+        }
     }
 
-
     /// <summary>
     /// LUCENENET specific interface used to apply covariance to GC
     /// </summary>

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/41b9732e/src/Lucene.Net.Grouping/Function/FunctionDistinctValuesCollector.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Grouping/Function/FunctionDistinctValuesCollector.cs b/src/Lucene.Net.Grouping/Function/FunctionDistinctValuesCollector.cs
index 2d5b9ee..22f2395 100644
--- a/src/Lucene.Net.Grouping/Function/FunctionDistinctValuesCollector.cs
+++ b/src/Lucene.Net.Grouping/Function/FunctionDistinctValuesCollector.cs
@@ -70,7 +70,7 @@ namespace Lucene.Net.Search.Grouping.Function
         /** Holds distinct values for a single group.
          *
          * @lucene.experimental */
-        public class GroupCount : AbstractGroupCount<MutableValue> /*AbstractDistinctValuesCollector.GroupCount<MutableValue>*/
+        public class GroupCount : AbstractDistinctValuesCollector.GroupCount<MutableValue>
         {
             internal GroupCount(MutableValue groupValue)
                 : base(groupValue)

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/41b9732e/src/Lucene.Net.Grouping/Term/TermDistinctValuesCollector.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Grouping/Term/TermDistinctValuesCollector.cs b/src/Lucene.Net.Grouping/Term/TermDistinctValuesCollector.cs
index ac4d4e9..91bc674 100644
--- a/src/Lucene.Net.Grouping/Term/TermDistinctValuesCollector.cs
+++ b/src/Lucene.Net.Grouping/Term/TermDistinctValuesCollector.cs
@@ -129,7 +129,7 @@ namespace Lucene.Net.Search.Grouping.Terms
         /** Holds distinct values for a single group.
          *
          * @lucene.experimental */
-        public class GroupCount : AbstractGroupCount<BytesRef> /*AbstractDistinctValuesCollector.GroupCount<BytesRef>*/
+        public class GroupCount : AbstractDistinctValuesCollector.GroupCount<BytesRef>
         {
             internal int[] ords;
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/41b9732e/src/Lucene.Net.Tests.Grouping/DistinctValuesCollectorTest.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Grouping/DistinctValuesCollectorTest.cs b/src/Lucene.Net.Tests.Grouping/DistinctValuesCollectorTest.cs
index 24beb86..711f339 100644
--- a/src/Lucene.Net.Tests.Grouping/DistinctValuesCollectorTest.cs
+++ b/src/Lucene.Net.Tests.Grouping/DistinctValuesCollectorTest.cs
@@ -26,7 +26,7 @@ namespace Lucene.Net.Search.Grouping
         private readonly string countField = "publisher";
         private readonly string dvCountField = "publisher_dv";
 
-        internal class ComparerAnonymousHelper1 : IComparer<IGroupCount<IComparable>>
+        internal class ComparerAnonymousHelper1 : IComparer<AbstractDistinctValuesCollector.IGroupCount<IComparable>>
         {
             private readonly DistinctValuesCollectorTest outerInstance;
 
@@ -35,7 +35,7 @@ namespace Lucene.Net.Search.Grouping
                 this.outerInstance = outerInstance;
             }
 
-            public int Compare(IGroupCount<IComparable> groupCount1, IGroupCount<IComparable>
groupCount2)
+            public int Compare(AbstractDistinctValuesCollector.IGroupCount<IComparable>
groupCount1, AbstractDistinctValuesCollector.IGroupCount<IComparable> groupCount2)
             {
                 if (groupCount1.GroupValue == null)
                 {
@@ -138,7 +138,7 @@ namespace Lucene.Net.Search.Grouping
             // 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")), firstCollector
as Collector);
-            IAbstractDistinctValuesCollector<IGroupCount<IComparable>> distinctValuesCollector
+            IAbstractDistinctValuesCollector<AbstractDistinctValuesCollector.IGroupCount<IComparable>>
distinctValuesCollector
                 = CreateDistinctCountCollector(firstCollector, groupField, countField, dvType.GetValueOrDefault());
             // 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.
@@ -146,7 +146,7 @@ namespace Lucene.Net.Search.Grouping
 
             //var gcs = distinctValuesCollector.Groups as List<IGroupCount<IComparable>>;
             // LUCENENET TODO: Try to work out how to do this without an O(n) operation
-            var gcs = new List<IGroupCount<IComparable>>(distinctValuesCollector.Groups);
+            var gcs = new List<AbstractDistinctValuesCollector.IGroupCount<IComparable>>(distinctValuesCollector.Groups);
             gcs.Sort(cmp);
             assertEquals(4, gcs.Count);
 
@@ -184,7 +184,7 @@ namespace Lucene.Net.Search.Grouping
 
             // LUCENENET TODO: Try to work out how to do this without an O(n) operation
             //gcs = distinctValuesCollector.Groups as List<IGroupCount<IComparable>>;
-            gcs = new List<IGroupCount<IComparable>>(distinctValuesCollector.Groups);
+            gcs = new List<AbstractDistinctValuesCollector.IGroupCount<IComparable>>(distinctValuesCollector.Groups);
             gcs.Sort(cmp);
             assertEquals(3, gcs.Count);
 
@@ -217,7 +217,7 @@ namespace Lucene.Net.Search.Grouping
 
             // LUCENENET TODO: Try to work out how to do this without an O(n) operation
             //gcs = distinctValuesCollector.Groups as List<IGroupCount<IComparable>>;
-            gcs = new List<IGroupCount<IComparable>>(distinctValuesCollector.Groups);
+            gcs = new List<AbstractDistinctValuesCollector.IGroupCount<IComparable>>(distinctValuesCollector.Groups);
             gcs.Sort(cmp);
             assertEquals(2, gcs.Count);
 
@@ -253,20 +253,20 @@ namespace Lucene.Net.Search.Grouping
                     Sort groupSort = new Sort(new SortField("id", SortField.Type_e.STRING));
                     int topN = 1 + random.nextInt(10);
 
-                    List<IGroupCount<IComparable>> expectedResult = CreateExpectedResult(context,
term, groupSort, topN);
+                    List<AbstractDistinctValuesCollector.IGroupCount<IComparable>>
expectedResult = CreateExpectedResult(context, term, groupSort, topN);
 
                     IAbstractFirstPassGroupingCollector<IComparable> firstCollector
= CreateRandomFirstPassCollector(dvType, groupSort, groupField, topN);
                     // 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(new TermQuery(new Term("content", term)), firstCollector
as Collector);
-                    IAbstractDistinctValuesCollector<IGroupCount<IComparable>>
distinctValuesCollector
+                    IAbstractDistinctValuesCollector<AbstractDistinctValuesCollector.IGroupCount<IComparable>>
distinctValuesCollector
                         = CreateDistinctCountCollector(firstCollector, groupField, countField,
dvType);
                     // 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(new TermQuery(new Term("content", term)), distinctValuesCollector
as Collector);
 
                     // LUCENENET TODO: Try to work out how to do this without an O(n) operation
-                    List<IGroupCount<IComparable>> actualResult = new List<IGroupCount<IComparable>>(distinctValuesCollector.Groups);
+                    List<AbstractDistinctValuesCollector.IGroupCount<IComparable>>
actualResult = new List<AbstractDistinctValuesCollector.IGroupCount<IComparable>>(distinctValuesCollector.Groups);
 
                     if (VERBOSE)
                     {
@@ -287,8 +287,8 @@ namespace Lucene.Net.Search.Grouping
                     assertEquals(expectedResult.Count, actualResult.Count);
                     for (int i = 0; i < expectedResult.size(); i++)
                     {
-                        IGroupCount<IComparable> expected = expectedResult[i];
-                        IGroupCount<IComparable> actual = actualResult[i];
+                        AbstractDistinctValuesCollector.IGroupCount<IComparable> expected
= expectedResult[i];
+                        AbstractDistinctValuesCollector.IGroupCount<IComparable> actual
= actualResult[i];
                         AssertValues(expected.GroupValue, actual.GroupValue);
                         assertEquals(expected.UniqueValues.Count(), actual.UniqueValues.Count());
                         List<IComparable> expectedUniqueValues = new List<IComparable>(expected.UniqueValues);
@@ -306,7 +306,7 @@ namespace Lucene.Net.Search.Grouping
             }
         }
 
-        private void PrintGroups(List<IGroupCount<IComparable>> results)
+        private void PrintGroups(List<AbstractDistinctValuesCollector.IGroupCount<IComparable>>
results)
         {
             for (int i = 0; i < results.size(); i++)
             {
@@ -427,7 +427,7 @@ namespace Lucene.Net.Search.Grouping
             doc.Add(valuesField);
         }
 
-        private IAbstractDistinctValuesCollector<IGroupCount<T>> CreateDistinctCountCollector<T>(IAbstractFirstPassGroupingCollector<T>
firstPassGroupingCollector,
+        private IAbstractDistinctValuesCollector<AbstractDistinctValuesCollector.IGroupCount<T>>
CreateDistinctCountCollector<T>(IAbstractFirstPassGroupingCollector<T> firstPassGroupingCollector,
                                                                             string groupField,
                                                                             string countField,
                                                                             FieldInfo.DocValuesType_e?
dvType)
@@ -436,11 +436,11 @@ namespace Lucene.Net.Search.Grouping
             IEnumerable<ISearchGroup<T>> searchGroups = firstPassGroupingCollector.GetTopGroups(0,
false);
             if (typeof(FunctionFirstPassGroupingCollector).IsAssignableFrom(firstPassGroupingCollector.GetType()))
             {
-                return (IAbstractDistinctValuesCollector<IGroupCount<T>>)new
FunctionDistinctValuesCollector(new Hashtable(), new BytesRefFieldSource(groupField), new
BytesRefFieldSource(countField), searchGroups as IEnumerable<ISearchGroup<MutableValue>>);
+                return (IAbstractDistinctValuesCollector<AbstractDistinctValuesCollector.IGroupCount<T>>)new
FunctionDistinctValuesCollector(new Hashtable(), new BytesRefFieldSource(groupField), new
BytesRefFieldSource(countField), searchGroups as IEnumerable<ISearchGroup<MutableValue>>);
             }
             else
             {
-                return (IAbstractDistinctValuesCollector<IGroupCount<T>>)new
TermDistinctValuesCollector(groupField, countField, searchGroups as IEnumerable<ISearchGroup<BytesRef>>);
+                return (IAbstractDistinctValuesCollector<AbstractDistinctValuesCollector.IGroupCount<T>>)new
TermDistinctValuesCollector(groupField, countField, searchGroups as IEnumerable<ISearchGroup<BytesRef>>);
             }
         }
 
@@ -475,7 +475,7 @@ namespace Lucene.Net.Search.Grouping
             }
         }
 
-        internal class GroupCount : AbstractGroupCount<BytesRef>
+        internal class GroupCount : AbstractDistinctValuesCollector.GroupCount<BytesRef>
         {
             internal GroupCount(BytesRef groupValue, IEnumerable<BytesRef> uniqueValues)
                 : base(groupValue)
@@ -484,9 +484,9 @@ namespace Lucene.Net.Search.Grouping
             }
         }
 
-        private List<IGroupCount<IComparable>> CreateExpectedResult(IndexContext
context, string term, Sort groupSort, int topN)
+        private List<AbstractDistinctValuesCollector.IGroupCount<IComparable>>
CreateExpectedResult(IndexContext context, string term, Sort groupSort, int topN)
         {
-            List<IGroupCount<IComparable>> result = new List<IGroupCount<IComparable>>();
+            List<AbstractDistinctValuesCollector.IGroupCount<IComparable>> result
= new List<AbstractDistinctValuesCollector.IGroupCount<IComparable>>();
             IDictionary<string, ISet<string>> groupCounts = context.searchTermToGroupCounts[term];
             int i = 0;
             foreach (string group in groupCounts.Keys)


Mime
View raw message