feat(434): distinct-values search endpoint (text fields, Lucene term enumeration)

Adds GET /api/v1/search/fields/{name}/values?q=&limit= — the backend slice of the
visual rule builder's facet-value typeahead (#434). Enumerates distinct Lucene term
values for a text field via MultiFields.GetTerms + TermsEnum, filtered by a
case-insensitive prefix, limit clamped to [1,50]. 404s when the field is absent from
SearchFieldCatalog or is not type "text". ElasticSearchIndex (the optional external
backend) throws NotSupportedException for this method — its text fields are analyzed,
not keyword-mapped, so a terms aggregation isn't safe to guess at without verifying
against a live cluster.

Regenerated OpenAPI trio (v1.json, v1.d.ts, endpoint-index.md).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-23 20:43:27 +02:00
co-authored by Claude Opus 4.8
parent b66a3400ae
commit b4ae0bde18
11 changed files with 370 additions and 58 deletions
@@ -189,6 +189,28 @@ public class SearchController(IMediator mediator) : ControllerBase
public Task<List<SearchFieldResponseModel>> GetSearchFields(CancellationToken cancellationToken) =>
mediator.Send(new GetSearchFieldCatalog(), cancellationToken);
[HttpGet("/api/v1/search/fields/{name}/values", Name = "GetSearchFieldValues")]
[Tags("Search")]
[EndpointSummary("List distinct term values for a text search field")]
[EndpointDescription(
"Returns distinct term values from the search index for the given text field, filtered by an " +
"optional case-insensitive prefix. Powers the visual rule builder's facet-value typeahead. " +
"404 when the field is unknown or is not a text field.")]
[EndpointGroupName("general")]
[ProducesResponseType(typeof(SearchFieldValuesResponseModel), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
public async Task<IActionResult> GetSearchFieldValues(
[FromRoute] string name,
[FromQuery] string q = "",
[FromQuery] int limit = 50,
CancellationToken cancellationToken = default)
{
Option<SearchFieldValuesResponseModel> result = await mediator.Send(
new GetSearchFieldValues(name, q ?? string.Empty, limit),
cancellationToken);
return result.ToGetResult();
}
private static SearchResultAllItemsResponseModel Project(SearchResultAllItemsViewModel vm) =>
new(
vm.MovieIds,