adityamparikh opened a new pull request, #312:
URL: https://github.com/apache/solr-mcp/pull/312

   ## Summary
   
   Implements the search part of the typed-mcp-contracts OpenSpec change (#306, 
spec `search`, design D3 "search" and D4). `search` now returns server-owned 
records instead of Solr's shapes: every hit carries the collection's uniqueKey 
value as `id`, `score` sits beside it rather than among the fields, and facets 
become an ordered list instead of nested maps, so clients can rely on one shape 
whatever the collection's schema.
   
   ```diff
    {
      "numFound": 42,
      "start": 10,
      "maxScore": 2.34,                      // omitted when Solr computed no 
scores
      "documents": [
   -    {"id": "book001", "score": 2.34, "name": ["A Game of Thrones"], "year": 
1996}
   +    {"id": "book001", "score": 2.34, "fields": {"name": ["A Game of 
Thrones"], "year": 1996}}
      ],
   -  "facets": {"genre": {"drama": 12, "comedy": 7}}
   +  "facets": [{"field": "genre", "values": [{"value": "drama", "count": 12}, 
{"value": "comedy", "count": 7}]}]
    }
   ```
   
   - `id` is the uniqueKey value as a string, whatever the field is called 
(`sku`, `id`, ...). When `fields` leaves the uniqueKey out, the server adds it 
to `fl`.
   - The uniqueKey comes from `SchemaRequest.UniqueKey` and is cached per 
collection with a 5-minute expiry and a 256-entry LRU bound. A uniqueKey can't 
change while a collection exists, but a collection can be deleted and recreated 
with another schema. A hit missing the cached key fails the call and evicts the 
entry, so the next search looks it up again.
   - No facet fields gives `"facets": []`.
   
   ```
   search/SearchResponse.java     records: SearchResponse + nested SearchHit, 
FacetField, FacetValue
   search/UniqueKeyCache.java     new: per-collection uniqueKey lookup (TTL + 
LRU)
   search/SearchService.java      maps SolrDocument/FacetField into the 
records; tool + prompt text
   config/SolrNativeHints.java    registers the three nested records
   README.md, docs/tutorial.md    search output shape
   tests                          SearchServiceTest, UniqueKeyCacheTest (new), 
SearchServiceIntegrationTest,
                                  McpClientIntegrationTestBase and four other 
ITs moved to the new shape
   ```
   
   `generateOutputSchema` is not turned on here (group 1 does that for every 
tool). The records are shaped for it: optional `maxScore`/`score` are 
`@Nullable`, records use `@JsonInclude(NON_NULL)`, and there are no 
`@JsonAnyGetter`/`@JsonAnySetter`s.
   
   ## Evidence
   
   | Spec scenario | Tests |
   |---|---|
   | Paged search | 
`SearchServiceTest.search_ReportsNumFoundStartAndAtMostRowsHits`, 
`SearchServiceIntegrationTest.pagedSearchReportsNumFoundStartAndAtMostRowsHits` 
|
   | No score requested | 
`SearchServiceTest.search_WithoutScores_OmitsMaxScoreAndHitScore` (checks the 
serialized JSON) |
   | uniqueKey not named `id` | 
`SearchServiceTest.search_UniqueKeyNotNamedId_BecomesHitIdAndLeavesFields`, 
`search_NonStringUniqueKey_IsReportedAsString` |
   | Scores requested | 
`SearchServiceTest.search_WithScores_MovesScoreOutOfFields`, 
`SearchServiceIntegrationTest.scoresRequestedInFieldsAreReportedOnEachHit` |
   | Field values keep their types | 
`SearchServiceTest.search_FieldValuesKeepTheirJsonTypes` (JSON), 
`SearchServiceIntegrationTest.fieldValuesKeepTheirTypes` |
   | uniqueKey not in the returned fields | 
`SearchServiceTest.search_FieldsWithoutUniqueKey_AddsItToFl`, 
`SearchServiceIntegrationTest.fieldsWithoutTheUniqueKeyStillReturnItAsId`, and 
over MCP in 
`McpClientIntegrationTestBase.searchWithQueryFieldsAndFieldsThroughMcp` (stdio 
and HTTP) |
   | Facet on one field | 
`SearchServiceTest.search_FacetOnOneField_IsAListOfOrderedValueCounts` (exact 
spec JSON), `SearchServiceIntegrationTest.facetValuesKeepSolrsCountOrder` |
   | No facets requested | 
`SearchServiceTest.search_WithoutFacetFields_ReturnsEmptyFacetList`, 
`SearchServiceIntegrationTest.searchWithoutFacetFieldsReturnsAnEmptyFacetList` |
   | One Schema API call per collection (task 3.1) | 
`SearchServiceTest.search_RepeatedOnOneCollection_AsksTheSchemaApiOnce`; 
expiry, eviction and the LRU bound in `UniqueKeyCacheTest` |
   
   - `./gradlew build`: 543 tests, 0 failures, 0 skipped.
   - `./gradlew nativeTest -Pnative`: 540 tests, 347 passed, 0 failed, 193 
skipped (the `@DisabledInNativeImage` Mockito tests).
   
   ## Merge Danger
   
   **Door:** two-way
   **Blast Radius:** tool-consumers
   Every `search` client sees the new `documents`/`facets` shape, which is 
intended before 1.0.0. Reverting this PR restores the old one.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to