Skip to content

SOLR-18101: SolrJ commit options, fluent API#4109

Draft
dsmiley wants to merge 1 commit intoapache:mainfrom
dsmiley:SOLR-18101-SolrjCommitApi
Draft

SOLR-18101: SolrJ commit options, fluent API#4109
dsmiley wants to merge 1 commit intoapache:mainfrom
dsmiley:SOLR-18101-SolrjCommitApi

Conversation

@dsmiley
Copy link
Contributor

@dsmiley dsmiley commented Feb 6, 2026

This is a little bit of an API refresh on UpdateRequest/AbstractUpdateRequest to make it clearer how to send various commit options, and their relation to optimize & expungeDeletes.

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

This is a little bit of an API refresh on UpdateRequest/AbstractUpdateRequest to make it clearer how to send various commit options, and their relation to optimize & expungeDeletes.
@dsmiley
Copy link
Contributor Author

dsmiley commented Feb 6, 2026

This is a draft, not using the API just showing what I think it should be and what I want to deprecate.

@epugh
Copy link
Contributor

epugh commented Feb 6, 2026

Seems fine.. I'll be honest, I don't think I have strong opinons around this area... I almost never use SolrJ in my real world work, I only ever interact with it inside of Solr... I'm mostly in favour of anything that moves us forward, gets rid of waitFlush, and let's me remove more deprecated code in main. I may also just be a bit fatigued around all the change/discussion/work in the Java SolrCLient world ;-)! Not very helpful, I know.

Copy link
Contributor

@gerlowskija gerlowskija left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great at this stage. I left a few real nit-picky comments on naming etc. that you can feel free to ignore, but the overall enum CommitOptions direction is a strongly positive step IMO 👍

I can already see @epugh licking his chops at all those 'setAction' deprecations 😛

public static final EnumSet<CommitOption> DEFAULTS = EnumSet.of(waitSearcher, openSearcher);
}

@Deprecated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[+1] 🎉


public enum CommitOption {
/** Makes the changes visible. True by default. */
openSearcher,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[0] Don't care strongly but I'm used to seeing enum values as ALL_CAPS, and I imagine most readers are as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I like the all caps as well, and we should probably have a lint rule for it!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confess I'm annoyed with the collective set of people (whoever they are; I don't care) that started making all-caps a defacto convention standard. Do they get paid by the lines of code they write? Do we need silly conversion methods between the all-caps and corresponding natural params they are supposed to map to?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear, the very explicit decision I made to use this casing is to align with the parameter names they correspond to.

super(m, path, SolrRequestType.UPDATE);
}

public enum CommitOption {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[0] This is well out-of-scope for your PR since you're focused on how to make the Java API better given the HTTP APIs that already exist, but...

Reading this PR really draws my attention to how quirky our HTTP-level API here is. Specifically the main decision conceptually when making a commit is "hard or soft?"...this HTTP API obscures that entirely. You could read these params and not even grok that distinction.

I wonder if it'd be worth adding some sort of commit.type query param that accepts values hard, soft, or both.

Just thinking aloud...

softCommit;

/** Default standard set of commit options: waitSearcher and openSearcher */
public static final EnumSet<CommitOption> DEFAULTS = EnumSet.of(waitSearcher, openSearcher);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[0] These aren't just general update "defaults", they're defaults specifically around committing. Might be good to represent that in the name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This constant is scoped inside the CommitOption, thus CommitOption.DEFAULTS.

return this;
}

public AbstractUpdateRequest commitAndOptimize(EnumSet<CommitOption> options, int maxSegments) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[0] Do we really need the commitAnd in the name of this method and commitAndExpungeDeletes below? It feels like a bit of an implementation detail that we're also setting the commit flag - the expunge or the optimize are the main thing by far.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It reflects the reality of what's happening. I recognize the "optimize" or "expungeDeletes" are a bigger impact. I wanted the API here to reflect something that was previously non-obvious.

return deleteById(id, route, null);
}

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[+1] Really appreciate the Javadocs you're adding here!

params.set(UpdateParams.COMMIT, true);
// only set if varies from default
if (options.contains(CommitOption.softCommit) == true) {
params.set(UpdateParams.SOFT_COMMIT, true);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

speaking of enum capitalization... my choice allows me to skip referencing UpdateParams constants and instead take the enum name itself as-is. I didn't do that... maybe I should. OTH, I often do a find-usages on canonical constants to see where we reference them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants