NOTE: Probably not Search 6.0 material, but we should probably at least think about how we will be able to add it in the future, because it may require to add more generic parameters to the DSL interfaces, which would be a breaking change.
The idea would be to allow users to pre-validate that a field exists and has a given type, getting a FieldReference<BridgedType> reference (from the SearchTarget, or maybe even from the backend/indexmanager, or from a static schema generated at compile-time).
They would then be able to use the reference in the DSL in a type-safe way: we would have additional onField(FieldReference<?>) methods defined approximately like this:
Then the matching() method would be defined accordingly:
By default when using onField(String), we could return a MatchContext<Object>.
The FieldReference<T> could potentially also be used when projecting (see HSEARCH-3222).
Of course it gets more complex when we want to target multiple fields…
It may not be very useful to users directly, but could be useful to implement DSLs on top of our own, that would be based on a static, generated static schema, similar to JPA’s model generator.