I am trying to modify some code using a hibernate FullTextEntityManager query. Essentially it works currently but I would like to constrain the results to a subset of records in a table (the most recent of a given type).
So for example the underlying query of data to search might be something along these lines (for demonstration only, I haven't parsed this!)
SELECT name, address
FROM Persons p
WHERE p.name = sq.name
FROM
(SELECT name, max(datemodified)
FROM Persons
GROUP BY name) sq
Currently the java code is just selecting from the raw table (essentially this is what the forEntity option does I think)
FullTextEntityManager ftem = Search.getFullTextEntityManager(getEntityManager());
SearchFactory sf= ftem.getSearchFactory();
QueryContextBuilder qcb = sf.buildQueryBuilder();
QueryBuilder qb= qcb.forEntity(entityClass).get();
//processSearchExpression builds a lucene style full text search
org.apache.lucene.search.Query q= processSearchExpression();
FullTextQuery ftq= ftem.createFullTextQuery(q, entityClass);
So essentially I think I've put the essentials in there quite faithfully. What I can't quite work out is how to add a sub query or something producing similar functionality so that I can just query the most recent records of each type ?