Repository navigation
feat(schema): return get-schema as CollectionSchema records with FieldFlag flags - #292
Closed
adityamparikh wants to merge 2 commits into
Closed
adityamparikh wants to merge 2 commits into
adityamparikh wants to merge 2 commits into
Conversation
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>
|
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
get-schemaandsolr://{collection}/schemanow return aCollectionSchemarecord instead of SolrJ'sSchemaRepresentation.The records type what clients read and keep everything else:
otheris a catch-all marked@JsonAnySetter @JsonAnyGetter. Jackson collects each property the record does not declare into it (positionIncrementGap,vectorDimension,useDocValuesAsStored,similarity, …) and writes it back out at the same level, so a property a later Solr version adds is passed on instead of dropped.flagsis a set of SolrJ'sFieldFlag, the enum Luke's flag letters decode to, soget-schemaandlist-fieldsdescribe flags the same way. The compact constructor moves the Schema API's boolean flag properties out of the catch-all:{"name": "platform", "type": "string", - "docValues": true, "multiValued": false, "indexed": true, "stored": true} + "flags": ["INDEXED", "STORED", "DOC_VALUES"]}Only properties set to
trueare reported; a property set tofalse, or inherited from the field type, is not.requiredhas noFieldFlagand stays a typed property. Flags are written as constant names: Jackson 3 writes enums withtoString(), which forFieldFlagis Luke's legend text ("D - DocValues"), soFieldFlags.NameSerializerwritesname().The new records and
FieldFlags.NameSerializerare registered inSolrNativeHints.MCP_TOOL_RECORDS, andFieldFlagwith the SolrJ types; theSchemaRepresentationhint is removed because nothing serializes it any more.Evidence
get-schemaon a_defaultcollection returns 32,169 chars, each field type wrapped as{"analyzer":null, "attributes":{"name":"strings","class":"solr.StrField","sortMissingLast":true,"multiValued":true}, "indexAnalyzer":null, "multiTermAnalyzer":null, …}.After: 23,297 chars (Solr's own
schemasection is 23,261):{"name":"strings","class":"solr.StrField","flags":["MULTI_VALUED","SORT_MISSING_LAST"]}.SchemaServiceIntegrationTest.getSchema_isTheSchemaApiResponseWithFlagPropertiesAsFlags: the serialized record equals Solr's Schema API response with each field's, dynamic field's and field type's boolean flag properties replaced by theflagsthat weretrue, compared as parsed JSON.getSchema_reportsFieldFlagspins examples (_root_isINDEXEDbut notSTORED).SchemaServiceTest.getSchema_keepsPropertiesTheRecordsDoNotDeclare: an unknown field property and an unknown top-level section reach the JSON at the level Solr sent them, with nootherkey;indexed: true, stored: falsebecomes"flags":["INDEXED"].McpClientIntegrationTestBase.getSchema(through Spring AI's serialization):classsits at the top level of a field type, there is noattributeswrapper and nootherkey, the arrays are present, andidcarries"flags"withINDEXEDandSTOREDinstead of booleans../gradlew build: 461 tests, 0 failures, 0 skipped../gradlew nativeTest -Pnative: 304 successful, 0 failed; the schema integration tests and both MCPgetSchematests (HTTP and STDIO) pass in the native image. The 154 skipped are the@DisabledInNativeImageMockito tests.Merge Danger
Door: two-way
Reverting restores the SolrJ type.
Blast Radius: schema-consumers
The JSON shape of
get-schemaandsolr://{collection}/schemachanges: field-type properties move out ofattributesto the top level, as the Schema API sends them, the null analyzer slots disappear, and boolean flag properties become aflagslist. A client that parsed the SolrJ shape, or readindexed/docValuesbooleans, has to readflagsinstead; an explicitfalseis no longer visible. Java callers ofSchemaService.getSchemagetCollectionSchemainstead ofSchemaRepresentation.🤖 Generated with Claude Code