Skip to content

feat(schema): return list-fields as FieldListing records with FieldFlag flags - #293

Closed
adityamparikh wants to merge 6 commits into
apache:mainfrom
adityamparikh:feat/list-fields-records
Closed

adityamparikh wants to merge 6 commits into
apache:mainfrom
adityamparikh:feat/list-fields-records

Conversation

@adityamparikh

Copy link
Copy Markdown
Contributor

Stacked on #288 (list-fields) and #292 (FieldFlags): review the last commit only. Rebased once both merge.

Summary

list-fields and solr://{collection}/fields now return a FieldListing record instead of Luke's fields and info sections as maps. Each field's flag letters are decoded into SolrJ's FieldFlag, the enum get-schema uses since #292, so Luke's info.key legend is no longer needed.

 "platform": {
   "type": "string",
-  "schema": "I-SD------OF-----l",
+  "flags": ["INDEXED", "STORED", "DOC_VALUES", "OMIT_NORMS", "OMIT_TF", "SORT_MISSING_LAST"],
   "docs": 61
 }
-"info": {"key": {"I": "Indexed", "T": "Tokenized", ...}, "NOTE": "..."}
listFields(collection)
  solrClient.request(LukeRequest numTerms=0 includeIndexFieldFlags=false)
  objectMapper.convertValue(response.get("fields"), Map<String, IndexedField>)   # SimpleOrderedMap is a Map
FieldListing(fields)
  IndexedField(type, flags, dynamicBase, docs: Long, other)   # compact constructor decodes "schema" into flags
  • docs is a Long, so a distributed sum past 2^31 does not depend on how it was parsed (SolrJ's LukeResponse.FieldInfo casts it to Integer).
  • The letters are decoded with FieldFlag.getFlag, not LukeResponse.FieldInfo.parseFlags, which adds getFlag's result without a null check and would throw on a letter a later Solr version adds. On an unknown letter the letters are kept as schema in the catch-all.
  • Every other property Luke sends is kept in a @JsonAnySetter @JsonAnyGetter catch-all and written back at the same level.
  • The tool description now names the flags and says to facet only on DOC_VALUES fields and sort only on ones without MULTI_VALUED.

Evidence

  • Before: an agent had to read "schema": "I-SD------OF-----l" against info.key to learn that platform has docValues; faceting on the schemaless text_general platform returned an empty facet because the missing D went unnoticed.
    After: "flags": ["INDEXED", "STORED", "DOC_VALUES", ...].
  • SchemaServiceTest: listFields_decodesFlagsAndLeavesOutTheInfoAndIndexSections pins the exact JSON; listFields_keepsADistributedDocCountPastIntegerMax (3,000,000,000); listFields_keepsTheLettersWhenOneIsNotAKnownFlag ("I-S-----------Z" gives no flags and keeps the letters).
  • ListFieldsIntegrationTest.decodesLukeFlagLettersIntoFieldFlags on real Solr: genre_s (*_s, string) has INDEXED, STORED, DOC_VALUES; year_i (pint) has DOC_VALUES and not MULTI_VALUED. The existing dynamicBase, point-field and two-shard tests pass on the record.
  • McpClientIntegrationTestBase.listShowsFieldsReturnsIndexedFields, through Spring AI's serialization: no info, id has flags with INDEXED and STORED, no schema letters.
  • ./gradlew build: 478 tests, 0 failures, 0 skipped.
  • ./gradlew nativeTest -Pnative: 316 successful, 0 failed; ListFieldsIntegrationTest and the MCP list-fields tests (HTTP and STDIO) pass in the native image. The skipped tests are the @DisabledInNativeImage Mockito tests.

Merge Danger

Door: two-way

Blast Radius: list-fields-consumers

list-fields is new in #288, so no released client reads its shape. Against #288 the JSON changes: schema letters become flags, info is gone.

🤖 Generated with Claude Code

adityamparikh and others added 6 commits November 16, 2026 20:54
…gh (apache#241)

get-schema returns the full schema definition (about 35 KB on _default) and
cannot say which dynamic fields hold data. list-fields sends one
collection-level Luke request (numTerms=0, includeIndexFieldFlags=false) and
returns Luke's fields and info sections as Solr sends them; info.key decodes
the schema flag letters. The index section is left out: get-collection-stats
covers it, and its directory entry names a path on the Solr host. The same
JSON is served as the solr://{collection}/fields resource, with
collection-name completion.

The server adds no logic of its own. The tool description says how to read
Solr's answer: point and docValues-only fields have no docs count (missing,
or 0 on 9.11+/10.1+), and before Solr 9.11/10.1 Luke reads one shard of a
multi-shard collection (SOLR-8127).

The field tools now name each other so a model can tell them apart:
get-schema is definitions and patterns, get-collection-stats is index size
and performance, and search drops its suffix guide in favour of calling
list-fields first. Its undefined-field and facet error hints point to
list-fields. A registration test pins the cross-references.

Closes apache#241

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
- Read Luke's raw NamedList with solrClient.request() instead of process(),
  which also builds SolrJ's typed LukeResponse: that parse casts each docs
  count to Integer and fails on a distributed sum past 2^31.
- Move the docValues advice to the error path it applies to. Solr rejects a
  facet or sort on an unsuitable field with a 400, which gets the generic
  hint; RESPONSE_ERROR is a client-side parse failure. The search
  description and search-collection prompt also say sorting needs a
  single-valued field.
- ListFieldsIntegrationTest: an unknown collection is a SolrException 404,
  and the comment on point-field docs names the right Solr code path.
- Test against Solr 9.11, the first release with distributed Luke: added to
  both compatibility matrices and the tested-version lists. The full suite
  passes on solr:9.11-slim, which runs the two-shard test's distributed
  branch.
- Update the tool and resource counts and lists in THREAT_MODEL.md,
  CHANGELOG.md and the client docs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
- java:S1192: the Luke key constant LUKE_FIELDS_KEY ("fields") made Sonar
  ask the add-fields parameter check to reuse it, though that "fields" is
  an error-message name, not a Luke key. One list of the Luke sections to
  pass through replaces the two key constants.
- java:S5785: assertNotEquals instead of assertTrue(a != b).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
get-schema returned SolrJ's SchemaRepresentation, whose FieldTypeDefinition
nests each type's properties under "attributes" and serializes every unset
analyzer slot as null: 32 KB on _default against the Schema API's own 23 KB.

It now returns a CollectionSchema record with typed components for the
properties clients read (fields, field types, analyzers, copy fields).
Every other property Solr sends is kept in a catch-all map, collected by
@JsonAnySetter when the response is converted and written back at the same
level by @JsonAnyGetter, so the JSON a client receives is the Schema API's,
key for key, and a property a later Solr version adds is passed on rather
than dropped.

The response is read with solrClient.request() and converted by Jackson:
the Schema API's JSON objects arrive as SimpleOrderedMap, a java.util.Map,
so no mapping code is needed.

Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
The Schema API's boolean properties (indexed, stored, docValues,
multiValued, omitNorms, sortMissingLast, ...) are now reported on every
field, dynamic field and field type as "flags", a set of SolrJ's
FieldFlag, the enum Luke's flag letters decode to. list-fields uses the
same enum, so both tools describe a field's flags the same way.

