Skip to content

SOLR-18197: Add root document query shortcut support to NestPathField#4512

Draft
abumarjikar wants to merge 2 commits into
apache:mainfrom
abumarjikar:SOLR_18197_nest_path_easy_of_use
Draft

SOLR-18197: Add root document query shortcut support to NestPathField#4512
abumarjikar wants to merge 2 commits into
apache:mainfrom
abumarjikar:SOLR_18197_nest_path_easy_of_use

Conversation

@abumarjikar

@abumarjikar abumarjikar commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

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

Description

This pull request introduces a quick and intuitive shortcut to query root documents within hierarchical/nested data structures using the NestPathField. Currently, finding root-level documents (which do not have a nested path defined) requires a more verbose or explicit query syntax. This change provides a cleaner "ease of use" developer experience when dealing with nested child documents.

Solution

When a query is made against this field with an empty value, a null value, or a root slash ("/"), it automatically constructs and returns a BooleanQuery that targets only top-level root documents. It accomplishes this by matching all documents and explicitly excluding any documents where the nested path field exists:

MUST: MatchAllDocsQuery

MUST_NOT: ExistenceQuery (for the NestPathField)

For all other standard path inputs, it safely falls back to the default super.getFieldQuery(...) behavior.

Tests

Please describe the tests you've developed or run to confirm this patch implements the feature or solves the problem.

Checklist

Please review the following and check all that apply:

  • I have reviewed the guidelines for How to Contribute and my code conforms to the standards described there to the best of my ability.
  • I have created a Jira issue and added the issue ID to my pull request title.
  • I have given Solr maintainers access to contribute to my PR branch. (optional but recommended, not available for branches on forks living under an organisation)
  • I have developed this patch against the main branch.
  • I have run ./gradlew check.
  • I have added tests for my changes.
  • I have added documentation for the Reference Guide
  • I have added a changelog entry for my change

@dsmiley dsmiley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks. Looking to see this used widespread in code & docs. The goal is to ensure no user sees that ugly/confusing syntax that was previously necessary.

@@ -0,0 +1,7 @@
title: Add root document query shortcut support to NestPathField
type: changed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This isn't "changed" since no existing user/query is going to trigger this functionality. The functionality here is opt-in, hence "added". If you think the changelog template could be improved here, LMK.


@Override
public Query getFieldQuery(QParser parser, SchemaField field, String externalVal) {
if (externalVal == null || externalVal.isEmpty() || "/".equals(externalVal)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm suspicious of null/empty. Do you think it should be implied the user means only root docs? Maybe we should just throw a SolrException BAD_REQUEST.

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.

2 participants