You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucenenet.apache.org by "paulirwin (via GitHub)" <gi...@apache.org> on 2026/04/13 02:16:39 UTC

Re: [PR] BREAKING: Remove covariance and LINQ use from Grouping, #1059 [lucenenet]

paulirwin commented on code in PR #1066:
URL: https://github.com/apache/lucenenet/pull/1066#discussion_r3070589884


##########
src/Lucene.Net.Grouping/GroupingSearch.cs:
##########
@@ -569,185 +489,234 @@ public virtual GroupingSearch SetCachingInMB(double maxCacheRAMMB, bool cacheSco
         /// <param name="maxDocsToCache">The maximum number of documents the cache is allowed to hold</param>
         /// <param name="cacheScores">Whether to cache the scores</param>
         /// <returns><c>this</c></returns>
-        public virtual GroupingSearch SetCaching(int maxDocsToCache, bool cacheScores)
+        public virtual AbstractGroupingSearch<T> SetCaching(int maxDocsToCache, bool cacheScores)
         {
-            this.maxDocsToCache = maxDocsToCache;
-            this.maxCacheRAMMB = null;
-            this.cacheScores = cacheScores;
+            this.MaxDocsToCache = maxDocsToCache;
+            this.MaxCacheRAMMB = null;
+            this.CacheScores = cacheScores;
             return this;
         }
 
         /// <summary>
         /// Disables any enabled cache.
         /// </summary>
         /// <returns><c>this</c></returns>
-        public virtual GroupingSearch DisableCaching()
+        public virtual AbstractGroupingSearch<T> DisableCaching()
         {
-            this.maxCacheRAMMB = null;
-            this.maxDocsToCache = null;
+            this.MaxCacheRAMMB = null;
+            this.MaxDocsToCache = null;
             return this;
         }
 
         /// <summary>
-        /// Specifies how groups are sorted.
-        /// Defaults to <see cref="Sort.RELEVANCE"/>.
+        /// Whether to include the score of the most relevant document per group.
         /// </summary>
-        /// <param name="groupSort">The sort for the groups.</param>
+        /// <param name="includeMaxScore">Whether to include the score of the most relevant document per group</param>
         /// <returns><c>this</c></returns>
-        public virtual GroupingSearch SetGroupSort(Sort groupSort)
+        public virtual AbstractGroupingSearch<T> SetIncludeMaxScore(bool includeMaxScore)
         {
-            this.groupSort = groupSort;
+            this.IncludeMaxScore = includeMaxScore;
             return this;
         }
 
         /// <summary>
-        /// Specified how documents inside a group are sorted.
-        /// Defaults to <see cref="Sort.RELEVANCE"/>.
+        /// Whether to also compute all groups matching the query.
+        /// This can be used to determine the number of groups, which can be used for accurate pagination.
+        /// <para>
+        /// When grouping by doc block the number of groups are automatically included in the <see cref="TopGroups"/> and this
+        /// option doesn't have any influence.
+        /// </para>
         /// </summary>
-        /// <param name="sortWithinGroup">The sort for documents inside a group</param>
+        /// <param name="allGroups">to also compute all groups matching the query</param>
         /// <returns><c>this</c></returns>
-        public virtual GroupingSearch SetSortWithinGroup(Sort sortWithinGroup)
+        public virtual AbstractGroupingSearch<T> SetAllGroups(bool allGroups)
         {
-            this.sortWithinGroup = sortWithinGroup;
+            this.AllGroups = allGroups;
             return this;
         }
 
         /// <summary>
-        /// Specifies the offset for documents inside a group.
+        /// If <see cref="SetAllGroups(bool)"/> was set to <c>true</c> then all matching groups are returned, otherwise
+        /// an empty collection is returned.
         /// </summary>
-        /// <param name="groupDocsOffset">The offset for documents inside a</param>
-        /// <returns><c>this</c></returns>
-        public virtual GroupingSearch SetGroupDocsOffset(int groupDocsOffset)
+        /// <returns>all matching groups are returned, or an empty collection</returns>
+        public virtual ICollection<T> GetAllMatchingGroups()
         {
-            this.groupDocsOffset = groupDocsOffset;
-            return this;
+            return MatchingGroups;
         }
 
         /// <summary>
-        /// Specifies the number of documents to return inside a group from the specified groupDocsOffset.
+        /// Whether to compute all group heads (most relevant document per group) matching the query.
+        /// <para>
+        /// This feature isn't enabled when grouping by doc block.
+        /// </para>
         /// </summary>
-        /// <param name="groupDocsLimit">The number of documents to return inside a group</param>
+        /// <param name="allGroupHeads">Whether to compute all group heads (most relevant document per group) matching the query</param>
         /// <returns><c>this</c></returns>
-        public virtual GroupingSearch SetGroupDocsLimit(int groupDocsLimit)
+        public virtual AbstractGroupingSearch<T> SetAllGroupHeads(bool allGroupHeads)
         {
-            this.groupDocsLimit = groupDocsLimit;
+            this.AllGroupHeads = allGroupHeads;
             return this;
         }
 
         /// <summary>
-        /// Whether to also fill the sort fields per returned group and groups docs.
+        /// Returns the matching group heads if <see cref="SetAllGroupHeads(bool)"/> was set to true or an empty bit set.
         /// </summary>
-        /// <param name="fillSortFields">Whether to also fill the sort fields per returned group and groups docs</param>
-        /// <returns><c>this</c></returns>
-        public virtual GroupingSearch SetFillSortFields(bool fillSortFields)
+        /// <returns>The matching group heads if <see cref="SetAllGroupHeads(bool)"/> was set to true or an empty bit set</returns>
+        public virtual IBits GetAllGroupHeads()
         {
-            this.fillSortFields = fillSortFields;
-            return this;
+            return MatchingGroupHeads;
         }
+    }
+
+    /// <summary>
+    /// Abstract base class for grouping search implementations.
+    /// </summary>
+    /// <typeparam name="T">The type of the group value</typeparam>
+    /// <remarks>
+    /// LUCENENET specific
+    /// </remarks>
+    /// <seealso cref="GroupingSearch"/>
+    public abstract class AbstractGroupingSearch<T> : IAbstractGroupingSearch

Review Comment:
   I ran this PR through Claude Code Opus 4.6 for a full review, and it discovered that the fluent API broke with this change, because they return the base class type rather than the concrete type.
   
   Example:
   ```c#
   // Doesn't compile - SetAllGroups returns AbstractGroupingSearch<BytesRef>, not FieldGroupingSearch
   FieldGroupingSearch search = GroupingSearch.ByField("field")
       .SetGroupSort(Sort.RELEVANCE)
       .SetAllGroups(true)
       .SetInitialSize(256); // CS1061: 'AbstractGroupingSearch<BytesRef>' does not contain 'SetInitialSize'
   ``` 
   
   This will be updated to use the CRTP pattern to return the concrete type from each fluent method.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@lucenenet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org