solr icon indicating copy to clipboard operation
solr copied to clipboard

SOLR-17044: Expose api "version" on SolrRequest objects

Open gerlowskija opened this issue 9 months ago • 6 comments

https://issues.apache.org/jira/browse/SOLR-17044

Description

SolrJ often needs to know whether a given request is for a v1 or v2 API, but doesn't have an easy way to do so. The best it can do is one of two approximations: either check the path string for "____v2", or do an instanceof V2Request check. Both of these are exceedingly brittle.

Solution

This PR introduces a new request on the SolrRequest class: getApiVersion(). It returns an ApiVersion enum value, which can either be "V1" or "V2". The method has a default implementation on SolrRequest which returns the enum value "V1", overriding this on a number of subclasses that represent v2 requests (V2Request, various generated SolrJ classes, etc.)

As usual with these sort of changes, GenericSolrRequest introduces some complications. There's no great way to determine whether a given GSR represents a v1 or v2 API without resorting to the same brittle string inspection we're trying to avoid. This PR solves this by assuming that 'GenericSolrRequest' instances represent v1 API requests, and adds a trivial 'GenericV2SolrRequest' class to represent v2 requests. (Open to other ways of doing this if folks don't like this approach)

Tests

Existing tests continue to pass.

Checklist

Please review the following and check all that apply:

  • [x] I have reviewed the guidelines for How to Contribute and my code conforms to the standards described there to the best of my ability.
  • [x] I have created a Jira issue and added the issue ID to my pull request title.
  • [x] I have given Solr maintainers access to contribute to my PR branch. (optional but recommended)
  • [x] I have developed this patch against the main branch.
  • [ ] I have run ./gradlew check.
  • [ ] I have added tests for my changes.

gerlowskija avatar May 10 '24 19:05 gerlowskija