Using a subquery in a hibernate FullTextEntityManager query

Apologies if this is a duplicate question, I have seen this and it comes close to what I am asking I think -
but the suggested solution of building a list of id’s seems a little impractical to me and so I hope there may be a slightly different slant to my question !

I have a set of tables which contain their own previous version records and I am trying to modify some existing code using a hibernate FullTextEntityManager query. Essentially it works currently against all records in the given table 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

> 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);

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 ? Or whether this is even possible ?

Hello,

I answered you question on stack overflow: https://stackoverflow.com/questions/56344916/using-a-subquery-in-a-hibernate-fulltextentitymanager-query/56358069#56358069

Let’s continue the discussion there if necessary.