Skip to content

Commit f6f0a84

Browse files
committed
Make ByDocBlock/DocBlockGroupingSearch non-generic to match Java's wildcard generic erasure for null
1 parent 7881476 commit f6f0a84

5 files changed

Lines changed: 38 additions & 36 deletions

File tree

src/Lucene.Net.Grouping/GroupingSearch.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ namespace Lucene.Net.Search.Grouping
5656
/// </item>
5757
/// <item>
5858
/// <description>
59-
/// <see cref="ByDocBlock{TGroupValue}(Filter)"/> - Constructs a <see cref="DocBlockGroupingSearch{TGroupValue}"/> instance
59+
/// <see cref="ByDocBlock(Filter)"/> - Constructs a <see cref="DocBlockGroupingSearch"/> instance
6060
/// that groups documents by doc block. This method can only be used when documents belonging in a group are indexed in one block.
6161
/// </description>
6262
/// </item>
@@ -72,7 +72,7 @@ namespace Lucene.Net.Search.Grouping
7272
/// </summary>
7373
/// <seealso cref="FieldGroupingSearch"/>
7474
/// <seealso cref="FunctionGroupingSearch{TMutableValue}"/>
75-
/// <seealso cref="DocBlockGroupingSearch{TGroupValue}"/>
75+
/// <seealso cref="DocBlockGroupingSearch"/>
7676
public static class GroupingSearch
7777
{
7878
/// <summary>
@@ -100,15 +100,14 @@ public static FunctionGroupingSearch<TMutableValue> ByFunction<TMutableValue>(Va
100100
}
101101

102102
/// <summary>
103-
/// Constructs a <see cref="DocBlockGroupingSearch{TGroupValue}"/> instance that groups documents by doc block.
103+
/// Constructs a <see cref="DocBlockGroupingSearch"/> instance that groups documents by doc block.
104104
/// This method can only be used when documents belonging in a group are indexed in one block.
105105
/// </summary>
106106
/// <param name="groupEndDocs">The filter that marks the last document in all doc blocks</param>
107-
/// <typeparam name="TGroupValue">The type of the group value</typeparam>
108-
/// <returns>A <see cref="DocBlockGroupingSearch{TGroupValue}"/> instance.</returns>
109-
public static DocBlockGroupingSearch<TGroupValue> ByDocBlock<TGroupValue>(Filter groupEndDocs)
107+
/// <returns>A <see cref="DocBlockGroupingSearch"/> instance.</returns>
108+
public static DocBlockGroupingSearch ByDocBlock(Filter groupEndDocs)
110109
{
111-
return new DocBlockGroupingSearch<TGroupValue>(groupEndDocs);
110+
return new DocBlockGroupingSearch(groupEndDocs);
112111
}
113112
}
114113

@@ -413,17 +412,17 @@ public override TopGroups<T> Search(IndexSearcher searcher, Filter filter, Query
413412
}
414413
}
415414

415+
#nullable enable
416416
/// <summary>
417417
/// A grouping search that groups documents by doc block.
418418
/// This class can only be used when documents belonging in a group are indexed in one block.
419419
/// </summary>
420-
/// <typeparam name="T">The type of the group value</typeparam>
421-
public class DocBlockGroupingSearch<T> : AbstractGroupingSearch<T, DocBlockGroupingSearch<T>>
420+
public class DocBlockGroupingSearch : AbstractGroupingSearch<object?, DocBlockGroupingSearch>
422421
{
423422
private readonly Filter groupEndDocs;
424423

425424
/// <summary>
426-
/// Constructs a <see cref="DocBlockGroupingSearch{T}"/> instance that groups documents by doc block.
425+
/// Constructs a <see cref="DocBlockGroupingSearch"/> instance that groups documents by doc block.
427426
/// This class can only be used when documents belonging in a group are indexed in one block.
428427
/// </summary>
429428
/// <param name="groupEndDocs">The filter that marks the last document in all doc blocks</param>
@@ -433,14 +432,15 @@ public DocBlockGroupingSearch(Filter groupEndDocs)
433432
}
434433