Only properties set to true appear: a flag property set to false, or
inherited from the field type, is not reported. required, which
FieldFlag has no counterpart for, stays a typed property; other
properties without one (useDocValuesAsStored, large, default) stay in
the catch-all unchanged.

Flags are written as their constant names (DOC_VALUES). Jackson 3 writes
enums with toString() by default, which for FieldFlag is Luke's legend
text ("D - DocValues").

Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
…ag flags

list-fields passed Luke's fields and info sections through as maps. An
agent had to decode each field's schema letters ("I-SD------OF-----l")
with the info.key legend to learn, for example, whether it can facet on
the field.

It now returns a FieldListing record. Each field's letters are decoded
into SolrJ's FieldFlag, the enum get-schema uses, so the info legend is
no longer needed and is left out. docs is a Long, so a distributed sum
past 2^31 no longer depends on how the value was parsed. Every other
property Luke sends is kept in a catch-all and written back at the same
level.

The letters are decoded with FieldFlag.getFlag rather than
LukeResponse.FieldInfo.parseFlags, which adds getFlag's result without a
null check and so would throw on a letter a later Solr version adds. On
an unknown letter the letters are kept as they are.

Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
@sonarqubecloud

Copy link
Copy Markdown

@adityamparikh

Copy link
Copy Markdown
Contributor Author

Folded into #288, whose branch now includes this commit, so list-fields is reviewed once, in its final record form.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant