Skip to content

refactor(indexing): parse Markdown front matter with SnakeYAML - #206

Closed
adityamparikh wants to merge 2 commits into
apache:mainfrom
adityamparikh:refactor/markdown-front-matter-yaml
Closed

adityamparikh wants to merge 2 commits into
apache:mainfrom
adityamparikh:refactor/markdown-front-matter-yaml

Conversation

@adityamparikh

Copy link
Copy Markdown
Contributor

Summary

Markdown front matter is YAML, but its values did not come from a YAML parser: the commonmark front-matter extension reads the block line by line, and MarkdownDocumentCreator added a hand-rolled splitter for flow sequences ([a, b]). A quoted title containing a comma or a colon, a quoted list element, or a nested mapping came out wrong or was lost.

The block is now sliced out verbatim using commonmark's source spans and handed to SnakeYAML, which Spring Boot already ships. Implicit type resolution is switched off, so every scalar stays the text as written (2026-01-01 is not turned into a Date, 8.4 not into a Double), exactly as before; Solr's schema guessing types it. Sequences become multi-valued fields, nested mappings flatten with underscores (ratings_imdb), nulls are skipped. The flow-sequence splitter is deleted.

What changed

  • MarkdownDocumentCreator: parser built with includeSourceSpans(BLOCKS); addFrontMatterFields loads the block with SnakeYAML's SafeConstructor and a resolver with no implicit tags; ~30 lines of custom parsing removed, ~25 lines of library wiring added.
  • MarkdownDocumentCreatorTest (plain JUnit): quoted scalars with delimiters, flow and block sequences, nested mapping, typed-looking scalars kept as text, invalid YAML reported, no-front-matter document unchanged.
  • MarkdownIndexingTest (existing, Spring) passes unchanged.

Independent of #202, #203 and #205; any merge order.

Verification

  • ./gradlew build on Java 25: green.
  • ./gradlew nativeTest -Pnative on GraalVM CE 25.0.2: green (SnakeYAML's SafeConstructor builds only JDK collections and strings).

🤖 Generated with Claude Code

https://claude.ai/code/session_01CiUHyyXLTo9ATdgg8eRFZJ

The front matter is YAML, but its values came from the commonmark
extension's line-by-line reader plus a hand-rolled splitter for flow
sequences, so a quoted title containing a comma or a colon, a quoted list
element, or a nested mapping came out wrong. The block is now sliced out
verbatim via commonmark's source spans and handed to SnakeYAML, which is
already on the classpath through Spring Boot. Implicit type resolution is
switched off so every scalar stays the text as written, exactly as before;
Solr's schema guessing types it. The flow-sequence splitter is gone.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CiUHyyXLTo9ATdgg8eRFZJ
Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
adityamparikh added a commit to adityamparikh/solr-mcp that referenced this pull request Sep 14, 2026
Two titles contained ': ' unquoted, which a YAML parser rejects and only
the line-by-line reader tolerated. The files are now emitted by a YAML
library, so they hold under apache#206 and under the current reader alike.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CiUHyyXLTo9ATdgg8eRFZJ
Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
Port shows-markdown/ (61 show records) and ShowsSampleDataTest from PR apache#201.
Validates that SnakeYAML front matter parsing produces documents matching
shows.json across all 61 records.

Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
Co-authored-by: Junie <junie@jetbrains.com>
@adityamparikh

Copy link
Copy Markdown
Contributor Author

Superseded by #207, which carries this SnakeYAML change plus multi-record splitting, so a Markdown dataset is one file rather than 61. Closing to keep a single open PR for Markdown indexing.

#207

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