435434
/// <inheritdoc cref="AbstractGroupingSearch{T, TSelf}.Search(IndexSearcher,Filter,Query,int,int)"/>
436-
public override TopGroups<T> Search(IndexSearcher searcher, Filter filter, Query query, int groupOffset, int groupLimit)
435+
public override TopGroups<object?> Search(IndexSearcher searcher, Filter filter, Query query, int groupOffset, int groupLimit)
437436
{
438437
int topN = groupOffset + groupLimit;
439438
BlockGroupingCollector c = new BlockGroupingCollector(GroupSort, topN, IncludeScores, groupEndDocs);
440439
searcher.Search(query, filter, c);
441440
int topNInsideGroup = GroupDocsOffset + GroupDocsLimit;
442-
return c.GetTopGroups<T>(SortWithinGroup, groupOffset, GroupDocsOffset, topNInsideGroup, FillSortFields);
441+
return c.GetTopGroups<object?>(SortWithinGroup, groupOffset, GroupDocsOffset, topNInsideGroup, FillSortFields);
443442
}
443+
#nullable restore
444444
}
445445

446446
/// <summary>

src/Lucene.Net.Grouping/package.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ Or alternatively use the `GroupingSearch` convenience utility:
140140

141141
```cs
142142
// Per search:
143-
DocBlockGroupingSearch<object> groupingSearch = GroupingSearch.ByDocBlock<object>(groupEndDocs);
143+
DocBlockGroupingSearch groupingSearch = GroupingSearch.ByDocBlock(groupEndDocs);
144144
groupingSearch.SetGroupSort(groupSort);
145145
groupingSearch.SetIncludeScores(needsScores);
146146
TermQuery query = new TermQuery(new Term("content", searchTerm));
147-
TopGroups<object> groupsResult = groupingSearch.Search(indexSearcher, query, groupOffset, groupLimit);
147+
TopGroups<object?> groupsResult = groupingSearch.Search(indexSearcher, query, groupOffset, groupLimit);
148148

149149
// Render groupsResult...
150150
```
@@ -166,4 +166,4 @@ int maxDoc = s.MaxDoc;
166166
FixedBitSet groupHeadsBitSet = c.RetrieveGroupHeads(maxDoc);
167167
```
168168

169-
For each of the above collector types there is also a variant that works with `ValueSource` instead of of fields. Concretely this means that these variants can work with functions. These variants are slower than there term based counter parts. These implementations are located in the `Lucene.Net.Search.Grouping.Function` package, but can also be used with the `GroupingSearch` convenience utility
169+
For each of the above collector types there is also a variant that works with `ValueSource` instead of of fields. Concretely this means that these variants can work with functions. These variants are slower than there term based counter parts. These implementations are located in the `Lucene.Net.Search.Grouping.Function` package, but can also be used with the `GroupingSearch` convenience utility

src/Lucene.Net.Tests.Grouping/GroupingSearchDocExampleTest.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
using NUnit.Framework;
88
using System.Collections.Generic;
99

10+
#nullable enable
11+
1012
namespace Lucene.Net.Search.Grouping
1113
{
1214
/*
@@ -70,12 +72,12 @@ public void TestFieldGroupingSearchDocExample()
7072

7173
// --- Code from package.md documentation ---
7274
Sort groupSort = Sort.RELEVANCE;
73-
bool fillFields = true;
74-
bool useCache = true;
75-
bool requiredTotalGroupCount = true;
76-
string searchTerm = "random";
77-
int groupOffset = 0;
78-
int groupLimit = 10;
75+
const bool fillFields = true;
76+
const bool useCache = true;
77+
const bool requiredTotalGroupCount = true;
78+
const string searchTerm = "random";
79+
const int groupOffset = 0;
80+
const int groupLimit = 10;
7981

8082
FieldGroupingSearch groupingSearch = GroupingSearch.ByField("author");
8183
groupingSearch.SetGroupSort(groupSort);
@@ -104,7 +106,7 @@ public void TestFieldGroupingSearchDocExample()
104106
{
105107
int? totalGroupCount = result.TotalGroupCount;
106108
Assert.IsNotNull(totalGroupCount);
107-
assertEquals(2, totalGroupCount.Value);
109+
assertEquals(2, totalGroupCount!.Value);
108110
}
109111

110112
indexSearcher.IndexReader.Dispose();
@@ -113,7 +115,7 @@ public void TestFieldGroupingSearchDocExample()
113115

114116
/// <summary>
115117
/// Tests the "GroupingSearch convenience utility" example for doc block grouping
116-
/// from the package.md documentation using <see cref="GroupingSearch.ByDocBlock{TGroupValue}(Filter)"/>.
118+
/// from the package.md documentation using <see cref="GroupingSearch.ByDocBlock(Filter)"/>.
117119
/// </summary>
118120
[Test]
119121
public void TestDocBlockGroupingSearchDocExample()
@@ -155,20 +157,20 @@ public void TestDocBlockGroupingSearchDocExample()
155157

156158
// --- Search code from package.md documentation ---
157159
Sort groupSort = Sort.RELEVANCE;
158-
bool needsScores = true;
159-
string searchTerm = "random";
160-
int groupOffset = 0;
161-
int groupLimit = 10;
160+
const bool needsScores = true;
161+
const string searchTerm = "random";
162+
const int groupOffset = 0;
163+
const int groupLimit = 10;
162164

163165
// Set this once in your app & save away for reusing across all queries:
164166
Filter groupEndDocs = new CachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Index.Term("groupEnd", "x"))));
165167

166168
// Per search:
167-
DocBlockGroupingSearch<object> groupingSearch = GroupingSearch.ByDocBlock<object>(groupEndDocs);
169+
DocBlockGroupingSearch groupingSearch = GroupingSearch.ByDocBlock(groupEndDocs);
168170
groupingSearch.SetGroupSort(groupSort);
169171
groupingSearch.SetIncludeScores(needsScores);
170172
TermQuery query = new TermQuery(new Index.Term("content", searchTerm));
171-
TopGroups<object> groupsResult = groupingSearch.Search(indexSearcher, query, groupOffset, groupLimit);
173+
TopGroups<object?> groupsResult = groupingSearch.Search(indexSearcher, query, groupOffset, groupLimit);
172174

173175
// Verify results
174176
Assert.IsNotNull(groupsResult);

src/Lucene.Net.Tests.Grouping/GroupingSearchFluentApiTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,26 +203,26 @@ public void TestFunctionGroupingSearch_FullChaining()
203203
[Test]
204204
public void TestDocBlockGroupingSearch_SetGroupSort_ReturnsConcrete()
205205
{
206-
DocBlockGroupingSearch<object> result = GroupingSearch
207-
.ByDocBlock<object>(null)
206+
DocBlockGroupingSearch result = GroupingSearch
207+
.ByDocBlock(null)
208208
.SetGroupSort(Sort.RELEVANCE);
209209
Assert.IsNotNull(result);
210210
}
211211

212212
[Test]
213213
public void TestDocBlockGroupingSearch_SetIncludeScores_ReturnsConcrete()
214214
{
215-
DocBlockGroupingSearch<object> result = GroupingSearch
216-
.ByDocBlock<object>(null)
215+
DocBlockGroupingSearch result = GroupingSearch
216+
.ByDocBlock(null)
217217
.SetIncludeScores(true);
218218
Assert.IsNotNull(result);
219219
}
220220

221221
[Test]
222222
public void TestDocBlockGroupingSearch_FullChaining()
223223
{
224-
DocBlockGroupingSearch<object> result = GroupingSearch
225-
.ByDocBlock<object>(null)
224+
DocBlockGroupingSearch result = GroupingSearch
225+
.ByDocBlock(null)
226226
.SetGroupSort(Sort.RELEVANCE)
227227
.SetSortWithinGroup(Sort.RELEVANCE)
228228
.SetGroupDocsOffset(0)

src/Lucene.Net.Tests.Grouping/GroupingSearchTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public virtual void TestBasic()
156156
// LUCENENET: using SearchDelegate callback to encapsulate non-covariant generic type use
157157
groupingSearch = (searcher, filter, query, offset, limit) =>
158158
{
159-
var topGroups = GroupingSearch.ByDocBlock<object>(lastDocInBlock).Search(searcher, filter, query, offset, limit);
159+
var topGroups = GroupingSearch.ByDocBlock(lastDocInBlock).Search(searcher, filter, query, offset, limit);
160160

161161
return new GroupingSearchResult
162162
{

0 commit comments

Comments
 (0)