Hardy,
I am using hibernate search.
@Indexed public class Article implements Cloneable, Serializable{ ... @DocumentId private String id; private String title; @IndexedEmbedded private Set<Author> authors; ... }
Search query: BooleanQuery query = new BooleanQuery(); keywordQuery.add(new TermQuery(new Term("title", keyword)), BooleanClause.Occur.SHOULD); ... if(searchKeyword)query.add(keywordQuery, BooleanClause.Occur.MUST); query.add(new TermQuery( new Term("authors.name",authorName)));
FullTextSession fullTextSession = Search.getFullTextSession( sessionFactory.getCurrentSession() ); FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery( query ); fullTextQuery.setFirstResult( (pageNumber) * pageSize ); fullTextQuery.setMaxResults( pageSize ); PartialListHolder results = new PartialListHolder(); results.setSource( fullTextQuery.list()); results.setNrOfElements( fullTextQuery.getResultSize() ); results.setPageSize( pageSize ); results.setPage( pageNumber ); In old search function, we can get a list of matched articles by searching keyword or authorName. Our new requirement is to display same article multiple times with each of its authors if it has.
As you said, it is kind of display problem. But I can not simply iterate over the authors because of the paging issue. I still want to display fix number of articles in each page. But the setNrOfElements and page count are still generated by fullTextQuery.
|