paulirwin commented on issue #1059: URL: https://github.com/apache/lucenenet/issues/1059#issuecomment-2540597340
I spent some time looking at this, and playing around with the APIs in both Lucene and Lucene.NET beta 17, and I've got a pretty good grasp on it now. The problem boils down to not as much that the Lucene Java code uses wildcard generics, but that we're trying to force a _reified_ generics design on this API, when in Java the generics are type-erased. The generic methods where only the generic type parameter is used in the return type lets the caller pretend like it's any type they want, but it will fail unless it's the exact type that is hydrated at runtime. For example, Lucene/Java happily let you write unintelligible code like the following: ```java TopGroups<System> topGroups = groupingSearch.search(searcher, query, 0, topNGroups); ``` (Yes, that System.) Since these types are erased, there's nothing telling `groupingSearch.search` what type to make (or expect to try to make) the group values. If the API took a `Class<T>` parameter, that would allow us to match it with .NET reified generics, but since it doesn't, our generics really can only just help ensure we don't have to cast everywhere to use the API as they're just doing the casting internally. i.e. if you try to pass `string` where it internally expects it to be a `BytesRef` it will fail, but that's not really different from what would happen in Lucene. It very easily could just be a non-generic API if we wanted to do that, where the group value would be of type `object`, but I think @NightOwl888's plan above is going to work. I've got the GroupingSearch class broken down into those three classes with a common abstract base class. The only failing test I'm chasing down now is that the Function tests are failing to cast from MutableValue to MutableValueStr (or Int32), so I have to figure out a solution to that. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
