| Fabio Massimo Ercoli:
Maybe the concept of scope compatibility is similar to the concept of index compatibility
The example you gave should actually fail. You created predicates taking into account metadata from one index, and later created a query using these same predicates, but targeting a completely different index. This index's metadata may be completely different, with some fields having a different type. The kind of compatibility checks I'm talking about are only similar on a very high level. "Compatibility" may not be the right word, actually. "Consistency" is probably a better fit. We want to check that, if a predicate was created targeting the index "Author", it cannot be used in a query targeting the index "Book". We could allow more things in the future, of course, such as the example you're giving. It would essentially amount to introducing some kind of duck-typing in SearchPredicate: if the predicate targets field name of index author, and index book declares a field name with similar characteristics, then we can use the predicate on index book too. We could do it, but let's not bother with that right now. The kind of (crude) consistency check I was thinking of could simply be implemented in org.hibernate.search.engine.search.predicate.spi.SearchPredicateBuilderFactory#toImplementation for predicates, for example. Let's imagine you store the set of targeted indexes in SearchPredicate: you would only need to check this set of targeted indexes is the same as the one targeted by the SearchPredicateBuilderFactory.
Maybe we could add some tests, such as: [...]
Tests may be similar, yes. However:
- I'm not sure testing all field types is really necessary, but if it's not too hard, I agree it would be nice.
- What we want to be sure about here is that incompatibility is detected. You example only tries to check that compatibility is detected, which is fine, but is probably already tested in multiple parts of the code. What's most important to test is that exceptions occur when users do things wrong.
In short the test would create two slightly different scopes, and check that using a predicate(/sort/projection) created from one scope on a query created from the other scope will fail.
|